SFML community forums

Help => General => Topic started by: blueeyedlion on May 03, 2013, 11:36:56 pm

Title: [Solved] Crashing within sf::RenderWindow constructor.
Post by: blueeyedlion on May 03, 2013, 11:36:56 pm
I just downloaded the latest SFML 2, and now I have mysterious crashes when going over the sf::RenderWindow constructor.  With this makefile and code, "test 1" is displayed, then the program crashes.  I am not very familiar with static linking, so that could be the cause.  Any help would be greatly appreciated.

compile = -c -Wall -std=c++0x -g # -mwindows
link = -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -g  # -mwindows -lsfml-main
objects = sfmlTesting.o

all: $(objects)
        g++ $(objects) $(link) -o sfmlTesting.exe

sfmlTesting.o: sfmlTesting.cpp
        g++ sfmlTesting.cpp $(compile)

check-syntax:
        g++ -Wall -o nul -std=c++0x -S ${CHK_SOURCES}
 

#define SFML_STATIC

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

int main()
{
    std::cout << "test 1" << std::endl;
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    std::cout << "test 2" << std::endl;
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 
Title: Re: Crashing within sf::RenderWindow constructor.
Post by: Laurent on May 04, 2013, 08:09:22 am
Make sure that the SFML package that you downloaded matches your compiler perfectly. If it matches, then try to remove the -std=c++0x flag.

By the way, SFML_STATIC should not be defined in source code, but rather in your compile flags (-DSFML_STATIC).
Title: Re: Crashing within sf::RenderWindow constructor.
Post by: blueeyedlion on May 04, 2013, 11:59:08 pm
Updating the compiler fixed everything.  Thanks.