Skip to main content
GameDev.net gamedev.net
🔒 Locked

Heap and stack corruption?

Started by Crypter Apr 27, 2008 at 5:46 PM 23 replies 6.4k views
Original Post
Crypter
Crypter
Hey everyone, After about 2 weeks or so, I decided to go back to my project again. However, I seem to have ran into an interesting problem. I cleaned and rebuilt the project, and got 100's of warnings that I have not gotten before. After resolving those, and decided to test it. To a surprise, it crashes in a routine that I have not needed to touch for awhile. I am getting these types of errors: "Not enough space for envirement", "Not enough space for lowio initialization", "Not enough space for arguments" and access violations at address 0 referencing memory at address 0. (No idea how that is possible. Selecting "Show Disassembly" from the debugger even brings me to address 0) It always crashes in my OpenGL driver at the same location:
GLuint PixelFormat;
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
{
	g_EvehLog << LogLevel (ERROR) << " *** Pixel format not avialble. Cannot initiate OpenGL device context." << std::endl;
}
Occording to the debugger, the variables are fine. It seems to crash inside of the ChoosePixelFormat() Win32 API routine. Has anyone ever experienced this before? What would you suggest to resolve these problems? I even ran a previous working build of the project, but it does not seem to work anymore. I am now at a loss at what to do... The projects were built with Visual C++ 2005. Perhaps I should try upgrading to 2008 (Assuming Visual C++ is the problem.) Any help is greatly appreciated.
Crypter
Crypter
Hm...

I just ran a previous release that worked fine and got the same problem :/

I am starting to suspect something else is causing my program to crash..
Crypter
Crypter
I took out my code that sets the pixel format for the window, and I did not get that problem anymore. Everything else worked fine.

Of course, I cannot do anything with OpenGL without a proper pixel format set. The same problem happens with both SetPixelFormat() and ChoosePixelFormat().

What can cause these two routines to crash like this? Here is where the code is crashing at. Commenting this section out fixes the problem, so I believe the problem must be happening here. I have no idea why though :/
GLuint PixelFormat=0;if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))	{	g_EvehLog << LogLevel (ERROR) << " *** Pixel format not avialble. Cannot initiate OpenGL device context." << std::endl;	continue;}if(!SetPixelFormat(hDC,PixelFormat,&pfd)){	g_EvehLog << LogLevel (ERROR) << " ** Unable to set pixel format to Rendering window's device context." << std::endl;	continue;}

Thanks again for any suggestions :)
ViperG
ViperG
un-install and re-install your video card drivers.
Black Sky A Star Control 2/Elite like game
zedz
zedz
see if youve bot enuf space on the hardidsk.
also reboot the machine, msvc ocasionally runs into trouble (esp if youre using PCH + full recompile doesnt work)
Crypter
Crypter
Quote:
Original post by zedz
see if youve bot enuf space on the hardidsk.
also reboot the machine, msvc ocasionally runs into trouble (esp if youre using PCH + full recompile doesnt work)


I have alot of free space left on my hdd. I also already tried rebooting, but no avail.

I will see if I can try the video driver reinstallation soon. I can seem to run some other OpenGL programs fine (They are smaller though).

If anyone else has any more suggestions, that would be great!

