SFML crash when debugging, but ok on release.

Started by
12 comments, last by Meerul264 10 years, 8 months ago

I tried to search regarding this problem on google but couldn't find a similar case. The problems I found is vice versa of mine - crash when release but ok when debugging.

I already checked my project's configuration a dozen times but still can't find whats wrong.

Advertisement

In what way is it crashing?

My first guess is that it's because of uninitialized data. The value of the unintialized data will be different in release and debug, and might make one of the cases crash.

My second guess is misuse of some pointer that either writes outside a buffer, or in already freed memory. That could also lead to one case crashing and the other not.

In both cases it can go either way, release working and debug crashing, or debug working but release crashing.

For SFML another possibility is that you've linked to the release version of the library in debug mode.


In what way is it crashing?

Thanks for replying. The crash is that, it just produce white blank window. And when I try to click the window, it wouldn't respond (like when trying to click 'x' button to close the window). Also, this doesn't happen before I changed the code a bit. After I received this crash, I undo the changes I had made, but still get the crash. Why did this happen?


For SFML another possibility is that you've linked to the release version of the library in debug mode.

I don't think so.

Under my Configuration -> Debug -> Linker -> Input -> Additional dependencies:

sfml-graphics-d.lib
sfml-window-d.lib
sfml-system-d.lib

If I'm not mistaken, "-d" for debug, without the "-d" for release.

Also, I just realised I got this output when debugging:

'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dinput.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\hid.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wintrust.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt32.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msasn1.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ole32.dll'
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\apphelp.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cmd.exe'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\cmd.exe'
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cmd.exe'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\cmd.exe'
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cmd.exe'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\cmd.exe'
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cmd.exe'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\cmd.exe'
[...and the lists of similar kind of error goes on...]
I hope this can give you the clue to find what causes this crash. Thanks for the reply really appreciate it.

I also got this, is this important?

'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Users\Amirul\Documents\Visual Studio 2012\Projects\Dragon Villa SFML\Dragon Villa SFML\sfml-graphics-d-2.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Users\Amirul\Documents\Visual Studio 2012\Projects\Dragon Villa SFML\Dragon Villa SFML\sfml-window-d-2.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Users\Amirul\Documents\Visual Studio 2012\Projects\Dragon Villa SFML\Dragon Villa SFML\sfml-system-d-2.dll'. Cannot find or open the PDB file.

Here's my general process for solving these kinds of problems:

Step 1: "Rebuild all". This might fix your problem on its own.

Step 2: Scatter a few breakpoints around areas where you think the crash is occurring.

Step 3: Run your debugger, and when you hit a debugger, start stepping through the code (using your debugger's 'step' feature) bit by bit until it reaches the point where it crashes. This is how you know what line is causing the crash.

Step 4: Find out why that line is crashing. Is a pointer uninitialized? Are you dividing by zero? Was the object already destroyed?

Step 5: Fix the problem. If you need help with that part, after you've already found the cause of the problem, then show us the part that's crashing, and we might have a few ideas if, by that point, you haven't already solved it yourself - which is usually the case.

It's also not a bad idea to occasionally run your code through a static analyzer like cppcheck. Static analyzers read your code, without compiling it, and look for common mistakes that compile fine but don't work fine.


In what way is it crashing?

Thanks for replying. The crash is that, it just produce white blank window. And when I try to click the window, it wouldn't respond (like when trying to click 'x' button to close the window). Also, this doesn't happen before I changed the code a bit. After I received this crash, I undo the changes I had made, but still get the crash. Why did this happen?


For SFML another possibility is that you've linked to the release version of the library in debug mode.

I don't think so.

Under my Configuration -> Debug -> Linker -> Input -> Additional dependencies:

sfml-graphics-d.lib
sfml-window-d.lib
sfml-system-d.lib

If I'm not mistaken, "-d" for debug, without the "-d" for release.

Also, I just realised I got this output when debugging:

'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dinput.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\hid.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wintrust.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt32.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msasn1.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ole32.dll'
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\apphelp.dll'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cmd.exe'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\cmd.exe'
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cmd.exe'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\cmd.exe'
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cmd.exe'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\cmd.exe'
'Dragon Villa SFML.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cmd.exe'. Cannot find or open the PDB file.
'Dragon Villa SFML.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\cmd.exe'
[...and the lists of similar kind of error goes on...]
I hope this can give you the clue to find what causes this crash. Thanks for the reply really appreciate it.

Anytime I get a white screen it is because I am missing a .dll in the folder.


start stepping through the code (using your debugger's 'step' feature)

Lol thanks for introducing me to this interesting feature. i wouldn't know this exist.

Anyway i tried it out and found out that in main:

 
    TEXT.Set_Fonts(); // problem avoided when I commented this out and came back when I uncomment this
    TEXT.Set_Texts();
 

So I guess that is the root of the problem. But I couldn't figure out why is it so.

//in Texts.cpp
 
void Texts::Set_Fonts()
{
if(font.loadFromFile("Fonts/BNEfG98.ttf"))
{
for(int i = 0; i < 10; i++)
{
text[i].setFont(font);
promptedText[i].setFont(font);
}
 
FPS.setFont(font);
 
}
else
{
std::cout << "Failed to load fonts " << std::endl;
system("pause");
}
 
}

Did you step through ("step into") that function also?

My guess is that this part of the documentation might be causing some difficulty.

The sf::Text only keeps a pointer to the sf::Font. You have to make sure the sf::Font stays around for longer than the sf::Texts are in use.

Are you sure "if(font.loadFromFile())" is returning true? Is your debugging output saying, "Failed to load fonts"?

I figured out the problem. It was really a silly mistake. I made the array promptedText[] to have a size of 2 elements ( I should make it at least 10 ) and I forgot to change it to 10 . Really silly mistake.. But this make me wonder why it gives a green light on release.

Oh well I got it now. Thanks man smile.png

This topic is closed to new replies.

Advertisement