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

Author Topic: Basic Window, Getting error after closing it  (Read 5632 times)

0 Members and 1 Guest are viewing this topic.

SEnergy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Basic Window, Getting error after closing it
« on: June 07, 2012, 05:14:25 pm »
Hello,

I've just did a basic window with this tutorial: http://sfml-dev.org/tutorials/1.6/window-events.php but when I close it, I'll get this debug error:
Code: [Select]
A buffer overrun has occurred in SFMLtest.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.

For more details please see Help topic 'How to debug Buffer Overrun Issues'.

this is my code:

Code: [Select]
#include <SFML/Window.hpp>
using namespace sf;

#pragma comment (lib, "sfml-window.lib")

int main()
{
Window MainWindow(VideoMode::GetMode(0), "SFMLTest");

bool running = true;
while(running)
{
Event Event;
while(MainWindow.GetEvent(Event))
{
if(Event.Type == Event::Closed)
running = false;
if((Event.Type == Event::KeyPressed) && (Event.Key.Code == Key::Escape))
running = false;
}

MainWindow.Display();
}

return 0;
}

also the title name of window is not "SFMLTest" but some weird characters...

ALSO I have another problem,

I've tried to include sfml-main.lib
Code: [Select]
#pragma comment (lib, "sfml-main") so it won't open console window but only app window but it's not working and it will open console window anyway...[/code]
« Last Edit: June 07, 2012, 05:24:02 pm by SEnergy »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Basic Window, Getting error after closing it
« Reply #1 on: June 07, 2012, 06:11:12 pm »
There are several things wrong or not that appreciated with your code/setup.
Upfront I highly suggest to use SFML 2, since SFML 1.6 has many problems which will never get fixed (one might even cause your problem) and SFML 2 is already out as RC which means it will soon be the offical release.

Have taken a closer look at the example given in the documentation?
Also I really recommend to read the tutorial on VS setup fully!

IMHO it's not good to use the namespace sf although there might never be any collisions but it's really hard to tell which functions/classes come from where.

When you're finished with the tutorial you'll notice that you never need #pragma comment (lib, "sfml-xyz.lib") instead you set it up with the project. This has specially the advantage whenever you'd want to port it to another platform you only have to setup a new project/makefile and not change the codebase.

Now for your problem, at first sight I'd say it's the nasty ATI bug of SFML 1.6. Do you have an ATI graphics card?
If you look at the example you'll notice that sf::Window has a IsOpened() function, which makes your bool running obsolent (except if you're doing some other stuff which I don't see atm).

Next you should also close the window after the close event was propageted. Although it probably gets called automatically in the destructor.

I guess the missing '.lib' is a typo, right?
#pragma comment (lib, "sfml-main.lib")
But you'll have to change the project settings to compile as 'window' and not as 'console'.

As a side note, this board has highlighting functionalities for code (dropdown box top left). ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

SEnergy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Basic Window, Getting error after closing it
« Reply #2 on: June 07, 2012, 06:36:59 pm »
There are several things wrong or not that appreciated with your code/setup.
Upfront I highly suggest to use SFML 2, since SFML 1.6 has many problems which will never get fixed (one might even cause your problem) and SFML 2 is already out as RC which means it will soon be the offical release.

Have taken a closer look at the example given in the documentation?
Also I really recommend to read the tutorial on VS setup fully!

IMHO it's not good to use the namespace sf although there might never be any collisions but it's really hard to tell which functions/classes come from where.

When you're finished with the tutorial you'll notice that you never need #pragma comment (lib, "sfml-xyz.lib") instead you set it up with the project. This has specially the advantage whenever you'd want to port it to another platform you only have to setup a new project/makefile and not change the codebase.

Now for your problem, at first sight I'd say it's the nasty ATI bug of SFML 1.6. Do you have an ATI graphics card?
If you look at the example you'll notice that sf::Window has a IsOpened() function, which makes your bool running obsolent (except if you're doing some other stuff which I don't see atm).

Next you should also close the window after the close event was propageted. Although it probably gets called automatically in the destructor.

I guess the missing '.lib' is a typo, right?
#pragma comment (lib, "sfml-main.lib")
But you'll have to change the project settings to compile as 'window' and not as 'console'.

As a side note, this board has highlighting functionalities for code (dropdown box top left). ;)

I have nvidia, not ATI

missing lib is not a typo, I deleted it because I thought that this is causing problem, and no I didn't take a close look at documentation example since I was taking examples from tutorial section (displaying window and handling events)

also I've setup everything right, Ieven have preprocessor (don't know if it is needed in my case but I did it, also tried it without it - same result), and including lib via #pragma is just same as doing it in properties, just faster and more flexible for me (I'm not going to recompile it to another platforms)

namespace sf - I'm using only sfml libs so far and they have only SF, so everything comes from sfml

I've changed my loop to MainWindow.IsOpened() and it's causing same error over and over again

so basically I've changed it to this:

Code: [Select]
#include <SFML/Window.hpp>
using namespace sf;

#pragma comment (lib, "sfml-window.lib")
#pragma comment (lib, "sfml-main.lib")

