Problem with nvidia cards

I have a problem with both of my nvidia cards concerning the switch between fullscreen and windowed mode (Deleting the rc, dc and window. changing resolution and creating back the window, dc and rc).

Almost half of the time I’ve tried, it has popped me a message box contaning the following message :

access violation error (nvopengl.dll) : stack overflow

Sometime (less fortunate) it’s kernel32.dll that crash…

I just wanted to know if someone else have this problem or if you own an nvidia card and you dont have this problem what would you be saying to that?


Help!

I’ve never had that problem…
Can you give more information about the situation when this is happening?
What else are you doing except everything you just said you did?

are you popping/pushing matrices by any chance?

When, exactly, during the execution of your app does the crash occur? What did you just do?

  • Matt

Well, below is my source, the problem is happening just before opengl star to display something and after the widow is created.

in pseudocode:

start the app in window;
while quit != true
{
check for input
if f1 is pressed
{
delete opengl context
delete window
change resolution
create window
// The error appen around here
create opengl context // Maybe in here
}
}

My source:

void DestroyMainWindow (void)
{
if (WIN_FULLSCREEN)
ChangeDisplaySettings (NULL, CDS_RESET);

if (hRC)
{
	if (!wglMakeCurrent (NULL, NULL))
		MessageBox (NULL,
					"wglMakeCurrent (NULL, NULL)",
					"DestroyWindow () Error",
					MB_OK | MB_ICONINFORMATION);

	if (!wglDeleteContext (hRC))
		MessageBox (NULL,
					"wglDeleteContext (hRC)",
					"DestroyWindow () Error",
					MB_OK | MB_ICONINFORMATION);
	hRC = NULL;
}

if (hDC && !ReleaseDC (hWnd, hDC))
{
	MessageBox (NULL,
				"ReleaseDC (hWnd, hDC)",
				"DestroyWindow () Error",
				MB_OK | MB_ICONINFORMATION);
	hDC = NULL;
}

if (hWnd && !DestroyWindow (hWnd))
{
	MessageBox (NULL,
				"DestroyWindow (hWnd)",
				"DestroyWindow () Error",
				MB_OK | MB_ICONINFORMATION);
	hWnd = NULL;
}

if (!UnregisterClass (WIN_TITLE, hInstance))
{
	MessageBox (NULL,
				"UnregisterClass (WIN_TITLE, hInstance)",
				"DestroyWindow () Error",
				MB_OK | MB_ICONINFORMATION);
	hInstance = NULL;
}

}

