[comp.windows.open-look] Problem with fork and Xview

samaddar@demon.siemens.com (Sumitro Samaddar) (02/09/91)

Summary: Using fork in Xview callback function. The child process is
	 supposed to display an image array on an Xview canvas, using
	 the Xlib call <XPutImage>. It works the first time around,
	 but causes an abnormal exit the next next around, with an
	 error message about BadIDChoice.

--------------------------------------------------------------------------
I am working on an Xview application with a canvas and a few buttons.
The actions triggered by the buttons may potentially take a long time.
Normally, when a button is clicked, the application is "blocked" till
this action is completed. In order to be able to do some other interaction
in the application, I want to run the actions as background processes.

The way I went about was to <fork> in the callback function for a button
(the one specified using PANEL_NOTIFY_PROC) and have the parent process return
immediately. The child process actually executes the desired action and then
exits. The data structure involved here includes a big image array. This
array is defined as a static array in the file where all the callback
functions have been defined. 

	Is creating a child process inefficient here?
	Does it entail creating a copy of the whole image array?

I have tried some simple image processing actions to be taken this way. It
seems to work all right. However, if I try to DISPLAY using this way, I land
into trouble. I use <XCreateImage> and <XPutImage> to display the image. The
first time around, there is no problem. However, the second time, I get an
abnormal exit at the <XPutImage> call, with the following error message :

X Error:  BadIDChoice
  Request Major code 55 ()
  Request Minor code 6
  ResourceID 0x1000037
  Error Serial #789
  Current Serial #782

I get different Error Serial # and Current Serial # every time, and they
always differ with each other by 7. The <Drawable> parameter used for the
Xlib calls (XCreateGC, XPutImage) is derived from the Xview canvas in the
following manner :

  Canvas_pixwin = (Xv_window) xv_get(Main_panel->canvas,
				     CANVAS_NTH_PAINT_WINDOW, 0);
  disp = (Display *)    xv_get( Canvas_pixwin, XV_DISPLAY );
  xwin = (Window)       xv_get( Canvas_pixwin, XV_XID );

<xwin> is the <Drawable> parameter, and <disp> is the <Display> parameter.

I printed the value of this <Drawable> parameter just before the Xlib calls,
and it is close but slightly different from the <ResourceID> number. So far,
I have seen the following value pairs :

	xwin       0xf0000e
	ResourceID 0xf00037

	
	xwin       0x10000e
	ResourceID 0x100037


Any help in solving this problem will be appreciated.

Sumitro