Re: [gtkmm] BadWindow ( invalid Window parameter ) / Gtk::Dialog hell for newbie



Here's the code:

string song, outputsong, s1;
int songlength, outputsonglength;
char* arg_list[10];
const int file = 1;
const int directory = 2;

void window1::on_processing() {
	const int mp3 = 1, ogg = 2, no = 0;
	for(int ii=0; ii<10; ii++) 
		arg_list[ii] = new char[100];

	int type;
	songlength = song.length();
        string temp( song, 0, songlength-4 );
        outputsong = temp;
	outputsonglength = outputsong.length();
        s1 = song.substr(outputsonglength+1,3) ;
                     
	if(s1=="mp3") type = mp3;	
	
	else if(s1=="ogg") type = ogg;

	else type = no;

        switch(type) {
		case mp3: do_mp3();
		 	  break;
	        case ogg: do_ogg();
			  break;
		default: 
			  break;
	}

        for(int i=0; i<10; i++) 
               	delete arg_list[i];
}

void do_ogg() {
	if( fork() == 0 ) {
		int child;
		arg_list[0] = "oggdec";
		song.copy( arg_list[1], songlength, 0 );
		arg_list[1][songlength] = '\0';
		arg_list[2] = NULL;
		spawn( "oggdec", arg_list );
		wait(&child);
		arg_list[0] = "lame";
		outputsong += ".wav";
		outputsong.copy( arg_list[1], outputsonglength+4, 0 );
		arg_list[1][outputsonglength+4] = '\0';
		outputsong = outputsong.substr( 0, outputsonglength );
		arg_list[2] = NULL;
		spawn( "lame", arg_list );
		wait(&child);
		arg_list[0] = "rm";
		spawn( "rm", arg_list );
		wait(&child);
		delete arg_list[2];
		arg_list[2] = new char[100];
		arg_list[0] = "mv";
		string temp = outputsong + ".wav" + ".mp3";
		temp.copy( arg_list[1], outputsonglength+8, 0 );
		arg_list[1][outputsonglength+8] = '\0';
		outputsong += ".mp3";
		outputsong.copy( arg_list[2], outputsonglength+4, 0 );
		arg_list[2][outputsonglength+4] = '\0';
		arg_list[3] = NULL;
		spawn( "mv", arg_list );
		wait(&child);
		_exit( 0 );
	}
}

void do_mp3() {
	if( fork() == 0 ) {
             int child;
	     arg_list[0] = "mpg321";
	     song.copy( arg_list[1], songlength, 0 );
	     arg_list[1][songlength] = '\0';
	     arg_list[2] = "-w";
	     outputsong.copy( arg_list[3], outputsonglength, 0 );
	     arg_list[3][outputsonglength] = '\0';
	     arg_list[4] = NULL;
	     spawn("mpg321", arg_list);
	     wait(&child);
	     arg_list[0] = "oggenc";
	     outputsong.copy( arg_list[1], outputsonglength, 0 );
	     arg_list[1][outputsonglength] = '\0';
	     arg_list[2] = NULL;
	     spawn("oggenc", arg_list);
	     wait(&child);
	     arg_list[0] = "rm";
	     outputsong.copy( arg_list[1], outputsonglength, 0 );
	     spawn("rm", arg_list);
	     wait(&child);
	     _exit( 0 );
	}
}

As you can see, none of my child processes talk to GUI. Any idea? 

