SFML community forums

Help => Window => Topic started by: niehoelzz on July 12, 2016, 12:30:40 am

Title: Window is closing after a few seconds
Post by: niehoelzz on July 12, 2016, 12:30:40 am
#include <SFML\Window.hpp>
#include <SFML\Graphics.hpp>
#include <iostream>


int main() {
        bool walkl = false, walkr = false;

        sf::RenderWindow mainwindow(sf::VideoMode(1920, 1080), "Mein Erstes Spiel", sf::Style::Default);
        // Adding Background
        sf::Texture background;
        background.loadFromFile("background.png");
        sf::Sprite backgroundsprite;
        backgroundsprite.setTexture(background);
       

        // As long as Window is open
        while (mainwindow.isOpen()) {
               
                // clear window
                mainwindow.clear();

                // Draw here
                mainwindow.draw(backgroundsprite);

                // end the current frame
                mainwindow.display();



                sf::Event event;
                while (mainwindow.pollEvent(event)) {
                        switch (event.type) {
                        case sf::Event::Closed:
                                mainwindow.close();
                                break;
                        case sf::Event::KeyPressed:
                                if (event.key.code == sf::Keyboard::D) {
                                        walkr = true;
                                }
                                else if (event.key.code == sf::Keyboard::A) {
                                        walkl = true;
                                }
                                break;
                        case sf::Event::KeyReleased:
                                walkr = false;
                                walkl = false;
                        }
                       
                       
                }

                if (walkr == true){
                        std::cout << "Bewege nach Rechts" << std::endl;
                }
                if (walkl == true) {
                        std::cout << "Bewege nach Links" << std::endl;
                }
        }


        return 0;
}

Why is my window closing after 5 - 10 seconds?  :-\
Title: Re: Window is closing after a few seconds
Post by: niehoelzz on July 12, 2016, 02:28:11 am
The Message is

The Program "[9952] GameDevelopment.exe" was endet with the code -1073740777 (0xc0000417).
Help me please i dunno what to do  :'(
Title: Re: Window is closing after a few seconds
Post by: eXpl0it3r on July 12, 2016, 03:11:32 am
Run it through the debugger and figure out what goes wrong.
Title: Re: Window is closing after a few seconds
Post by: niehoelzz on July 12, 2016, 12:14:54 pm
Run it through the debugger and figure out what goes wrong.
I already did but it enters the loop for like thousands of times and that in under 1msec so it would take forever to get the error
Title: Re: Window is closing after a few seconds
Post by: Laurent on July 12, 2016, 12:44:53 pm
Don't run step by step. The debugger halts the execution automatically when the crash happens.
Title: Re: Window is closing after a few seconds
Post by: niehoelzz on July 12, 2016, 03:43:28 pm
Don't run step by step. The debugger halts the execution automatically when the crash happens.

Heres some Output:
The Thread 0x3308 has ended with the code -1073740777 (0xc0000417).
The Thread 0x36bc has ended with the code -1073740777 (0xc0000417).
The Thread 0x39e4 has ended with the code -1073740777 (0xc0000417).
The Thread 0x32c0 has ended with the code -1073740777 (0xc0000417).
The Thread 0x4ed8 has ended with the code -1073740777 (0xc0000417).
The Thread 0x1408 has ended with the code -1073740777 (0xc0000417).
The Thread 0x2988 has ended with the code -1073740777 (0xc0000417).
The Thread 0x1fb8 has ended with the code -1073740777 (0xc0000417).
The Thread 0x4708 has ended with the code -1073740777 (0xc0000417).
The Thread 0x3808 has ended with the code -1073740777 (0xc0000417).
The Thread 0x21f0 has ended with the code -1073740777 (0xc0000417).
The Thread 0x2620 has ended with the code -1073740777 (0xc0000417).
The Thread 0x135c has ended with the code -1073740777 (0xc0000417).
The Thread 0xca4 has ended with the code -1073740777 (0xc0000417).
The Thread 0x300c has ended with the code -1073740777 (0xc0000417).
The Thread 0x405c has ended with the code -1073740777 (0xc0000417).
The Thread 0xc84 has ended with the code -1073740777 (0xc0000417).
The program "[19804] GameDevelopment.exe" was closed with the code -1073741510 (0xc000013a).

I dont know if it helps...
Ill try to run the Debug mode later cuz im reinstalling the Visual Studio right now maybe that will solve the problem... hopefully

It even wont work if its only the window which is drawn but it works if i use 'sf::Window' instead of 'sf::RenderWindow'
Title: Re: Window is closing after a few seconds
Post by: niehoelzz on July 12, 2016, 04:17:12 pm
After some Testing i found out that this happens when im adding the
mainwindow.display();
line.

But why?
Title: Re: Window is closing after a few seconds
Post by: Rosme on July 12, 2016, 06:45:11 pm
Are you linking correctly? Debug libraries with debug build? Release libraries with release build? You downloaded the correct library for your compiler?
Title: Re: Window is closing after a few seconds
Post by: niehoelzz on July 12, 2016, 07:15:24 pm
Are you linking correctly? Debug libraries with debug build? Release libraries with release build? You downloaded the correct library for your compiler?

Configuration Debug:
sfml-graphics-d.lib
sfml-window-d.lib
sfml-system-d.lib
sfml-network-d.lib
sfml-audio-d.lib

Configuration Release:
sfml-graphics.lib
sfml-window.lib
sfml-system.lib
sfml-network.lib
sfml-audio.lib

Visual Studio 2015        Sfml 14 (VS2015)
Title: Re: Window is closing after a few seconds
Post by: niehoelzz on July 12, 2016, 09:58:00 pm
It has to do with my Visual Studio. It works neither with Allegro. The Allegro window is closing after some time too.
Ill try to do it with Code blocks
Title: Re: Window is closing after a few seconds
Post by: niehoelzz on July 12, 2016, 11:08:19 pm
It works on my stupid laptop but i did exactly the same.