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

Author Topic: My window will only stay open for a second.  (Read 1199 times)

0 Members and 1 Guest are viewing this topic.

Geners

  • Newbie
  • *
  • Posts: 9
    • View Profile
My window will only stay open for a second.
« on: November 12, 2012, 06:08:37 am »
I am very new to the SFML libraries, I have been reading through the tutorials and decided to play around with it to see how it worked. Everything was working fantastically! I fixed my linker issues, Everything was running smoothly...

Until I Cleared the screen and drew a shape.
After I put in those two instructions the window now only stays open for a second then closes.

I am using SFML 1.6 with Windows Visual C++ 2008 Express edition.

Here is the code

#include "stdafx.h"
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
using namespace sf;
using namespace std;

int main(){


RenderWindow App(VideoMode(800,600,32), "Tutorial");
Shape rect = Shape::Rectangle (0, 0, 10, 10, Color::Red);
int NumberLoops = 0;
while(true) {
Event handle;

while(App.GetEvent(handle))
{
       

       
        cout << "Next loop has been made, It has looped" << NumberLoops << "times";
        NumberLoops++;
        cout << endl;
        if(handle.Key.Code == Key::Back || handle.Type == Event::Closed) {
                App.Close();
        cout << "Window closed";
        cout << endl;
        }
        if(handle.Type == Event::MouseButtonPressed) {
                cout << "Mouse button pressed?";
                cout << endl;
        }
       
        if(handle.Type == Event::MouseButtonReleased) {
                cout << "Mouse button released";
                cout << endl;
        }
}
App.Clear();
App.Draw(rect);
App.Display();
}


return EXIT_SUCCESS;
}

If I get rid of App.Clear(); and App.Draw(rect); It will run fine without closing, But apparently those two members of the RenderWindow class doesn't like my IDE very much.

Where have I gone wrong?

If it helps anything, this is what it says on the debug window when it closes.

STATUS_STACK_BUFFER_OVERRUN encountered
The thread 'Win32 Thread' (0x1e94) has exited with code -1073740791 (0xc0000409).
The thread 'Win32 Thread' (0x1f08) has exited with code -1073740791 (0xc0000409).
The thread 'Win32 Thread' (0x1e68) has exited with code -1073740791 (0xc0000409).
The thread 'Win32 Thread' (0xec) has exited with code -1073740791 (0xc0000409).
The program '[7824] Testing_sfml.exe: Managed' has exited with code -1073740791 (0xc0000409).
The program '[7824] Testing_sfml.exe: Native' has exited with code -1073740791 (0xc0000409).
 
« Last Edit: November 12, 2012, 07:09:54 am by Geners »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
AW: My window will only stay open for a second.
« Reply #1 on: November 12, 2012, 11:49:50 am »
I'd advise you to use SFML 2. SFML 1.6 is 2 years old and lacks quite a few features.

As for your problem, ready again hoe to handle events in the official tutorial. Checking for key code without checking if a key event has happend leads to undefinded behavior.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything