Haw many device contexes r u using?
For example there is a limitaiton in Win9x for the number of the reserved HDCs. NT doesn’t have such a problem. In 9x platform you can use CS_OWNDC in your window class style…(this will help preventing the crash)
Also I may point, that using wglMakeCurrent & MDI app is very slow solution - wglMakeCurrent is really a slow operations - I have tried it, and so it’s written on the NVidia developers FAQ. Try to use SDI app, and to divide the view with glViewport…
I am not sure, but maybe OpenGL can’t switch to another rendering context if it didn’t finish rendering previous one. So, you shouldn’t call wglMakeCurrent until you are sure that all GL commands for the other rendering context are processed. You do so by calling glFinish instead of glFlush. glFlush returns immediately before finishing rendering. Try it.
From your pice of Code I see that you create a single rendering Context for each Window. This is not nescessary and uses huge amounts of MEM especially on GForce Cards btw. ! You should create one rendering context and then bind it to the Device context of the window you are currently drawing in. Then in your WM_PAINT handler of every window you call:
wglMakeCurrent(CurDC, GlobalRC);
// Draw
wglMakeCurrent(NULL, NULL); // Make the rendering context usable to other device contexts i.e windows. This will work.
If you want to keep your code you should try the following:
loop
{
wglMakeCurrent(hdc1,ghlrc1);
//paint in first window
glFlush(); or glFinish();
wglMakeCurrent(NULL, NULL);
wglMakeCurrent(hdc2,ghlrc2);
//paint in second window
glFlush(); or glFinish();
wglMakeCurrent(NULL, NULL);
}