Destroy Multiple GLUI Windows

Hi, I have a system that perform volume rendering and I want to display a slice of my volume.

I’m using a glut window with a GLUI subwindow inside the first one, to put the controls. Now I’d like to open a new glut window with another GLUI subwindow inside, in order to show a slice of my volume.

I can create the window but it becames impossible to close it without generate an error.

So, the first time I close the window I get this error:

GLUT: Warning in iso: glutSetWindow attempted on bogus window.

The second time I get a bounch of these errors, and then a segmentation fault.

Here is the code I use to open and close the window

void ShowSliceWindow(int id)
{
if (!sliceW)
{
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize (400, 500);
glutInitWindowPosition (20, 20);
//Create glut slice window
sliceWindow = glutCreateWindow(“Slice Window”);

//Set the function pointers for glut
glutDisplayFunc(SliceDisplayFunction);

GLUI_Master.set_glutMouseFunc(SliceMouseFunction);

//Create GLUI subwindow inside the glut one
sliceW = GLUI_Master.create_glui_subwindow(sliceWindow, GLUI_SUBWINDOW_BOTTOM);

// Add Rollout for commands
GLUI_Rollout *SliceRollout = sliceW->add_rollout(“Slice Settings”, 1);
<…some commands>
sliceW->add_button(“Close”, 4, closeDialog);
}
}

and these is the closeDialog function
void CloseDialog( int id )
{
if ( glutGetWindow() != mainWindow )
glutSetWindow(mainWindow);
sliceW->close();
glutDestroyWindow(sliceWindow);
sliceW = NULL;
}

I wonder there is some kind of problem whith the current window… but I don’t know how to debug it!

Anybody can helps me, please?

Thank you very much,
Remedios

I’m sorry, I don’t get a segmentation fault, but this strange (for me…) error:

X Error of failed request: BadWindow (invalid Window parameter)
Major opcode of failed request: 12 (X_ConfigureWindow)
Resource id in failed request: 0x4212b5ac
Serial number of failed request: 13393
Current serial number in output stream: 13395

Please, any idea could be very helpful!
Thank you again,
Remedios