Thanks :D
Crypter
Crypter
After uninstalling and reinstalling the video drivers, I still get the same problem :(

I also tried my previous release (That works fine), but it created an access violation at address 0 again :/

According to my log output, it is also still at the same location too..

I can post more code if it would help. (I just dont know what else to post that can cause this though)

I should also point out that I am in windowed mode, not full screen.

*edit:

According to the stack trace, nvoglnt.dll (Part of my video driver) is jumping to address 0. Sometimes it returns an error from ChoosePixelFormat(), other times it crashes.

I am suspecting that something is indeed wrong with my display drivers.

[Edited by - Crypter on April 27, 2008 9:03:13 PM]
Crypter
Crypter
I am actually thinking about reinstalling Windows+drivers. I find it quite odd that I would be unable to run any of my previous releases while others can just fine.

However, I also find it odd that some other OpenGL programs work fine :/ So I question if that would even work; or if the problem is somewhere within my code. Although, why would it surface up now? ...And in all releases? ...At the same time :/

Finally, I wanted to add that I ran into a new type of runtime error while trying to run my previous release: R6017: unexpected multithreaded lock error
_Sigma
_Sigma
Host it somewhere and we can give it a go - make it clear if its a code bug or an environment issue...
Crypter
Crypter
Clicky (5.20MB *.zip This is a RELEASE build)

Its an older demo test that tests the engines scene manager. Not much to it, but even this fails on my system. No error--it just immediately quits. The log file stops at the same spot (setting pixel format). I had another member test it, and it worked fine for them.

(Some might recognize the textures used ;) )

Thanks for any help :)

*edit:

I updated this post with a new download link. This demo has been verified to work fine on my work computer. It still fails to work on mine though)

[Edited by - Crypter on April 28, 2008 5:50:32 PM]
_Sigma
_Sigma
Vista x64
Nvidia 8800gts
Dies right off the bat.

Quote:

---------------------------
Eveh3D Real Time Scene Editor - Fatal Exception Error
---------------------------
An Access Violation (0xc0000005) Exception error has accured at address (0x77540043).
Invalid read attempt.

We apologize, a fatal error has occurred, and the Eveh3D Realtime Scene Editor must shut down. Any unsaved work might be lossed.

Please tell us about this problem so that it can be corrected.
---------------------------
OK
---------------------------
Structural
Structural
Do you have a valid HDC? Also make sure you didn't create your HDC with a NULL window handle. Check it all... DC, RC, window handle. I can't remember if the pixel format can mess things up.
I once bluescreened my PC with Intel video chip because I tried to make a device context on a window handle that was NULL. I can tell you that was a real pain to find because it rebooted the moment it hit that creation function.



...


