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

Author Topic: [Solved] Execution does not terminate when window closes (VS2010)  (Read 4455 times)

0 Members and 1 Guest are viewing this topic.

DocHoncho

  • Newbie
  • *
  • Posts: 4
    • View Profile
Hello!

I'm having an issue with SFML & Visual Studio 2010 where when the window is closed, the application itself does not terminate.  I followed the tutorial and have a basic SFML skeleton app. 

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main( int argc, char *args[] )
{
        sf::RenderWindow window( sf::VideoMode( 640, 480 ), "Window" );
        window.setFramerateLimit( 60 );

        while ( window.isOpen() ) {
                sf::Event event;

                while ( window.pollEvent( event ) ) {
                        switch ( event.type ) {
                        case sf::Event::Closed:
                                window.close();
                                break;

                        case sf::Event::KeyReleased:
                                if ( event.key.code == sf::Keyboard::Escape ) {
                                        window.close();
                                }
                                break;
                        }

                }

                printf( "Loopin..\n" );
                window.clear();
                window.display();
        }

        printf( "Quittin...\n" );
        return EXIT_SUCCESS;
}
 

When run, "Loopin..." is repeated in the console, until the window is closed.  It prints "Quittin..." and then hangs until I close the console window.  I'm having the same issue when compiled as a Windows application as well, although in that case there is no indication that the program is still running unless run from within VS.  In the Windows App case, the program must be terminated from the Task Manager.

I've searched around quite a bit and nothing has really helped.  Per some suggestions, I put in a break point to see what is executing after it is supposed to close, and as far as I can tell it's sitting in ntdll.dll doing... something.

I'm at wits end here.  There are no apparent functions/methods for "quitting" SFML, it just seems like Windows doesn't want to let the app die.  I've seen behavior like this in say, pyGame, where depending on how the program was run (e.g., IDLE, console, etc.) execution wouldn't terminate unless pygame.quit() was explicitly called.

In case this helps, here are the command lines being run by VS to build the program.

C++:
/I"c:\dev\sfml-2.1_vs10\include" /ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_WINDOWS" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"Debug\SFML_Test_vs10.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue

Linker:
/OUT:"c:\dev\SFML_Test_vs10\Debug\SFML_Test_vs10.exe" /NOLOGO /LIBPATH:"c:\dev\sfml-2.1_vs10\lib" "sfml-main-d.lib" "sfml-graphics-d.lib" "sfml-window-d.lib" "sfml-system-d.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"*SNIP*" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"*SNIP*" /SUBSYSTEM:CONSOLE /PGD:"*SNIP*" /TLBID:1 /ENTRY:"main" /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

Thanks in advance for any help you can offer!

EDIT:  I should point out that this behavior happens when program is run outside of VS as well, in both Release and Debug configurations.  So it doesn't seem to be strictly a VS thing.
« Last Edit: November 06, 2013, 11:54:04 pm by DocHoncho »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Execution does not terminate when window closes (VS2010)
« Reply #1 on: November 06, 2013, 07:37:13 am »
You can use your debugger to find out where the execution is stuck.
Laurent Gomila - SFML developer

DocHoncho

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Execution does not terminate when window closes (VS2010)
« Reply #2 on: November 06, 2013, 07:52:24 am »
As I mentioned before, when I pause the execution after the program should have closed, the debugger shows ntdll.dll!77da015d() at the top of the call stack.  Just noticed, the address in the disassembly window says "_write_nolock(int, const void *, unsigned int)".  Also, two threads terminate and two more remain active.

It still does this when the code is reduced to
#include <Windows.h>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main( int argc, char *args[] )
{
        sf::RenderWindow window( sf::VideoMode( 640, 480 ), "Window" );

        printf( "Quittin...\n" );
        return EXIT_SUCCESS;
}

And does not do it when the window variable is removed.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Execution does not terminate when window closes (VS2010)
« Reply #3 on: November 06, 2013, 08:22:40 am »
The top of the call stack is usually meaningless in such situations, because it is deep inside the system libraries. What would be more interesting is the complete stack.
Laurent Gomila - SFML developer

TheRabbit

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Execution does not terminate when window closes (VS2010)
« Reply #4 on: November 06, 2013, 10:05:36 pm »
I can almost guarantee it's a problem with your project settings.

I notice you're using main, what's your console doing?

DocHoncho

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Execution does not terminate when window closes (VS2010)
« Reply #5 on: November 06, 2013, 11:01:43 pm »
I can almost guarantee it's a problem with your project settings.

I notice you're using main, what's your console doing?

That depends.  The version posted here is set to use the console subsystem.   When executed it prints "Loopin..." until the window is closed; it then prints "Quitting...", returns 0 and then hangs.   I have also compiled using the Windows subsystem with the entry point set to main and linking with sfml-main, both with an allocated console and without.  Either way it behaves the same, the process  remains running after the window closes and my code returns 0.

Is there a way to export project settings as a text file?  I can try to post that later tonight when I get home.

DocHoncho

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Execution does not terminate when window closes (VS2010)
« Reply #6 on: November 06, 2013, 11:52:38 pm »
Ok, it figures that once I ask for help I end up figuring it out.  I decided to try using the standard WinMain signature and changing the configuration to use the default entry point.  It worked correctly, that is, execution correctly terminates  after the window closes.  Not being satisfied with using the derpy Windows specific way, I changed the main signature back to the standard definiton and linked against sfml-main.  The key difference is that I left the entry point as default, and once again it worked!

I don't know if I missed something, but the usage of sfml-main isn't well documented.  Oh well, thanks for your help guys.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [Solved] Execution does not terminate when window closes (VS2010)
« Reply #7 on: November 07, 2013, 07:45:11 am »
Quote
Is there a way to export project settings as a text file?
Project files are already human-readable XML files.

Quote
the usage of sfml-main isn't well documented
What point exactly is not documented properly?
Laurent Gomila - SFML developer

 

anything