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

Author Topic: Help, new to SFML, compile errors in simple project  (Read 2591 times)

0 Members and 1 Guest are viewing this topic.

LonGShoT

  • Newbie
  • *
  • Posts: 4
    • View Profile
Help, new to SFML, compile errors in simple project
« on: March 05, 2015, 10:56:31 am »
Hi everybody,
This is driving me up the wall, I cannot get this thing to run and I've tried everything, I'm trying to follow the book example from http://www.amazon.com/SFML-Game-Development-Jan-Haller/dp/1849696845 Chapter 1 and I'm getting an error at compile

**EDIT**
If I remove the call to loadFromFile it seems fine, although it does nothing....
**ENDEDIT**

**EDIT**
Oh and I'm using VS2013 community ed, but I've also tried this on VC++E2010 too and I get the same issue
**ENDEDIT**

Error:
First-chance exception at 0x6D96F20C (msvcr120.dll) in SFML-tuts.exe: 0xC0000005: Access violation reading location 0x00ACF000.

Stack:
6D96F20C  rep movs    byte ptr es:[edi],byte ptr [esi]

All the code:

Game.h:
#include <SFML/Graphics.hpp>
#include <SFML/Window/Event.hpp>

class Game
{
public:
        Game();
        void run();
private:
        void handlePlayerInput(sf::Keyboard::Key key, bool isPressed);
        void processEvents();
        void update();
        void update(sf::Time deltaTime);
        void render();
        bool mIsMovingUp;
        bool mIsMovingDown;
        bool mIsMovingLeft;
        bool mIsMovingRight;
        static const float              PlayerSpeed;
        sf::RenderWindow mWindow;
        sf::Texture mTexture;
        sf::Sprite mPlayer;

};
int main()
{
        Game game;
        game.run();
}

Game.cpp
#include "Game.h"
#include <iostream>

const float Game::PlayerSpeed = 100.f;

Game::Game()
        : mWindow(sf::VideoMode(640, 480), "SFML Application")
        , mTexture()
        , mPlayer()
{
        if (!mTexture.loadFromFile("/Media/Textures/Eagle.png"))
        {
                std::cout << "Error canny load file";
        }
        mPlayer.setTexture(mTexture);
        mPlayer.setPosition(100.f, 100.f);
}
void Game::run()
{
        sf::Clock clock;
        sf::Time timeSinceLastUpdate = sf::Time::Zero;
        sf::Time TimePerFrame = sf::seconds(1.f / 60.f);
        while (mWindow.isOpen())
        {
                processEvents();
                timeSinceLastUpdate += clock.restart();
                while (timeSinceLastUpdate > TimePerFrame)
                {
                        timeSinceLastUpdate -= TimePerFrame;
                        processEvents();
                        update(TimePerFrame);
                }
                render();
        }
}
void Game::handlePlayerInput(sf::Keyboard::Key key, bool isPressed)
{
        if (key == sf::Keyboard::W)
                mIsMovingUp = isPressed;
        else if (key == sf::Keyboard::S)
                mIsMovingDown = isPressed;
        else if (key == sf::Keyboard::A)
                mIsMovingLeft = isPressed;
        else if (key == sf::Keyboard::D)
                mIsMovingRight = isPressed;
}
void Game::processEvents()
{
        sf::Event event;
        while (mWindow.pollEvent(event))
        {
                switch (event.type)
                {
                case sf::Event::KeyPressed:
                        handlePlayerInput(event.key.code, true);
                        break;
                case sf::Event::KeyReleased:
                        handlePlayerInput(event.key.code, false);
                        break;
                case sf::Event::Closed:
                        mWindow.close();
                        break;
                }
        }
}
void Game::update(sf::Time deltaTime)
{
        sf::Vector2f movement(0.f, 0.f);
        if (mIsMovingUp)
                movement.y -= PlayerSpeed;
        if (mIsMovingDown)
                movement.y += PlayerSpeed;
        if (mIsMovingLeft)
                movement.x -= PlayerSpeed;
        if (mIsMovingRight)
                movement.x += PlayerSpeed;
        mPlayer.move(movement * deltaTime.asSeconds());
}
void Game::render()
{
        mWindow.clear();
        mWindow.draw(mPlayer);
        mWindow.display();
}
« Last Edit: March 05, 2015, 11:43:09 am by LonGShoT »

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: Help, new to SFML, compile errors in simple project
« Reply #1 on: March 05, 2015, 04:40:42 pm »
Sounds like either a memory management error or trying to use a list of some kind and going out of range on it but I can't see where it is. ???
I have many ideas but need the help of others to find way to make use of them.

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Help, new to SFML, compile errors in simple project
« Reply #2 on: March 05, 2015, 05:40:48 pm »
Quote
I'm getting an error at compile
Quote
First-chance exception at 0x6D96F20C (msvcr120.dll) in SFML-tuts.exe: 0xC0000005: Access violation reading location 0x00ACF000.
This doesn't look like a compile error. This looks like a run-time error. Is that what you meant?

Quote
If I remove the call to loadFromFile it seems fine, although it does nothing....

When you have loadFromFile in there is it actually succeeding? If loadFromFile fails (for example, it can't find your picture) all you're doing is printing a message and then continuing on. Is your error message being printed to the console?

LonGShoT

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Help, new to SFML, compile errors in simple project
« Reply #3 on: March 05, 2015, 07:59:58 pm »
@StormWingDelta - thats all the code there is....if you cant see it, it doesnt exist.

@Arcade - Nope nothing prints to the console, if the picture exists or not it fails, the command prompt just shows a load of scrambled chars before it bombs out...I also agree its likely a runtime error in the C++ redist but I've removed it and reinstalled with no luck, tried official and nightly builds of SFML and I've tried both VS2013CE and VC++2010

The only thing I havent done is try another computer which I'll do in a few minutes

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Help, new to SFML, compile errors in simple project
« Reply #4 on: March 05, 2015, 08:30:10 pm »
When I said runtime error, I meant an error that occurs when your program is running (not compiling). I wasn't suggesting the error is in the C++ redist package.

Quote
the command prompt just shows a load of scrambled chars before it bombs out
This is likely related to the problem. Perhaps it is trying to print a string that isn't NUL terminated or one that was never initialized.

if (!mTexture.loadFromFile("/Media/Textures/Eagle.png"))
 
I'm not very familiar with how Windows handles things, but should you have that first forward slash in front of Media?

I don't have much time to look into this more right now, but I may look at your code more later.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Help, new to SFML, compile errors in simple project
« Reply #5 on: March 05, 2015, 08:37:06 pm »
Quote
the command prompt just shows a load of scrambled chars

If I were a betting man.... you mixed up debug and release libs.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

LonGShoT

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Help, new to SFML, compile errors in simple project
« Reply #6 on: March 05, 2015, 08:44:45 pm »
@Arcade - it shouldn't overly matter but I've tried either way

@zsbzsb - I suppose its possible, I can take a look

LonGShoT

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Help, new to SFML, compile errors in simple project
« Reply #7 on: March 05, 2015, 08:57:55 pm »
Quote
the command prompt just shows a load of scrambled chars

If I were a betting man.... you mixed up debug and release libs.

WE HAVE A WINNER!!!!!  ;D ;D ;D ;D ;D

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Help, new to SFML, compile errors in simple project
« Reply #8 on: March 05, 2015, 08:59:48 pm »
For future reference you can edit posts.  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor