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

Author Topic: RenderWindow object crashes during Graphics Tutorial.  (Read 7398 times)

0 Members and 1 Guest are viewing this topic.

Stewbond

  • Newbie
  • *
  • Posts: 9
    • View Profile
RenderWindow object crashes during Graphics Tutorial.
« on: October 08, 2011, 01:47:45 pm »
Hello,

I'm on my second day of learning SFML.  I got through the window tutorial without issue, however I am having problems with the graphics tutorial.  Sample code from the sprites tutorial is given below.  I can compile this without issue, however when I run this, the program crashes when I use
    App.GetEvent(Event)
    App.Clear()
    App.Display()
    App.Close()

These worked fine when App was defined as sf::Window but doesn't work with sf::RenderWindow.  I've read through the forums a bit and found that someone had a similar problems which were solved by updating their video card driver.  I've run other games on this PC with more complicated graphics so I'm not sure why my video-card would not work for this very specific case.  Regardless I've tried updating my driver and found that it is the most recent one available.  I've also read that someone needed to re-compile SFML 1.6 for VC++ 2010 because his definition of the RenderWindow didn't work.  I'm not sure quite how to do that, but my RenderWindow definition works so I don't think that is the problem.

Does anyone have any ideas?  I am running SFML 1.6 (built for VC++ 2008) with MS Visual C++ 2010 in Windows 7.  I'm compiling in Debug mode. I'm using the SFML release libraries and DLLs.  My video card is an NVIDIA GeForce 8600 GT with NVIDIA driver version 8.17.12.6099.

Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

    sf::Image Image;
    if (!Image.LoadFromFile(".//Images//Katie.png")) //This file exists and is loaded.
        return EXIT_FAILURE;

    sf::Sprite Sprite(Image);

    Sprite.SetColor(sf::Color(0, 255, 255, 128));
    Sprite.SetPosition(200.f, 100.f);
    Sprite.SetScale(2.f, 2.f);

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event)) // This line crashes
            if (Event.Type == sf::Event::Closed) App.Close();

        float ElapsedTime = App.GetFrameTime();

        if (App.GetInput().IsKeyDown(sf::Key::Left))  Sprite.Move(-100 * ElapsedTime, 0);
        if (App.GetInput().IsKeyDown(sf::Key::Right)) Sprite.Move( 100 * ElapsedTime, 0);

        App.Clear(); // This line crashes
        App.Draw(Sprite);
        App.Display(); // This line crashes
    }
    return EXIT_SUCCESS;
}


[EDIT:] Here is the debug error provided by Visual Studio's Debug tool:
A buffer overrun has occurred in GraphicsTutorial.exe which has corrupted the program's internal state.
Thank you!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
RenderWindow object crashes during Graphics Tutorial.
« Reply #1 on: October 08, 2011, 02:14:36 pm »
The advice to recompile SFML for Visual Studio 2010 is true, because the VS 2008 libraries are not compatible. You can download the SDK, open the .sln solution for VS 2008, convert the project to VS 2010, and recompile everything.

Alternatively, you can directly start with SFML 2 and CMake. The advantage is, there are a lot of bugfixes, new features and you don't have to change your code when you eventually port projects to the new version ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Stewbond

  • Newbie
  • *
  • Posts: 9
    • View Profile
RenderWindow object crashes during Graphics Tutorial.
« Reply #2 on: October 09, 2011, 09:26:45 am »
I've spent the last 10 hours attempting to get a compiled version of SFML with Visual C++ and so far I am unsuccessful.

CMake was actually pretty easy to use.  The actual compilation went okay without errors (except that my DLLs all have a "-2" suffix).  

My problem now is I can't compile my current code with the headers included in the SFML 2.0 package.

It gives me errors such as GetEvent() is not a member of sf::Window or sf::RenderWindow.  When I compare the headers from 1.6 and 2.0, I find that these definitions are indeed missing.  Therefore it appears that the SFML 1.6 code that I've taken from the tutorial is not compatible with SFML 2.0.

I've reverted back to SFML 1.6 because I can compile my code now.  The problem still remains that it was built using VC++ 2008 while I am using 2010.  I am thinking of just installing Visual Studio 2008 but I need to confirm that this is the problem.

Like I said earlier, the other guy who used 2010 had his problems with the sf::RenderWindow App() line.  I don't have my problem in the same spot so it may not be the same issue.

Are there any other potential things I could try before I take this step?
Thank you!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
RenderWindow object crashes during Graphics Tutorial.
« Reply #3 on: October 09, 2011, 11:15:36 am »
Quote
Therefore it appears that the SFML 1.6 code that I've taken from the tutorial is not compatible with SFML 2.0.

Of course, 1.6 and 2.0 are a lot different. There's a list of modifications in the general forum.

Quote
The problem still remains that it was built using VC++ 2008 while I am using 2010

Yes, and you still need to recompile it with Visual C++ 2010 ;)
It's even easier with SFML 1.6, Visual studio solutions are provided directly. You just have to open them, let the assistant convert from 2008 to 2010, and compile.
Laurent Gomila - SFML developer

