Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Unhandled exception in 2.0, NOT in 1.6  (Read 3125 times)

0 Members and 1 Guest are viewing this topic.

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Unhandled exception in 2.0, NOT in 1.6
« on: November 07, 2012, 05:55:32 am »
Hi, I'm quite new to SFML but decent in C++ and encountered a weird problem I thought I might share with you :)

I was following this tutorial, which is written with SFML 1.6. I've made a minimal working example to be found at the bottom.
In 1.6 it works as it should, but when converting to 2.0 I got an Unhandled exception and I have no clue why. All should be setup correctly since I've read the tutorial Getting Started multiple times to make sure I've made no mistake.

The error is at line 4 when creating a sf::Renderwindow in the global scope.
Could this be a bug or is it intentional? If it is intentional, can anyone point out why?

Working under Windows 7, in MS Visual C++ 2010 Express. Linked SFML 2.0 statically and the exact error is: Unhandled exception at 0x777122b2 in TestSFML_2.0.exe: 0xC0000005: Access violation writing location 0x00000004.

Here is the minimal working example for 1.6, thus working:
#include <SFML/Graphics.hpp>

// create window in global scope
sf::RenderWindow window;

// MAIN FUNCTION
int main(int argc, char *argv[]) {
        window.Create(sf::VideoMode(640,380), "SFML Window"); // initialize window

        // wait for close event to close
        sf::Event ev;
        while(window.IsOpened()) {
                while (window.GetEvent(ev)) {
                        if (ev.Type == sf::Event::Closed)
                                window.Close();
                }
        }
        return 0;
}

And for the error in 2.0, which throws an exception on line 4
#include <SFML/Graphics.hpp>

// create window in global scope
sf::RenderWindow window;

// MAIN FUNCTION
int main(int argc, char *argv[]) {
        window.create(sf::VideoMode(640,380), "SFML Window"); // initialize window

        // wait for close event to close
        sf::Event ev;
        while(window.isOpen()) {
                while (window.pollEvent(ev)) {
                        if (ev.type == sf::Event::Closed)
                                window.close();
                }
        }
        return 0;
}

Debug window (why are none of these files anywhere on my pc?):
Code: [Select]
'TestSFML_2.0.exe': Loaded 'C:\Users\Dieter\Documents\Visual Studio 2010\Projects\TestProject\Debug\TestSFML_2.0.exe', Symbols loaded.
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\dciman32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'TestSFML_2.0.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
First-chance exception at 0x777122b2 in TestSFML_2.0.exe: 0xC0000005: Access violation writing location 0x00000004.
Unhandled exception at 0x777122b2 in TestSFML_2.0.exe: 0xC0000005: Access violation writing location 0x00000004.
The program '[1300] TestSFML_2.0.exe: Native' has exited with code -1073741819 (0xc0000005).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Unhandled exception in 2.0, NOT in 1.6
« Reply #1 on: November 07, 2012, 08:43:57 am »
Don't declare your RenderWindow in global scope, something happens in its constructor and some internal objects of SFML might not be initialized at this point.

Next time you have a crash, use your debugger to get the exact line of the crash as well as the call stack. What you show is not the debug window, it's just the standard output, it says almost nothing about the crash.

Quote
why are none of these files anywhere on my pc?
Google knows the answer if you ask nicely.

Everybody asks about these messages (it happens on this forum at least once per week), thinking that they imply an error, but nodoby ever wonders "what is a PDB file?" or "am I really supposed to have them, and if so, how?". It's sad to see that programers just want their problems to be solved, they don't want to learn things :-\
« Last Edit: November 07, 2012, 08:47:55 am by Laurent »
Laurent Gomila - SFML developer

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Unhandled exception in 2.0, NOT in 1.6
« Reply #2 on: November 07, 2012, 02:14:45 pm »
I'm still learning how to use the debugger.. We learned to program in C++ in school, but always had to run it without debugging so I don't know much about it... I'll first try to search some about debugging and see what I find.
But I have still no clue why it doesn't throw an exception in 1.6. Is it a check SFML 2.0 performs while 1.6 just doesn't care?

And I was in fact asking myself what a PDB file was and why I needed those files, but the thread isn't about that, so I left it at what I wrote :) (most forum rules are to keep one topic for one question)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Unhandled exception in 2.0, NOT in 1.6
« Reply #3 on: November 07, 2012, 02:53:18 pm »
Quote
I'm still learning how to use the debugger.. We learned to program in C++ in school, but always had to run it without debugging so I don't know much about it... I'll first try to search some about debugging and see what I find.
Run your app with F5, and it will already give you interesting results: it will stop at the line which crashes, and show you the call stack in the "call stack" debug window (you may have to show it in the debug menu).

Quote
But I have still no clue why it doesn't throw an exception in 1.6. Is it a check SFML 2.0 performs while 1.6 just doesn't care?
No, but things are totally different in SFML 2 internally. Now SFML relies on internal globals, and they might be initialized after yours; in this case the behaviour is undefined and your app may crash. That's why you should avoid using SFML objects in global scope.
Laurent Gomila - SFML developer

didii

  • Full Member
  • ***
  • Posts: 122
    • View Profile
Re: Unhandled exception in 2.0, NOT in 1.6
« Reply #4 on: November 07, 2012, 03:34:26 pm »
No, but things are totally different in SFML 2 internally. Now SFML relies on internal globals, and they might be initialized after yours; in this case the behaviour is undefined and your app may crash. That's why you should avoid using SFML objects in global scope.
Makes sense. Thanks for the answer.