I just remembered something else...
There is something tricky with register class. If you call registerClass with the wrong class string you can get some weird results (ie: you don't get an OpenGL context).
Also, there was something evil with calling RegisterClass twice too, but I don't quite remember what.


Alternatively, you could just use a library like SDL to create your OpenGL window. It'll save you a lot of troubles.
STOP THE PLANET!! I WANT TO GET OFF!!
Crypter
Crypter
It seems no routine is failing. It just crashes with the same error when calling ChoosePixelFormat(). Here is the full code where I set it up:
	PIXELFORMATDESCRIPTOR pfd=	{		sizeof(PIXELFORMATDESCRIPTOR),		1,		PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,		PFD_TYPE_RGBA,		m_kWindow.m_kWinResolution.m_iBitsPerPels,		0, 0, 0, 0,		0, 0, 0, 0,		0, 0, 0, 0,		0,		!m_kWindow.m_kWinResolution.m_iDepthBits ? 16 : m_kWindow.m_kWinResolution.m_iDepthBits,		m_kWindow.m_kWinResolution.m_iStencilBits,		0,		PFD_MAIN_PLANE,		0, 0, 0, 0	};	HGLRC hRC=0;	HDC hDC=0;	if ((hDC=GetDC((HWND)m_kWindow.m_khWindow))==0) {		g_EvehLog << LogLevel (ERROR) << " *** Error retrieving window device context. System error [" << GetLastError() << "]" << std::endl;		return 0;	}	GLuint	PixelFormat=0;	if ((PixelFormat=ChoosePixelFormat(hDC,&pfd))==0) {		g_EvehLog << LogLevel (ERROR) << " *** Pixel format not available. Cannot initiate OpenGL device context. System error [" << GetLastError() << "]" << std::endl;		return 0;	}	if(!SetPixelFormat(hDC,PixelFormat,&pfd)) {		g_EvehLog << LogLevel (ERROR) << " *** Unable to set pixel format to Rendering window's device context." << std::endl;		return 0;	}


Does anyone know of any good software that I can use to track this problem down? The MSVC++ debugger is helpful; but is not giving me much help on this one.

The PIXELFORMATDESCRIPTOR structure is being set up fine, so I am not sure what is going on here...

Also, I uploaded another version of a previous demo that worked fine on a work PC. I linked it from my other post if you would like to try it. I have not tested it on Vista yet, though.
kiwibonga
kiwibonga
I gave it a try and it works just fine, I see an ocean with mountains in the horizon, a bunch of crates and spheres flying... I can rotate...

I'm running Windows XP SP2 (32 bit) with a Radeon 9600XT.
Crypter
Crypter
I just tested it on my laptop and it worked fine. I still get the same problem running from my pc though.

I am thinking that there may be compatibility problems with vista. It seems to work on every xp machine but my pc, so I am suspecting that there is something wrong with my pc again...
Structural
Structural
Quote:
Original post by Crypter
I just tested it on my laptop and it worked fine. I still get the same problem running from my pc though.

I am thinking that there may be compatibility problems with vista. It seems to work on every xp machine but my pc, so I am suspecting that there is something wrong with my pc again...


You can put the executable in compatibility mode in Vista. Right-click the exe -> properties -> go to the compatibility tab -> check "run in compatibility mode" (or something along those lines) and check an OS from the dropdown list.

Another wild guess: I you are not doing so already you can try building the exe as an x86 rather than x64. It may be something with mismatching struct/class sizes.

Lastly, you can try an SDL demo project and see if that works. SDL wraps the OpenGL window creation for you. If that also crashes then you may have a problem with your installation.
STOP THE PLANET!! I WANT TO GET OFF!!
_Sigma
_Sigma
Quote:
Original post by Structural
You can put the executable in compatibility mode in Vista

Doesn't help for my machine...

DevFred
DevFred
Quote:
Original post by Crypter
I am thinking that there may be compatibility problems with vista.

Do you write something to the harddrive? Like a log or something?
MadMax1992
MadMax1992
Thought that I might just drop in:

Vista x86
nVidia 8800 GTS (640mb edition)
2gb ram

Didn't work

Oh and a minor thing: In your error message it reads the following: "any unsaved work might be lossed", it should be: "any unsaved work might be lost"...

EDIT: Log file:

Info: +--------------------------------------------------+Info: Eveh3D Engine v.0.1.1Info: Eveh3D Copyright © 2005 - 2008 BrokenThorn Entertainment Co. All Rigts Reserved.Info: ------------------<<<<<<<<>>>>>>>>----------------Info:Info:Info: ---------------------------------------------------------------------Info: ~<[ Eveh3D Log Started on Tuesday, April 29, 2008 12:05:23 ]>~Info: ---------------------------------------------------------------------Info:Info:Info: Eveh3D Initializing...Info: ...Checking cpuid instruction support...Info: ...cpuid Instruction supported. Checking processor features...Info: ...Available CPU features:Info: ...Initializing Module Manager...Info: ...Initializing Winsock...Info: ...Initializing Core Task Manager...Info: Eveh3D Completed initialization procedures.Info: ...Loading Dynamic Module " Plugins\EvehGL "...Info: ...Loading Module " OpenGL-Win32 v.0.1.1 "...Info: ...Initializing OpenGL...Info: ...Creating Render Device " OpenGL-Win32 v.0.1.1 "... 
Crypter
Crypter
Quote:
Do you write something to the harddrive? Like a log or something?

Its in Log/Eveh3D.html. It also writes to the MSVC debugger and console output during runtime.

Quote:
Another wild guess: I you are not doing so already you can try building the exe as an x86 rather than x64. It may be something with mismatching struct/class sizes.

Sorry--It is already being built as an x86,

Quote:
Lastly, you can try an SDL demo project and see if that works. SDL wraps the OpenGL window creation for you. If that also crashes then you may have a problem with your installation.

Thats a nice idea :) I will try it and let you know if it works or not.

@MadMax1992:

That is where it seems to crash for me too :( It runs fine on other XP machines though..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.