program breaks after awhile

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
sharpedge
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 5
Joined: Thu Aug 05, 2010 5:41 am

program breaks after awhile

Post 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.
pritam
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 991
Joined: Thu Nov 13, 2008 3:16 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Amiga, PSOne, NDS
Programming Language of Choice: C++
Location: Sweden

Re: program breaks after awhile

Post by pritam »

Please post some relevant code to your problem.
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: program breaks after awhile

Post 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.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: program breaks after awhile

Post 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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
sharpedge
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 5
Joined: Thu Aug 05, 2010 5:41 am

Re: program breaks after awhile

Post 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 :)
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: program breaks after awhile

Post 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. ;)
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
sharpedge
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 5
Joined: Thu Aug 05, 2010 5:41 am

Re: program breaks after awhile

Post by sharpedge »

I'll keep that in mind thanks :)
Post Reply