bool CreateMainWindow (void)
{
unsigned int PixelFormat;
WNDCLASS WndClass;
DWORD WinExStyle;
DWORD WinStyle;
RECT WindowRect;

WindowRect.left		= 0;
WindowRect.right	= WIN_WIDTH;
WindowRect.top		= 0;
WindowRect.bottom	= WIN_HEIGHT;

hInstance				= GetModuleHandle(NULL);
WndClass.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
WndClass.lpfnWndProc	= (WNDPROC) WndProc;
WndClass.cbClsExtra		= 0;
WndClass.cbWndExtra		= 0;
WndClass.hInstance		= hInstance;
WndClass.hIcon			= LoadIcon (hInstance, MAKEINTRESOURCE (IDI_VERSION6));
WndClass.hCursor		= LoadCursor (NULL, IDC_ARROW);
WndClass.hbrBackground	= NULL;
WndClass.lpszMenuName	= NULL;
WndClass.lpszClassName	= WIN_TITLE;

if (!RegisterClass (&WndClass))
{
	MessageBox (NULL,
				"RegisterClass (&WndClass)",
				"CreateWindow () Error",
				MB_OK | MB_ICONEXCLAMATION);
	return false;
}

if (WIN_FULLSCREEN)
{
	DEVMODE DevMode;
	ZeroMemory (&DevMode, sizeof (DevMode));

	DevMode.dmSize			= sizeof (DevMode);
	DevMode.dmPelsWidth		= WIN_WIDTH;
	DevMode.dmPelsHeight	= WIN_HEIGHT;
	DevMode.dmBitsPerPel	= WIN_GL_COLOR_BITS;
	DevMode.dmFields		= DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

	if (ChangeDisplaySettings (&DevMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
	{
		DestroyMainWindow ();
		return false;
	}
}

if (WIN_FULLSCREEN)
{
	WinExStyle	= WS_EX_APPWINDOW;
	WinStyle	= WS_POPUP;
	
}
else
{
	WinExStyle	= WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
	WinStyle	= WS_OVERLAPPEDWINDOW;
}

AdjustWindowRectEx (&WindowRect, WinStyle, false, WinExStyle);

if (!(hWnd=CreateWindowEx (	WinExStyle,
							WIN_TITLE,
							WIN_TITLE,
							WinStyle |
							WS_CLIPSIBLINGS |
							WS_CLIPCHILDREN,
							WIN_FULLSCREEN? 0 : WIN_XPOSITION,
							WIN_FULLSCREEN? 0 : WIN_YPOSITION,
							WindowRect.right - WindowRect.left,
							WindowRect.bottom - WindowRect.top,
							NULL,
							NULL,
							hInstance,
							NULL)))
{
	MessageBox (NULL,
				"CreateWindowEx (...)",
				"CreateWindow () Error",
				MB_OK | MB_ICONEXCLAMATION);
	DestroyMainWindow ();
	return false;
}

static	PIXELFORMATDESCRIPTOR pfd =
{
	sizeof (PIXELFORMATDESCRIPTOR),
	1,
	PFD_DRAW_TO_WINDOW |
	PFD_SUPPORT_OPENGL |
	PFD_DOUBLEBUFFER,
	PFD_TYPE_RGBA,
	WIN_GL_COLOR_BITS,
	0, 0, 0, 0, 0, 0,
	0,
	0,
	WIN_GL_ACCUM_BITS,
	0, 0, 0, 0,
	WIN_GL_DEPTH_BITS,
	WIN_GL_STENCIL_BITS,
	0,
	PFD_MAIN_PLANE,
	0,
	0, 0, 0
};

if (!(hDC = GetDC (hWnd)))
{
	MessageBox (NULL,
				"GetDC (hWnd)",
				"CreateWindow () Error",
				MB_OK | MB_ICONEXCLAMATION);
	DestroyMainWindow ();
	return false;
}

if (!(PixelFormat = ChoosePixelFormat (hDC, &pfd)))
{
	MessageBox (NULL,
				"ChoosePixelFormat (hDC, &pfd)",
				"CreateWindow () Error",
				MB_OK | MB_ICONEXCLAMATION);
	DestroyMainWindow ();
	return false;
}

if (!SetPixelFormat (hDC, PixelFormat, &pfd))
{
	MessageBox (NULL,
				"SetPixelFormat (hDC, PixelFormat, &pfd)",
				"CreateWindow () Error",
				MB_OK | MB_ICONEXCLAMATION);
	DestroyMainWindow ();
	return false;
}

if (!(hRC = wglCreateContext (hDC)))
{
	MessageBox (NULL,
				"wglCreateContext (hDC)",
				"CreateWindow () Error",
				MB_OK | MB_ICONEXCLAMATION);
	DestroyMainWindow ();
	return false;
}

if (!wglMakeCurrent (hDC, hRC))
{
	MessageBox (NULL,
				"wglMakeCurrent (hDC, hRC)",
				"CreateWindow () Error",
				MB_OK | MB_ICONEXCLAMATION);
	DestroyMainWindow ();
	return false;
}

ShowWindow (hWnd, SW_SHOW);
SetForegroundWindow (hWnd);
SetFocus (hWnd);
ResizeMainWindow (WIN_WIDTH, WIN_HEIGHT);

WIN_GL_NEED_INIT = true;

return true;

}

Can you trace through this and find the exact line where it crashes, though?

Yes I know its long… I dump the source because I cannot put breakpoints in the program because when I do, the program does not crash… That’s why I tought for a while that the problem was occuring only if the creation of the second window was made too shortly after the destruction of the first window.

I adressed the problem to Sébastien Dominé form nvidia corporation, and after some emails he stop awnsering me…

There is something else… I was wondering if it is needed to had some special compiler configuration…
like the calling convention, __cdecl, __stdcall or __fastcall ?
On Montreal University web site they recommend stdcall… Could that be in relation with the problem?

I think what mcraighead was referring to is if you can set your debugger to break program execution on all exceptions, and then look to see what line of your code caused the crash.

I’ve tried that too… But it didn’t work because at every frame, gdi32.dll cause the same exeption number making tracking almost impossible. I read on a forum on this page that the gdi32 error was a “normal” bug and would not disturb applications.

When it crashes you should be able to at least look at your call stack to see which of your functions was being executed when the crash occured.

Gabriel, I already emailed you about this, but just to make sure you see…

If you can, email me a binary that illustrates the problem, and I will debug it from our side of things.

  • Matt

I’ve got the same problem.
When “killing” my OpenGL app. in fullscreen mode there is an stack overflow in gdi32.dll or user32.dll ( win98 / NT ).

If I set fullscreen and 32bit mode the error occurs when calling:
wglMakeCurrent(NULL, NULL)

In 16bit mode:
ReleaseDC( glHwnd, glhDC )

I just cant solve it!

Guys… try this:

I noticed both of you are using wglMakeCurrent(NULL, NULL).

Change it to:

wglMakeCurrent(m_hDC, NULL);
where m_hDC is the DC of the window you are about to destroy.

Let me know if it works.

Siwko

Oh yeah… make sure you do this BEFORE you delete/release the DC.

Siwko

Already tried it.
Still the same problem
I did send my code to a friend, he compiled it and there was no problem.
He told me to try out a tetris clone a friend of his had made in OpenGL. If the same problem occurs it has to be my drivers. Well, it did work out fine.
So, if it’s not the drivers, not my code, then what? This is driving me crazy.

OK I solved it.
Dont call ChangeDisplaySettings( NULL, 0 );
until you Released your DC,RC.
On some drivers ChangeDisplaySettings() seems to mess up the DC or RC.

It worked for me.
Something to think of for everybody if you want your programs to run properly on my machine ( or other with similar drivers )

Still in 16 bit mode it stays there after my program is terminated. If this ring a bell please post a message.

Oh yeah!

It worked fine for me too! Groovy!

Thank you all !