I've been banging my head off a wall for two days now with this.
Game.h
#pragma once
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"
class Game
{
public:
static void Start();
static sf::RenderWindow& GetWindow();
const static sf::Event& GetInput();
const static int vWidth = 800;
const static int vHeight = 600;
private:
static bool IsExiting();
static void GameLoop();
enum GameState { Uninitialized, Playing, Exiting };
static GameState _gameState;
static sf::RenderWindow _window;
};
Game.cpp
#include "stdafx.h"
#include "game.h"
void Game::Start(void)
{
if(_gameState != Uninitialized )
return;
_window.create( sf::VideoMode( vWidth, vHeight, 32), "flaccy" );
_gameState = Game::Playing;
while( !IsExiting() )
{
GameLoop();
}
_window.close();
}
bool Game::IsExiting()
{
if( _gameState == Game::Exiting )
return true;
else
return false;
}
sf::RenderWindow& Game::GetWindow()
{
return _window;
}
const sf::Event& Game::GetInput()
{
sf::Event currentEvent;
_window.pollEvent( currentEvent );
return currentEvent;
}
void Game::GameLoop()
{
sf::Event currentEvent;
_window.pollEvent( currentEvent );
switch( _gameState )
{
case Game::Playing:
{
_window.clear( sf::Color( 0, 0, 0 ) );
_window.display();
if( currentEvent.type == sf::Event::Closed )
{
_gameState = Game::Exiting;
}
}
break;
}
}
Game::GameState Game::_gameState = Uninitialized;
sf::RenderWindow Game::_window;
When I run this I get the error...
Unhandled exception at 0x76f015de in flaccy second.exe: 0xC0000005: Access violation writing location 0x00000004.
Debugger shows this
> flaccy second.exe!`dynamic initializer for 'Game::_window''() Line 65 + 0x28 bytes C++
and its stopped on sf::renderwindow in the game.cpp file.
Sorry if this is stupid but I couldn't seem to find an answer anywhere.
Visual Studio 2012, SFML 2.0