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 / Release Mode Executable Crashes

Author
Message
Ryklon
13
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 17th Oct 2011 14:55
Hello.
I'm a game programming beginner with some basic knowledge in C++.

I'm currently studying Dark Invaders to gather ideas on how would I improve my game development skills. In fact, I created a game patterned with Dark Invaders. Since I'm a complete newbie with game development, I based some of the codes in my game from Dark Invaders and currently analyzing and studying how those codes work.

Here is my problem. I tried to create an executable file through release mode in VC++ but unfortunately it the executable file crashes. I searched google for answers and found out that the problem might be some sort of array out of bounds or an uninitialized variable. I tried initializing all the globally declared variables but it still doesn't solve the problem.

Every time use the release mode to create executable files I encounter and error saying "Unhandled exception at 0x0000012e in Asteroid Blaster.exe: 0xC0000005: Access Violation". Pressing continue doesn't work while pressing break tells me this "No symbols are loaded for any call stack frame. The source code cannot be displayed."

I'm really confused where the source of the problem is. Please lend me a hand here if anyone of you got some solution or even just an idea to solve this problem.

I've attach the link for the whole source code files for your reference. it is located in the bottom. I'm prepared to accept all the constructive criticism and what nots for my bad programming. I'm aware of it, so yeah...LOL

Thanks in advance!

http://www.mediafire.com/myfiles.php
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 17th Oct 2011 21:24
Unfortunately the link just takes me to the login page of mediafire. Better zip together the source (.cpp and .h) files and attach the zip to your post.

Finding bugs in a release mode EXE is a pain because you don't have access to the debugger. You can try to put message boxes (MessageBoxA function) or prints (dbPrint) into the program at specific places to see how far it gets before it crashes, that helps narrow down the search. Also, make sure that the program can find all the media it tries to load (e.g. images) and that nothing is loaded twice with the same ID number.
Ryklon
13
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 18th Oct 2011 10:55
Oh, sorry for that one.

The program crashes somewhere in the function named gLevel. Since it crashes when the player begins to enter the level. I'm really confused where in the world is the source of this error located specifically. Instead of thinking improvements, I'm currently having nightmares dubugging this error. LOL.

Here. This is the whole project folder. Please help me deal with this one all for the sake of learning and improvement.

Thanks!

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Oct 2011 14:27 Edited at: 18th Oct 2011 14:29
Quote: "Please help me deal with this one all for the sake of learning and improvement."


Me too.

I've only recently started dabbling with DGDK and am baffled by the environment (I'm not a C++ programmer).

