Page 1 of 1

program breaks after awhile

Posted: Tue Aug 10, 2010 7:51 pm
by sharpedge
Hi there! I've got this problem, and I'm not sure how to fix it. I'm using c++ with sdl.
So when I run my game everything works fine.. but after awhile (2-3minutes) it suddenly breaks and tells me this:
Unhandled exception at 0x6f4c237b in Project Z.exe: 0xC0000005: Access violation reading location 0x00000000.
and when I look at the disassembly it tells me that this is the problem: 6F4C237B mov eax,dword ptr [edx]
I've been searching on google and havn't found anything. I am running my project with Visual studio 2008 and in release mode.

Thanks for any answer.

Re: program breaks after awhile

Posted: Tue Aug 10, 2010 8:00 pm
by pritam
Please post some relevant code to your problem.

Re: program breaks after awhile

Posted: Tue Aug 10, 2010 8:28 pm
by qpHalcy0n
A 0c5 error indicates that you're trying to access memory that does not exist (was never allocated, or was already freed) whether it be attempting to delete memory that does not exist, trying to de-reference, call functions from...etc etc.

"...reading location 0x00000000" indicates that the invoker is null.

You're trying to free, de-reference, or invoke functions from memory that does not exist. Run in debug and see if the problem exists in a debug build. When it pops up saying whether you want to break, ignore, or what have you. You want to break. Look at the call stack window and see what ultimately leads up to the problem.

Re: program breaks after awhile

Posted: Tue Aug 10, 2010 10:05 pm
by Ginto8
qpHalcy0n wrote:A 0c5 error indicates that you're trying to access memory that does not exist (was never allocated, or was already freed) whether it be attempting to delete memory that does not exist, trying to de-reference, call functions from...etc etc.

"...reading location 0x00000000" indicates that the invoker is null.

You're trying to free, de-reference, or invoke functions from memory that does not exist. Run in debug and see if the problem exists in a debug build. When it pops up saying whether you want to break, ignore, or what have you. You want to break. Look at the call stack window and see what ultimately leads up to the problem.
If you're a bit confused by all this, don't worry, I usually still am. ;)
Basically what he's saying is that at some point one of your pointers is being used when it's NULL, and it's causing a segfault (also known as the error that is a a certified pain in the ass). Use a debugger (most good IDEs have them) and figure out where the error occurs. After that, it's just a fairly simple matter of making sure that none of your pointers are NULL when they aren't supposed to.

Re: program breaks after awhile

Posted: Wed Aug 11, 2010 8:39 am
by sharpedge
Yes it's now fixed :) Stupid mistake not running in debug mode <.< The problem was abit strange though. Had to do with TTF_RenderText_Solid. I wanted to only display some text when clicking on a place, so when you were not clicking I did
surface = TTF_RenderText_Solid(font, " ", white) and somehow that didn't work so well. So I removed it and put the drawing function inside a if(clicked == true) ... Anyway thank you all for your help :)

Re: program breaks after awhile

Posted: Wed Aug 11, 2010 11:37 am
by Ginto8
sharpedge wrote:Yes it's now fixed :) Stupid mistake not running in debug mode <.< The problem was abit strange though. Had to do with TTF_RenderText_Solid. I wanted to only display some text when clicking on a place, so when you were not clicking I did
surface = TTF_RenderText_Solid(font, " ", white) and somehow that didn't work so well. So I removed it and put the drawing function inside a if(clicked == true) ... Anyway thank you all for your help :)
well the funny thing about the SDL_ttf functions is that most of them don't work if you pass them NULL pointers. In the docs it actually mentions a lot that passing most of the functions null pointers will cause it to segfault. That's an example of a lib not letting users be ignorant. ;)

Re: program breaks after awhile

Posted: Wed Aug 11, 2010 6:30 pm
by sharpedge
I'll keep that in mind thanks :)