On Wed, 2004-04-14 at 16:20, Matthew Walton wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi
> 
> I've not looked at your code in any great depth, but I suspect that
> on_processing() is trying to talk to the GUI. If this is the case, then
> when you fork() and it tries to talk to the GUI from one of the child
> processes, you're asking for trouble, as you end up with X windows
> shared across processes which X doesn't think they should be accessed
> from, and it starts complaining about it. Try doing everything in a
> single process; if it works, then you need to consider more carefully
> how you're going to do things in the background, if you're going to do
> it - if you do fork(), make sure only the parent talks directly to the
> GUI. If you need to pass data from the children for the GUI to display,
> it will have to pass through the parent process in some way - pipes,
> FIFOs, shared memory, whatever.
> 
> Hopefully that will help and I'm not barking up entirely the wrong tree.
> 
> Akbar wrote:
> | I try to make front-end using gktmm library and glade. I use gtkmm 2.2
> | and glade 2.0.0. My program will convert ogg files to mp3 files and vice
> | versa. It works great but only for one file. I always get this error
> | when I want to convert all files in one directory:
> |
> |
> | The program 'converter' received an X Window System error.
> | This probably reflects a bug in the program.
> | The error was 'BadWindow (invalid Window parameter)'.
> |   (Details: serial 2703 error_code 3 request_code 4 minor_code 0)
> |   (Note to programmers: normally, X errors are reported asynchronously;
> |    that is, you will receive the error a while after causing it.
> |    To debug your program, run it with the --sync command line
> |    option to change this behavior. You can then get a meaningful
> |    backtrace from your debugger if you break on the gdk_x_error()
> | function.)
> |
> | I am newbie so don't expect me to understand this error. Ok here's the
> | detail:
> | I got Gtk::Entry entry to hold the file or directory that user want to
> | convert. If the case is file, it is easy. If the file is
> | /home/knight/Music/blabla.mp3, my program will convert it to blabla.ogg
> | file. if the file is /home/knight/Music/blabla.ogg, my program will
> | convert it to mp3 file. But if the case is directory, it is not easy
> | anymore. It is hell for me. :(
> |
> | Assume entry hold this value: /home/knight/Music. Just for note, I set
> | entry value using Gtk::FileSelection class. If my user push the
> | Gtk::Button convert, my program will confuse. What files must it
> | convert? mp3 to ogg or ogg to mp3?
> |
> | Then I make Gtk::Dialog dialog. Here's the code. If you push the button,
> | this function will work:
> |
> | void window1::on_convert_clicked()
> | {
> | 	if(status==1) {             //if the case is file
> | 	song = input->get_text();
> |         on_processing();
> | 	}
> | 	else if(status==2) {        //if the case is directory
> |
> |                 //Ok, look over here: I make a dialog. The dialog for
> |                 //this mailing list purpose will consist only two
> |                 //button; ogg and mp3
> | 		Gtk::Dialog *dialog;
> | 		dialog = new class Gtk::Dialog("bla bla", *this ) ;
> |                 dialog->add_button("ogg",1);
> | 		dialog->add_button("mp3",2);
> |
> | 		int bla;
> | 		bla = dialog->run();
> |
> | 		DIR *d;
> | 	        struct dirent *dir;
> |
> |
> | 		delete dialog;
> |
> |
> | 		Glib::ustring Direct = input->get_text();
> | 	        d = opendir(Direct.c_str());
> | 	        string temp;
> | 	        vector<string> files;
> | 		switch(bla) {
> | 			case 1:
> | 		                if(d) {
> | 			                while((dir = readdir(d))) {
> | 						temp = dir->d_name;
> | 						if(temp.length()>=4)
> | 					               if(temp.substr(temp.length()-4,4)==".ogg")	
> | 						                files.push_back(temp);
> | 					}
> | 				}
> | 				break;
> | 			case 2:
> | 				if(d) {
> | 					while((dir = readdir(d))) {
> | 						temp = dir->d_name;
> | 						if(temp.length()>=4)
> | 						       if(temp.substr(temp.length()-4,4)==".mp3")
> | 						        	files.push_back(temp);
> | 					}
> | 				}
> | 				break;
> | 			default:
> | 				break;
> | 		}
> | 		int child;
> | 		if(fork()==0)
> | 		     for( int i=0; i<files.size(); i++ ) {
> | 		        	song = Direct + "/" + files[i];
> | 		        	on_processing();
> | 				wait(&child);
> | 		     }
> | 	}
> | }
> |
> |
> | But if I push the ogg or mp3 button in Gtk::Dialog dialog, I get this
> | message:
> | This probably reflects a bug in the program.
> | The error was 'BadWindow (invalid Window parameter)'.
> |   (Details: serial 2703 error_code 3 request_code 4 minor_code 0)
> |   (Note to programmers: normally, X errors are reported asynchronously;
> |    that is, you will receive the error a while after causing it.
> |    To debug your program, run it with the --sync command line
> |    option to change this behavior. You can then get a meaningful
> |    backtrace from your debugger if you break on the gdk_x_error()
> | function.)
> |
> | If I comment the delete dialog statement, I got this error:
> | Xlib: unexpected async reply (sequence 0x24ff)!
> |
> | Please, tell me what's wrong!!!!
> | Here's my gdb sessing after fork() function statement:
> |
> | Breakpoint 2, window1::on_convert_clicked (this=0x80834c8) at
> | window1.cc:307
> | 307                     if(fork()==0)
> | (gdb) n
> | Detaching after fork from child process 7052.
> | 101         { for ( ; __first != __last; ++__first) _Destroy(&*__first);
> | }
> | (gdb) n
> | 130           _M_deallocate(_Tp* __p, size_t __n) {
> | _Alloc_type::deallocate(__p,  __n);}
> | (gdb) n
> | 242           { if (0 != __n) _Alloc::deallocate(__p, __n * sizeof
> | (_Tp)); }
> | (gdb) n
> | 249           { return  _M_dataplus._M_p; }
> | (gdb) n
> | 38      {
> | (gdb) n
> | 40        __asm__ __volatile__ ("lock; xadd{l} {%0,%1|%1,%0}"
> | (gdb) n
> | 38      {
> | (gdb) n
> | 207                 _M_destroy(__a);
> | (gdb) n
> | 656           ~allocator() throw() {}
> | (gdb) n
> | 314     }
> | (gdb) n
> | 0x08053a27 in SigC::ObjectSlot0_<void, window1_glade>::proxy
> | (s=0x8106580)
> |     at object_slot.h:62
> | 62              return ((Obj*)(os->object_)
> | (gdb) n
> | Glib::SignalProxyNormal::slot0_void_callback (self=0x80ad160,
> | data=0x81065b0)
> |     at signalproxy.cc:108
> | 108     signalproxy.cc: No such file or directory.
> |         in signalproxy.cc
> | (gdb) n
> | 0x40760d27 in g_cclosure_marshal_VOID__VOID ()
> |    from /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function g_cclosure_marshal_VOID__VOID,
> | which has no line number information.
> | 0x4074dea7 in g_closure_invoke () from /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function g_closure_invoke,
> | which has no line number information.
> | 0x4074e3d0 in g_signal_type_cclosure_new () from
> | /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function g_signal_type_cclosure_new,
> | which has no line number information.
> | 0x4074dee0 in g_closure_invoke () from /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function g_closure_invoke,
> | which has no line number information.
> | 0x407607d6 in g_signal_emit_by_name () from
> | /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function g_signal_emit_by_name,
> | which has no line number information.
> | 0x40761e40 in g_cclosure_marshal_BOOLEAN__FLAGS ()
> |    from /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function
> | g_cclosure_marshal_BOOLEAN__FLAGS,
> | which has no line number information.
> | 0x407604dd in g_signal_emit_by_name () from
> | /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function g_signal_emit_by_name,
> | which has no line number information.
> | 0x40761e40 in g_cclosure_marshal_BOOLEAN__FLAGS ()
> |    from /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function
> | g_cclosure_marshal_BOOLEAN__FLAGS,
> | which has no line number information.
> | 0x40760627 in g_signal_emit_by_name () from
> | /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function g_signal_emit_by_name,
> | which has no line number information.
> | 0x4075f958 in g_signal_emit_valist () from
> | /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function g_signal_emit_valist,
> | which has no line number information.
> | 0x4075fb94 in g_signal_emit () from /usr/lib/./libgobject-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function g_signal_emit,
> | which has no line number information.
> | 0x40314a5b in gtk_button_clicked () from /usr/lib/./libgtk-x11-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function gtk_button_clicked,
> | which has no line number information.
> | 0x40315a4b in _gtk_button_paint () from /usr/lib/./libgtk-x11-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function _gtk_button_paint,
> | which has no line number information.
> | 0x40316110 in _gtk_button_set_depressed () from
> | /usr/lib/./libgtk-x11-2.0.so.0
> | (gdb) n
> | Single stepping until exit from function _gtk_button_set_depressed,
> | which has no line number information.
> | The program 'converter' received an X Window System error.
> | This probably reflects a bug in the program.
> | The error was 'BadWindow (invalid Window parameter)'.
> |   (Details: serial 2701 error_code 3 request_code 10 minor_code 0)
> |   (Note to programmers: normally, X errors are reported asynchronously;
> |    that is, you will receive the error a while after causing it.
> |    To debug your program, run it with the --sync command line
> |    option to change this behavior. You can then get a meaningful
> |    backtrace from your debugger if you break on the gdk_x_error()
> | function.)
> |
> |
> | Thank you!!!!
> | _______________________________________________
> | gtkmm-list mailing list
> | gtkmm-list gnome org
> | http://mail.gnome.org/mailman/listinfo/gtkmm-list
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (Darwin)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
> 
> iD8DBQFAfQJE0UvYjCBpIlARAoStAJ4lWmQN+7x1ftOTWFV7lCOawA1iywCgpX2J
> p5dLTvWMzPuy5yu+K99F/sI=
> =xq0C
> -----END PGP SIGNATURE-----
> 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]