int main()
{
Window MainWindow(VideoMode::GetMode(0), "SFMLTest");

while(MainWindow.IsOpened())
{
Event Event;
while(MainWindow.GetEvent(Event))
{
if(Event.Type == Event::Closed)
MainWindow.Close();
if((Event.Type == Event::KeyPressed) && (Event.Key.Code == Key::Escape))
MainWindow.Close();
}

MainWindow.Display();
}

return 0;
}

and there is not any difference, it still has weird characters in title name instead of normal name and it's causing that error when closing

and I forgot that main, well, I don't have any settings for a console application in VS, there isn't such settings, I've created EMPTY project, which I'm using for both, win32 and console applications and it's working fine, main - console, WinMain - win32

also I have no idea what highlight function you mean, I don't see anything here O_o


EDIT:

I've downloaded and compiled SFML 2, and I'm getting those errors when compiling:

Code: [Select]
1>  source.cpp
1>source.cpp(12): error C2039: 'IsOpened' : is not a member of 'sf::Window'
1>          C:\Users\PCCCPCPCPC\Desktop\SFML-2.0\include\SFML/Window/Window.hpp(57) : see declaration of 'sf::Window'
1>source.cpp(12): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

downloaded it from git, generated with cmake, compiled libs with 8 successfull and 0 failed, copied libs and includes to SFML-2.0 folder ondesktop (SFML-2.0/libs & /include), changed path in settings
« Last Edit: June 07, 2012, 07:03:41 pm by SEnergy »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Basic Window, Getting error after closing it
« Reply #3 on: June 08, 2012, 09:51:20 am »
Quote
I've downloaded and compiled SFML 2, and I'm getting those errors when compiling:
functions name have changed since 1.6. e.g. IsOpened is now isOpen. Read the doc/forum to find their new name.
SFML / OS X developer

SEnergy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Basic Window, Getting error after closing it
« Reply #4 on: June 08, 2012, 10:57:44 am »
yeah it's working with 2.0, everything is fine BUT I'm still getting console window even if I have sfml-main.lib included

Code: [Select]
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
using namespace sf;

#pragma comment (lib, "sfml-window.lib")
#pragma comment (lib, "sfml-main.lib")

int main()
{
Window MainWindow(VideoMode(800, 600, 32), "SFMLTest");

while(MainWindow.isOpen())
{
Event Event;
while(MainWindow.waitEvent(Event))
{
if(Event.type == Event::Closed)
MainWindow.close();
}

MainWindow.display();
}

return 0;
}

also key::Escape is not working, because "key" does not exist, how can I fix it? can someone link me documentation for 2.0 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Basic Window, Getting error after closing it
« Reply #5 on: June 08, 2012, 11:14:05 am »
Quote
also I have no idea what highlight function you mean, I don't see anything here O_o
The "Code" dropdown list in the WYSIWYG editor, so that you can select the language and get "code=cpp" tags (which highlights the code accordingly).

Quote
yeah it's working with 2.0, everything is fine BUT I'm still getting console window even if I have sfml-main.lib included
Please read the tutorial, everything is explained.

Quote
also key::Escape is not working, because "key" does not exist, how can I fix it? can someone link me documentation for 2.0 ?
sfml-dev.org >> Documentation >> 2.0.
Was it too hard to find? :P
Laurent Gomila - SFML developer

SEnergy

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Basic Window, Getting error after closing it
« Reply #6 on: June 08, 2012, 01:58:09 pm »
Quote
also I have no idea what highlight function you mean, I don't see anything here O_o
The "Code" dropdown list in the WYSIWYG editor, so that you can select the language and get "code=cpp" tags (which highlights the code accordingly).

Quote
yeah it's working with 2.0, everything is fine BUT I'm still getting console window even if I have sfml-main.lib included
Please read the tutorial, everything is explained.

Quote
also key::Escape is not working, because "key" does not exist, how can I fix it? can someone link me documentation for 2.0 ?
sfml-dev.org >> Documentation >> 2.0.
Was it too hard to find? :P

well I've included that lib and that's everything it says there... it wasn't working so I used
int wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, INT nShowCmd)
and it's working, I'm not going to compile it for another OSs so far so w/e ... anyway thanks for your help, everything is working so far :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Basic Window, Getting error after closing it
« Reply #7 on: June 08, 2012, 02:07:35 pm »
The tutorial really explains it.

Quote
The first thing to do is to choose what kind of project to create: you must select a "Win32 application". The wizard offers a few options to customize the project: select "Console application" if you need the console, or "Windows application" if you don't want it.
Quote
If you chose to create a "Windows application" project, then the entry point of your code has to be the "WinMain" function instead of "main". Since it's Windows specific, and your code would therefore not compile on Linux or Mac OS X, SFML provides a way to keep a standard "main" entry point in this case: link your project to the sfml-main module ("sfml-main-d.lib" in Debug, "sfml-main.lib" in Release), the same way you linked sfml-graphics, sfml-window and sfml-system.
Laurent Gomila - SFML developer