changeset 2828:f796297a014c

prevent crash when user changes selects plugin
author Andrew O. Shadoura <bugzilla@tut.by>
date Sun, 13 Jul 2008 23:22:43 +0300
parents ab41a5a743a0
children ae797b0c21fa
files src/icecast/icecast.c
diffstat 1 files changed, 14 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/icecast/icecast.c	Sun Jul 13 20:57:22 2008 +0300
+++ b/src/icecast/icecast.c	Sun Jul 13 23:22:43 2008 +0300
@@ -62,6 +62,7 @@
 };
 
 static FileWriter plugin;
+static FileWriter plugin_new;
 static uint8_t *outputbuffer = NULL;
 static guint outputlength=0;
 static gint buffersize;
@@ -138,11 +139,11 @@
 
 #ifdef FILEWRITER_MP3
     if (streamformat == MP3)
-        plugin = mp3_plugin;
+        plugin_new = mp3_plugin;
 #endif
 #ifdef FILEWRITER_VORBIS
     if (streamformat == VORBIS)
-        plugin = vorbis_plugin;
+        plugin_new = vorbis_plugin;
 #endif
 }
 
@@ -175,6 +176,7 @@
     outputbuffer=g_try_malloc(buffersize);
 
     set_plugin();
+    plugin=plugin_new;
     if (plugin.init)
         plugin.init(&ice_write_output);
 }
@@ -252,6 +254,8 @@
     pos = aud_playlist_get_position(playlist);
     tuple = aud_playlist_get_tuple(playlist, pos);
 
+    plugin = plugin_new;
+
     if (!shout)
     {
         rv = (plugin.open)();
@@ -539,16 +543,16 @@
 {
     streamformat = gtk_combo_box_get_active(GTK_COMBO_BOX(streamformat_combo));
     set_plugin();
-    if (plugin.init)
-        plugin.init(&ice_write_output);
+    if (plugin_new.init)
+        plugin_new.init(&ice_write_output);
 
-    gtk_widget_set_sensitive(plugin_button, plugin.configure != NULL);
+    gtk_widget_set_sensitive(plugin_button, plugin_new.configure != NULL);
 }
 
 static void plugin_configure_cb(GtkWidget *button, gpointer data)
 {
-    if (plugin.configure)
-        plugin.configure();
+    if (plugin_new.configure)
+        plugin_new.configure();
 }
 
 static void configure_destroy(void)
@@ -562,6 +566,8 @@
         GtkWidget * hbox;
         GtkWidget * label;
 
+        plugin_new = plugin;
+
         configure_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
         gtk_signal_connect(GTK_OBJECT(configure_win), "destroy",
@@ -597,13 +603,10 @@
         g_signal_connect(G_OBJECT(streamformat_combo), "changed", G_CALLBACK(streamformat_cb), NULL);
 
         plugin_button = gtk_button_new_with_label(_("Configure"));
-        gtk_widget_set_sensitive(plugin_button, plugin.configure != NULL);
+        gtk_widget_set_sensitive(plugin_button, plugin_new.configure != NULL);
         g_signal_connect(G_OBJECT(plugin_button), "clicked", G_CALLBACK(plugin_configure_cb), NULL);
         gtk_box_pack_end(GTK_BOX(hbox), plugin_button, FALSE, FALSE, 0);
 
-
-
-
         gtk_box_pack_start(GTK_BOX(configure_vbox), gtk_hseparator_new(), FALSE, FALSE, 0);
 
         hbox = gtk_hbox_new(FALSE, 5);