Jump to content

  • Log In with Google      Sign In   
  • Create Account

SFML crash when debugging, but ok on release.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 Meerul264   Members   -  Reputation: 130

Like
0Likes
Like

Posted 27 July 2013 - 06:05 AM

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.



Sponsor:

#2 Olof Hedman   Crossbones+   -  Reputation: 2823

Like
0Likes
Like

Posted 27 July 2013 - 07:42 AM

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.



#3 SiCrane   Moderators   -  Reputation: 9594

Like
0Likes
Like

Posted 27 July 2013 - 07:50 AM

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



#4 Meerul264   Members   -  Reputation: 130

Like
0Likes
Like

Posted 27 July 2013 - 09:16 AM


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.


#5 Meerul264   Members   -  Reputation: 130

Like
0Likes
Like

Posted 27 July 2013 - 03:10 PM

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.


#6 Servant of the Lord   Crossbones+   -  Reputation: 19507

Like
0Likes
Like

Posted 27 July 2013 - 03:23 PM

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.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#7 Dragonsoulj   Crossbones+   -  Reputation: 2111

Like
0Likes
Like

Posted 27 July 2013 - 03:26 PM

 


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.



#8 Meerul264   Members   -  Reputation: 130

Like
0Likes
Like

Posted 27 July 2013 - 03:48 PM


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");
}
 
}


#9 Servant of the Lord   Crossbones+   -  Reputation: 19507

Like
0Likes
Like

Posted 27 July 2013 - 03:56 PM

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"?


Edited by Servant of the Lord, 27 July 2013 - 03:56 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#10 Meerul264   Members   -  Reputation: 130

Like
0Likes
Like

Posted 27 July 2013 - 04:03 PM

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


Edited by Meerul264, 27 July 2013 - 04:04 PM.


#11 Servant of the Lord   Crossbones+   -  Reputation: 19507

Like
0Likes
Like

Posted 27 July 2013 - 04:29 PM

Yeah, that kind of mistake occurs alot. Part of programming is learning good practices that reduces or removes those kind of mistakes.

 

Two solutions:

 

1) Don't use "magic numbers" in your code. '10' in your code doesn't mean anything, and neither does '2'. Changing them in one place requires you to remember changing them in other places (sometimes dozens). Instead, it's much better to replace magic numbers with well-named constant variables. Changing the constant's value automaticly makes all the code that uses the constant still work properly.

 

Example:

//The value is only set once, in a specific location.
const int PROMPTED_TEXT_COUNT = 10;

//In one location:
sf::Text promptedText[PROMPTED_TEXT_COUNT];

//In another location:
for(size_t i = 0; i <  PROMPTED_TEXT_COUNT; i++) { ... }

2) You could make it a std::vector. Or, if you're using C++11, you could make it a std::array. std::vectors keep track of their size as part of their class, and can still be accessed through the [] subscript operator during for() loops, and can also be used with vector.at(n) which double-checks that that location is valid before accessing.

 

Your for-loop would then look like:

//If you're using C++11's new range-for() syntax:
for(sf::Text &text : promptedText)
{
     text.setFont(font);
}

//If you're not using C++11's range-for():
for(size_t i = 0; i < promptedText.size(); i++)
{
     promptedText[i].setFont(font);
}

I'd also make sure "text[i].setFont(font);" and  "promptedText[i].setFont(font);" are in different for()-loops, unless you're 100% confident that they will always forever have the same number of elements as each other.


Edited by Servant of the Lord, 27 July 2013 - 04:46 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#12 Meerul264   Members   -  Reputation: 130

Like
0Likes
Like

Posted 27 July 2013 - 04:41 PM


//If you're not using C++11's range-for():
for(int i = 0; i < promptedText.size(); i++)
{
     promptedText[i].setFont(font);
}

You are using promptedText.size(). Doesn't that require promptedText.push_back(sf::Text &) first? Is this possible if I were to initialise the font of this text before i begin the game loop (i.e before window is open) ?

 

Or you are saying that I have to implement the std::vector's reserve() or resize() first?


Edited by Meerul264, 27 July 2013 - 04:42 PM.


#13 Servant of the Lord   Crossbones+   -  Reputation: 19507

Like
0Likes
Like

Posted 27 July 2013 - 04:46 PM

Oh, yes, most certainly resize to the correct size first. I was (incorrectly) assuming your code was already doing that in your existing array elsewhere.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#14 Meerul264   Members   -  Reputation: 130

Like
0Likes
Like

Posted 27 July 2013 - 04:57 PM

I see. Thanks again :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS