Game crashes when running the .exe

Started by
7 comments, last by Steve_Segreto 11 years, 4 months ago

I recently started translating a small platformer game from C# to C++ as a school project. The game works perfectly fine when I run it in debug and release mode in Visual C++, but when I run the .exe in the release folder it crashes after 1 second. It only shows a frozen image of the game and then instantly crashes. I copied the game data such as textures and music to the release folder so it's not missing any files. I figured out that it can't be caused by DirectX either because it shows all the textures, but frozen, so it's not getting through the update function. For sounds I'm using the FMOD library. I copied the dll into the release folder of the game and even tried removing the whole sound system from the game, but it's still crashing. Once again, everything works fine when I run the game inside Visual C++. Any idea what's causing the crash?

Advertisement
From my experience this type of behaviour can occur from wrong use of SIMD XMVECTOR, XMMATRIX types<br />If you use those types in function calls or as datamembers of your class, you need to make sure they are properly aligned.<br /><br /><br />http://msdn.microsoft.com/en-us/library/windows/desktop/ee418725%28v=vs.85%29.aspx<br /><br />

You really need to write some error handling on all of your calls. Otherwise this is what happens.

The game works perfectly fine when I run it in debug and release mode in Visual C++, but when I run the .exe in the release folder it crashes after 1 second. It only shows a frozen image of the game and then instantly crashes.
Does the Debug build crash in the same way when run outside of the IDE? You could also modify your Release profile (or copy it) to include the debug symbols, and then attempt to attach a debugger to the program after it has started.

I copied the game data such as textures and music to the release folder so it's not missing any files.
This is brittle. Keeping this in sync manually is tedious and error prone. Consider instead using the command line, or a batch file, to ensure the project directory is the current working directory. A simple debug.bat and/or release.bat in the project directory that calls Debug/Program.exe or Release/Program.exe respectively should suffice.

Also, consider temporarily deleting all your resources from the project directory (I presume you can retrieve them from version control). Ensure that when you run the program from the IDE, it (at least) correctly reports the file(s) it is missing, rather than crashing.

Also keep in mind that running in the IDE (debug or release) will initialize data to different values than just 0 - if you don't initialize the data yourself that is :)

However as pointed out, if you build your release version with symbols (pdb files), then you can launch the process using Visual Studio and debug from there. My guess is either un-initialized data behaving differently outside the IDE or a missing file resulting from your error-prone process of keeping the game assets in a different folder between IDE and explorer execution.

Sorry I forgot to mention that I do have error handling in all my initialize and load functions.
I still haven't found what's causing the crash. When I start the game I see all the objects and background but nothing moves, I even hear the background music, and then after 1 or 2 seconds I get the "Game.exe has stopped working" message. I tried to remove everything from FMOD from the game one more time, but that didn't help either.
The only thing I'm not sure about are the extern class variables. I'm defining new class variables in my main .cpp file, and defining external variables for them in the other .cpp files. This is correct right?
From my experience this type of behaviour can occur from wrong use of SIMD XMVECTOR, XMMATRIX types<br />If you use those types in function calls or as datamembers of your class, you need to make sure they are properly aligned.<br /><br /><br />http://msdn.microsoft.com/en-us/library/windows/desktop/ee418725%28v=vs.85%29.aspx<br /><br />
I'm not using those types. I only use D3DXVECTOR3 for the texture positions. Could this in any way cause my crash?

Does the Debug build crash in the same way when run outside of the IDE? You could also modify your Release profile (or copy it) to include the debug symbols, and then attempt to attach a debugger to the program after it has started.
Both debug and release mode work fine in the IDE, and they both crash when I run it outside of the IDE.
Also keep in mind that running in the IDE (debug or release) will initialize data to different values than just 0 - if you don't initialize the data yourself that is smile.png

However as pointed out, if you build your release version with symbols (pdb files), then you can launch the process using Visual Studio and debug from there. My guess is either un-initialized data behaving differently outside the IDE or a missing file resulting from your error-prone process of keeping the game assets in a different folder between IDE and explorer execution.
Visual C++ always gives errors or at least warnings for uninitialized data, or am I wrong?

EDIT:
I found the issue. It was a char variable for displaying scores that was defined as a new char twice. The debugger somehow ignored it but it caused the game to crash outside Visual C++.
Thanks for all the suggestions!

[quote name='VisualChaser' timestamp='1356337826' post='5013896']
Visual C++ always gives errors or at least warnings for uninitialized data, or am I wrong?
[/quote]

Depends on warning level, I think level 4 turns those into errors.

[quote name='Steve_Segreto' timestamp='1356405610' post='5014076']
Depends on warning level, I think level 4 turns those into errors.
[/quote]

I already can't compile in debug mode /W3 if variables were not initialized

from time to time i find time

[quote name='~Helgon' timestamp='1356438311' post='5014151']
Steve_Segreto, on 24 Dec 2012 - 19:20, said:


Depends on warning level, I think level 4 turns those into errors.





I already can't compile in debug mode /W3 if variables were not initialized
[/quote]

Yeah I guess Visual Studio 2008 does it a bit different. I have two settings, Warning Level and Treat Warnings as Errors. I can compile and link no problem when I use an un-initialized variable under /W3 because it doesn't generate a warning. However YMMV with other Visual Studio versions.

This topic is closed to new replies.

Advertisement