Stewbond

  • Newbie
  • *
  • Posts: 9
    • View Profile
RenderWindow object crashes during Graphics Tutorial.
« Reply #4 on: October 09, 2011, 11:44:47 am »
Ah ha!

I just recompiled SFML 1.6 by opening the .SLN file and then playing around a bit.  I've got everything working with is static libraries and the release DLLs.  This was my first time compiling someone else's solution so it took me a little while.

The Rendering Window tutorial now runs properly!
Thank you!

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
RenderWindow object crashes during Graphics Tutorial.
« Reply #5 on: October 18, 2011, 04:45:48 am »
Can you give some instructions of what you did?
I'm having a similar problem. I can compile the 'graphics solution', but at run time it crashes. The debugger points to the App.Display();  line. If I comment it, along with the App.Clear(sf::Color(200, 0, 0));, that also gives problems, the program runs.

I get: Unhandled exception at 0x00c29515 in NEW GAME.exe: 0xC0000005: Access violation reading location 0x42c80010.

Thank you.



Tobiski

  • Newbie
  • *
  • Posts: 8
    • View Profile
RenderWindow object crashes during Graphics Tutorial.
« Reply #6 on: October 19, 2011, 03:48:30 pm »
I'm having problems too, and I'm starting to have enough...

I've tried several different IDE, Visual Studio 2008, Visual Studio 2010 and Code::Blocks and none of them will open the graphics window. They only open the console window and that's it. I've tried building the SFML solution with VS2010 but it didn't help. And I have everything linked correctly in each IDE and it builds fine. Running the program isn't working.

If someone could tell me what to do, it would be great.

To add some more mystery into this is that it worked last week just fine when I was using sfml library

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
RenderWindow object crashes during Graphics Tutorial.
« Reply #7 on: October 19, 2011, 04:04:29 pm »
Don't forget the ATI bug, with SFML 1.6 and dynamic SFML libraries on Windows.

If this is it, switch to static libraries or to SFML 2.
Laurent Gomila - SFML developer

Tobiski

  • Newbie
  • *
  • Posts: 8
    • View Profile
RenderWindow object crashes during Graphics Tutorial.
« Reply #8 on: October 19, 2011, 04:06:14 pm »
Quote from: "Laurent"
Don't forget the ATI bug, with SFML 1.6 and dynamic SFML libraries on Windows.

If this is it, switch to static libraries or to SFML 2.

tried to compile it with static and dll both but didn't help, I'll give 2.0 a go

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
RenderWindow object crashes during Graphics Tutorial.
« Reply #9 on: October 19, 2011, 04:17:39 pm »
Quote
tried to compile it with static and dll both but didn't help

Can you explain what you did exactly?
Laurent Gomila - SFML developer

Tobiski

  • Newbie
  • *
  • Posts: 8
    • View Profile
RenderWindow object crashes during Graphics Tutorial.
« Reply #10 on: October 19, 2011, 04:23:23 pm »
Quote from: "Laurent"
Quote
tried to compile it with static and dll both but didn't help

Can you explain what you did exactly?

I opened the SFML.sln project from SFML-1.6\build\vc2008 directory with VS2010 Premium. Let it port the solution from 2008 to 2010, deleted the examples so that there was left sfml-audio, sfml-graphics, sfml-main, sfml-network, sfml-system and sfml-window in the project. Then I chose "Debug DLL" and "Build", "Release DLL" and "Build" and tried to run a program.

Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Window");

while(window.IsOpened())
{
sf::Event Event;
while(window.GetEvent(Event))
{
if(Event.Type == sf::Event::Closed)
{
window.Close();
}
}
window.Clear();
window.Display();
}
return EXIT_SUCCESS;
}


I couldn't get the window to show so I opened the same SFML solution again and chose "Debug static" "Rebuild" "Release static" "Rebuild" and tried again but it didn't work.

Tobiski

  • Newbie
  • *
  • Posts: 8
    • View Profile
RenderWindow object crashes during Graphics Tutorial.
« Reply #11 on: October 19, 2011, 05:33:49 pm »
Ok, now I had little patience when running the program in debug mode and the graphics window popped up about 10-15 seconds after I had started the program and works fine, but every time I run the program I have to wait for that 10-15 seconds???

and this is when I'm using VS2008

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
RenderWindow object crashes during Graphics Tutorial.
« Reply #12 on: October 19, 2011, 06:42:59 pm »
Windows 7?
Laurent Gomila - SFML developer

Tobiski

  • Newbie
  • *
  • Posts: 8
    • View Profile
RenderWindow object crashes during Graphics Tutorial.
« Reply #13 on: October 19, 2011, 06:53:10 pm »
Yes, Windows 7 Professional 64-bit Version 6.1 (Build 7601: Service Pack 1)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
RenderWindow object crashes during Graphics Tutorial.
« Reply #14 on: October 19, 2011, 06:57:52 pm »
Other people seem to have a similar problem on Windows 7. I also have Windows 7, but everything works fine for me.

Have you tried SFML 2 yet?
Laurent Gomila - SFML developer

 

anything