Hi,
I'm new here I've started to learn SFML and now I've encountered a problem that I don't know how to solve?
First-chance exception at 0xeeffee01 in SFML_Test.exe: 0xC0000005: Access violation.
Unhandled exception at 0xeeffee01 in SFML_Test.exe: 0xC0000005: Access violation.
Here is the code of my app:
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
//-------------------------------------------------------------------------------------------------------------------
#pragma comment(lib,"sfml-system-s.lib")
#pragma comment(lib,"sfml-window-s.lib")
#pragma comment(lib,"sfml-graphics-s.lib")
//-------------------------------------------------------------------------------------------------------------------
using namespace std;
//-------------------------------------------------------------------------------------------------------------------
sf::RenderWindow App;
sf::Event Event;
sf::Clock Clock;
//-------------------------------------------------------------------------------------------------------------------
const float Speed = 50.f;
//-------------------------------------------------------------------------------------------------------------------
float x = 0.f;
float y = 0.f;
float rot = 0.f;
float zaFPS = 0.f;
float FPS = 0.f;
//-------------------------------------------------------------------------------------------------------------------
void f_Clock();
void f_Render();
void f_DrawAll();
void f_HandleEvents();
void f_Init();
//-------------------------------------------------------------------------------------------------------------------
void f_Clock()
{
zaFPS = Clock.GetElapsedTime();
FPS = 1.f / Clock.GetElapsedTime();
Clock.Reset();
}
//-------------------------------------------------------------------------------------------------------------------
void f_Render()
{
App.Display();
}
//-------------------------------------------------------------------------------------------------------------------
void f_DrawAll()
{
App.Clear(sf::Color(200, 0, 0));
}
//-------------------------------------------------------------------------------------------------------------------
void f_HandleEvents()
{
while(App.GetEvent(Event))
{
// Window closed
if (Event.Type == sf::Event::Closed)
App.Close();
// Escape key pressed
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
if( App.GetInput().IsKeyDown(sf::Key::Left) ) x -= Speed * zaFPS; // LEVO
if( App.GetInput().IsKeyDown(sf::Key::Right) ) x += Speed * zaFPS; // DESNO
if( App.GetInput().IsKeyDown(sf::Key::Up) ) y += Speed * zaFPS; // GORE
if( App.GetInput().IsKeyDown(sf::Key::Down) ) y -= Speed * zaFPS; // DOLE
}
//-------------------------------------------------------------------------------------------------------------------
void f_Init()
{
App.Create(sf::VideoMode(800, 600, 32), "SFML Window");
App.SetFramerateLimit(60);
}
//-------------------------------------------------------------------------------------------------------------------
int main()
{
f_Init();
while(App.IsOpened())
{
f_Clock();
f_HandleEvents();
cout << "X: " << x << " Y: " << y << " FPS: " << FPS << endl;
f_DrawAll();
f_Render();
}
return 0;
}
//-------------------------------------------------------------------------------------------------------------------
I get the problem above when my app reaches the f_DrawAll() and tries to execute App.Clear(sf::Color(200, 0, 0)); .
So any idea how to fix this problem?
Best Regards!