Reputation: 11
I'm starting to create a game with SFML and C++. However, I'm having one issue. I have the basic skeletal class code down, but for some reason, when I create a window(sf::Window), I immediately crash! This code does not contain any event checking code, but it did and it still crashed; besides, apparently, it should take several seconds to crash if it's because of the lack of event checking. Of course, once I see the window, I'll add it.
#include <iostream>
#include <windows.h>
#include <SFML/Window.hpp>
#include "GameBase.h"
#include "Character.h"
#include "GameStart.h"
using namespace std;
using namespace sf;
int main() {
GameStart::GameStart();
Clock timer;
cout << "Started." << endl;
Window GameWindow(VideoMode(640, 480),"Basic window");
while (1) {
Sleep(0.5f);
}
return 0;
}
I know that it is not the timer, GameStart or any of the other personal include files.
Upvotes: 1
Views: 1686
Reputation: 2629
I tried out that and it worked without problem :
#include <iostream>
#include <SFML/Window.hpp>
int main() {
std::cout << "Started." << std::endl;
sf::Window gameWindow( sf::VideoMode(640, 480),"Basic window");
while (gameWindow.IsOpened()) {
sf::Event event;
while (gameWindow.GetEvent(event)) {
if (event.Type == sf::Event::Closed)
gameWindow.Close();
}
}
return EXIT_SUCCESS;
}
I replaced while(1)
by while (gameWindow.IsOpened())
and added support of close button. This allows to remove the windows header that is not relevant here.
You should try to compile and execute this in debug mode. It will probably help you understand the problem.
Also, when your code doesn't work. I'll suggest to comment everything that is not relevant (in this example : GameStart::GameStart();
, Clock timer;
, ...) and see if it works.
Upvotes: 0
Reputation: 2613
Code::Blocks 12.11 ships with MinGW GCC 4.7.1 TDM compiler, which is not compatible with the binaries provided on the official download page, so unless you've recompiled SFML 1.6 with the new compiler, things won't work out.
Besides that you should read this section of the SFML FAQ.
Upvotes: 1