Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Need help for an unhandled exception

Author
Message
Kevin002
15
Years of Service
User Offline
Joined: 23rd Aug 2009
Location:
Posted: 23rd Aug 2009 15:25
Hi I'm Kevin and well I have encountered an unhandled exception while trying to compile and run a release build.

After a short while of commenting out code and testing I have isolated the problem to my Enemies.cpp

Unfourtinately I can't figure out what is wrong with it.

Here is the Error : "Unhandled exception at 0x000001f5 in Crazy Driver.exe: 0xC0000005: Access violation reading location 0x000001f5."

Here is the code for my Enemies.cpp



Any help would be very much appreciated.

Kevin
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 23rd Aug 2009 18:34
Are you sure that when you get the unhandled exception it doesn't point to a line in your code? Because that's usually what happens to me, the message pops up then it goes to the line in my code that's defected.

Games are like life, they should never stand still.
Kevin002
15
Years of Service
User Offline
Joined: 23rd Aug 2009
Location:
Posted: 23rd Aug 2009 21:40
No the only Options I get are to show the dissembly.

Kevin
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd Aug 2009 22:46
@heyufool1

Remember, he's compiling/running release mode. There should be no debug info to provide a line number.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 23rd Aug 2009 23:02
Oh, didn't see the release build part my bad

Games are like life, they should never stand still.
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 24th Aug 2009 02:44
Kevin ,try to compiling in debug mode to see if you get any more debugging info. With debug mode on, when you get that option for dissembly, it should take you to the actaul line number of the error.

I have a feeling you may be writting to memory where you are not suppose to be. Look over where you delcared C strings. How do you initialize them? If you store strings using "LPSTR" or "char*", did you assign enough memory to hold your string?

Without seeing the rest of the code you have, the only thing I can go on that may not be the case is the "black.SpritePath = "Assets\\Black_anim.png";" in your above code. How did you intialize black.SpritePath so you can hold a string?

Hope that helps...

Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 24th Aug 2009 03:21
@Todd - looks like the "black" object is an instance of the class that it is operating inside of.... (it is being instanced over and over in multiple methods-which will be the reason its not holding the data it is being expected too, keeps going out of scope)

Is there a particular reason that you are using an instance of the class inside of itself ? ... could you not instance the "Enemies black" object inside you main program(or aggregate it into another class) and assign its data member their values there ?

and also, without dwelling on the above -
"Enemies black;" is declared at the top of a number of your functions, which means that each time a function ends... the object black will go out of scope(be destroyed), so the next time you instance it, it will be a new object with new data members etc(it will be a different object, just with the same name, so none of the data you assign it in the "spawn" function will be available to the black object in the Move function for example, they are as far as the program is concerned, 2 seperate things)...

If you dont mind me asking, Do you have much programming experience in using C++ ? Your coding style is nice and neat, which makes me think you are not brand new to programming, but maybe dont have alot of experience with c/cpp, if that is the case, I would suggest doing a bit of reading on how the OO aspects of C++ work, as it is a fairly complex topic that requires alot of thought to understand and implement properly. If you dont have much programming experience, then starting with something procedural would probably be a better idea and easier to understand what is happening where...

Hope this helps

If it ain't broke.... DONT FIX IT !!!
Kevin002
15
Years of Service
User Offline
Joined: 23rd Aug 2009
Location:
Posted: 24th Aug 2009 04:11
Thanks for the help guys. I will post more information when I modify and sharpen my skills in C++ or if I continue to have some problems. I will look into what you have mentioned.

To answer your question yes I am new to c++ and this was my first attempt at creating classes.

Kevin
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 24th Aug 2009 04:22
Quote: "looks like the "black" object is an instance of the class that it is operating inside of...."


I agree with that. Is kind of wierd, unless his enemies can spawn more duplicates of themselfs on a certain condition that calls the spawn method. But, ...

Still, kind of hard to see when we don't have the full source code. I can understand not wanting to share all your hard work.

He said he commented code out in that code where it stops giving that error. What exactly did he comment out in that code? Or did he have to comment everything out in that code? Need more info...

Kevin002
15
Years of Service
User Offline
Joined: 23rd Aug 2009
Location:
Posted: 24th Aug 2009 15:00
ok here is more information. I run the Enemies::Spawn Method through my main gameplay loop.



As you can see most of it is commented out, if only Enemies::Spawn was called in this loop the game would give me this error. If I simply didn't call it, the game worked fine. It just didn't spawn any enemies.

Here is the Enemies class which is located in the Enemies.h file



Kevin
Kevin002
15
Years of Service
User Offline
Joined: 23rd Aug 2009
Location:
Posted: 26th Aug 2009 06:12
Fixed it. after revision and reading a c++ book I rewrote my class so that it wasn't so weird

The problem was simply that

EnemyY = dbSpriteY ( Sprite );

dbSprite(sprite) can't be called before sprite has been created.

Thanks for all the help guys.

Kevin

Login to post a reply

Server time is: 2024-10-01 12:19:58
Your offset time is: 2024-10-01 12:19:58