Out of curiosity I tried your download and the Debug version worked fine. When I try to run the Release version Windows stops the program saying that DEP has stopped it (and Windows won't let me turn DEP off for that program ).

Since I'm unfamiliar with the way VS handles Debug vs Release versions I tried the simple Hello World tutorial. The Debug version worked fine but the Release version just gave a black screen - run both within VS and as a standalone exe. [Edited wording. ]

So my "learning and improvement" question is "what do I have to do to create a standalone exe from a DGDK project?".
Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 18th Oct 2011 16:28 Edited at: 18th Oct 2011 16:36
I will look through your source code Ryklon, I'll will try to see what is wrong.

EDIT:

It could be that you are including "DarkSDK.h", you should include "DarkGDK.h". Something in your program is triggering Data Execution Prevention in release mode, it could be the "case..break" statements but I doubt it. I will look through more of your code when I get home from work.
Ryklon
13
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 18th Oct 2011 17:12
Thank you Mr Bigglesworth!

I'm looking forward to your replies.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Oct 2011 17:23 Edited at: 18th Oct 2011 17:31
Strange. It won't compile now. I get:



All I did was change



to



and back again.

Edit Just checked the zip file. It seems I was just running the zipped exe before (I keep forgetting to Rebuild rather than Build). So why won't this compile?
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 18th Oct 2011 21:46
I had a look at the project too. The program is fine, but your Visual Studio project settings are not good. When those are corrected, the program compiles and runs without any problem on my computer (Windows 7), both in debug and release mode.

Did you start the project from a Dark GDK template or just started an empty project? Always start from a Dark GDK template (you can use the empty game template, so that there is no disturbing extra sample code) because that contains all the settings you need. Don't change them if you don't know what they do, there are hundreds of them and it's easy to get lost. What I did was to compare the settings between a new Dark GDK project and yours, and change back what did not match. Fortunately the settings page indicates with bold letters if something is modified.

(Continued in the next post.)
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 18th Oct 2011 22:09
Here is a list of the settings I changed to match the template. Note that you have to change settings both for debug and release configuration, you can set what you are changing from the drop-down list. The settings can be the same of different for the different configurations.

C/C++, code generation page:

Runtime library: The Dark GDK defaults are "Multi-Threaded Debug (/MTd)" for debug configuration and "Multi-Threaded (/MT)" for release configuration. It's good to know that if you want to use anything from the standard library (e.g. vector, string, file stream), then set this to /MT for the debug configuration as well, otherwise it won't compile. (Frequent question on the forum.)

These three probably did not have anything to do with your problem but I set them back anyway (I don't know what they do):
Basic runtime checks: "default" for both configs.
Enable minimal rebuild: "no" for both configs.
Enable function-level linking: "no" for both configs.

C/C++ general page, debug information format: for the release config "disabled" (for debug config, edit and continue, that matched the template).

Linker, Input page:
Ignore specific libraries: for both configs list "libcmtd, msvcrt, atls". This is why the linker complained for Green Gandalf that it cannot open atls.lib, these should be ignored.

Linker, Debugging page:
Generate debug info: "no" for the release configuration (yes for the debug config, obviously, but a release build does not need it).

Linker, System page:
Subsystem: set Windows for both configs, otherwise more linker complaints will follow.

With these settings I was able to rebuild and run the program, but in the next post I'd like to say something about working directories as well.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 18th Oct 2011 22:49
A slightly annoying thing is that the working directory is different when you run the program from Visual Studio or from outside Visual Studio. When you press F5 to run the program in the debugger, usually the working directory is where the vcproj file is. You created an "Images" directory and load the images like this:



That works because the working directory contains the Images directory. However, the release-mode EXE should run independently from Visual Studio. You can start it in the debugger, but the good way to test it is to start the compiled EXE from your file manager. In that case, the working directory is where you start the EXE from. The compiled EXE is in another directory - by default the compiled files are in the "Debug" and "Release" subdirectories, and your media files are not inside these. So to test the final compilation, you either have to copy the EXE next to the media directory, or the media files into the EXE directory, otherwise the images won't be found. (@Green Gandalf: this might the problem with the Hello World tutorial, although I haven't tried it out.)

It's not so comfortable to copy all the time, or to keep media files in two copies, just for testing. It's possible to change where the EXE will be placed and also what the working directory will be.

In configuration properties, general: the "output directory" controls where the EXE will be. The "intermediate directory" controls where the compiler places its generated files, which are needed for compilation but not needed for running the finished program. If these are set to different directories, then the EXE will be separated from the intermediate files (which can be deleted any time).

On the configuration properties, Debugging page, the "working directory" controls which directory the debugger will set as its working directory when the program is running in the debugger.

Finally, in the Linker, general page, the "output file" setting controls the EXE file name. For example, if you want to put the debug and release EXE files into the same directory, you can change the name, so they won't overwrite each other.

By playing with these settings, it is possible to create a configuration in which your media files are kept in one place and both debug and release EXE files are searching for them in the same directory.

These settings use some linker variables (the dollar signs mean variables which will be substituted) but it's easy to guess what they mean.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 18th Oct 2011 23:00 Edited at: 18th Oct 2011 23:36
About including DarkGDK.h or DarkSDK.h: I opened the DarkGDK.h file and this is all it contains:



So, it seems the program may work if you include the other file (if those two defines are not missed somewhere, I don't know), but you are supposed to include DarkGDK.h. (EDIT: I changed the includes everywhere before recompiling the program.)

Finally, about zipping a project: You do not need to zip the large "ncb" file. That's a symbol table which Visual Studio regenerates automatically, as soon as you open the project. The "debug" and "release" directories are not needed either, since these are also generated by the compiler and can be deleted and re-built any time. It's good to remove these from the zip because they only increase the download size.

I didn't think I'd write such a long story but I hope it helps. If the program still crashes after changing the settings, then post again, but it works on my machine. (EDIT: If I try the EXE that is in the release directory in your zipped project, that crashes, but the one I recompiled with the new settings works.)
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Oct 2011 01:58
@Mireben

Thanks for all those suggestions. I'll try them out tomorrow.
Ryklon
13
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 19th Oct 2011 04:22
Gonna try what you suggested.
I'll keep you updated what happens next.
Ryklon
13
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 19th Oct 2011 05:33
@Mireben

I tried all what you said. In fact I created a whole new project with the DarkGDK 2D Template. Copy and pasted all the codes in the new project I created. I just copy and pasted the codes from my previous project, I did not do any import of files. I also checked all the settings according to what you stated above and everything is the same. But in the end the problem still exists. What happens is, when I compile the program in release mode, it still crashes immediately after entering the game level, giving me the same error message. Same happens when I copied the media directory to the release folder. It somehow executes but as soon as I entered the level by pressing the space bar, it crashes.
Ryklon
13
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 19th Oct 2011 07:23
UPDATE

Yay!

It seems that I've narrowed down the problem.
The problem seems to exist in the source file of my asteroid setup(asteroid.cpp). Looks like it is caused by my bad programming. XD

Mireben was right. I realized now that the crashing was caused because of the media files not included in the same folder as the exe file generated in release mode. I feel that the release mode crashing part is already solved. However, I'm still having crashing problems due to my bad programming but I guess that this is not the proper thread to discuss this kind of problem anymore. Just tell me guys whether I should create another thread to ask for help in debugging that particular source file or should I ask for help right here, right now in this thread. Just say so.

Thanks!
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 19th Oct 2011 08:17 Edited at: 19th Oct 2011 08:57
I have looked through the code which I didn't thoroughly check yesterday and have one more suggestion for you.

I've noticed that the program crashes not right after pressing the spacebar, but when the spaceship reaches the starting position and the program begins to update the asteroids. (So you are right, the trouble should be in asteroid.cpp.) This might be the cause:



Here you clone the sprite before it's created. The 401 you give in dbLoadImage is an image number, but dbCloneSprite expects a sprite number, and a sprite 401 does not exist at that point. It is created only in the dbSprite(401, .... 401) line afterwards.

In fact you can completely remove the lines that clone the sprites and the program will still work, because the dbSprite commands will create all the sprites.



Does that help? It's strange that I can't reproduce the crash on my machine, but this may well cause it.

Another thing that I noticed is that you delete the asteroid sprites when there is a collision. That means that in the next game loop, you will use dbMoveSprite and dbSpriteCollision commands for non-existent sprites. Dark GDK commands do not return error codes (unfortunately) but some of them write error codes into the first integer position on the stack. This can ruin the first variable of the main program, but I haven't yet seen a crash caused by this. In any case, deleting an asteroid comes much later than starting the level, so this is surely not the issue here. (EDIT: If this were the problem, the program would crash after hitting the first asteroid, but it doesn't get that far.) For the future, it would be better to solve it somehow that only existing sprites are referenced.

Otherwise, maybe the code is not as efficient as it could be (I would use arrays to handle sprites instead of copy-pasting code for each of them, and I would try to eliminate some of the global variables), but nothing else at first sight that would have such catastrophic results. (EDIT: that's why I looked at the settings, because the code seemed so straightforward that I didn't suppose the problem is in the coding.) Try removing the sprite cloning part, I hope that will solve it.
Ryklon
13
Years of Service
User Offline
Joined: 17th Oct 2011
Location:
Posted: 19th Oct 2011 08:51
Thanks a lot Mireben!

I'll try all the tips you said.
Dude, thanks for explaining that directory setting. That really lead me into thinking that the problem was on my coding. That one really nailed it.

I guess this thread ends here.
Thank you guys for sharing your brilliant ideas!

Login to post a reply

Server time is: 2024-11-19 06:53:15
Your offset time is: 2024-11-19 06:53:15