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

Author Topic: Access Violation Problem  (Read 2781 times)

0 Members and 1 Guest are viewing this topic.

Vita

  • Newbie
  • *
  • Posts: 6
    • View Profile
Access Violation Problem
« on: April 16, 2011, 12:16:42 am »
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?

Code: [Select]

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:
Code: [Select]

#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!
SFML is the best! :)

Fred_FS

  • Newbie
  • *
  • Posts: 48
    • View Profile
Access Violation Problem
« Reply #1 on: April 16, 2011, 01:22:19 am »
What SFML version are you using? I don't have any problems with your code ;). I tested it with 1.6.

Vita

  • Newbie
  • *
  • Posts: 6
    • View Profile
Access Violation Problem
« Reply #2 on: April 16, 2011, 01:35:52 am »
I also have SFML 1.6, Using Visual C++ 2008 Express
SFML is the best! :)

Vita

  • Newbie
  • *
  • Posts: 6
    • View Profile
Access Violation Problem
« Reply #3 on: April 16, 2011, 02:08:19 am »
Fixed... :lol: It was set to Debug and when I set it to Release than it worked OK.
SFML is the best! :)

 

anything