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

Author Topic: Crashes using loadFromFile/saveToFile  (Read 1869 times)

0 Members and 1 Guest are viewing this topic.

Hildar

  • Newbie
  • *
  • Posts: 2
    • View Profile
Crashes using loadFromFile/saveToFile
« on: March 17, 2013, 02:12:34 am »
Using the prebuilt 2.0RC binaries, or building my own ones from the latest source, I get an instant crash (access violation, no exception thrown) on calling Font.loadFromFile(), SoundBuffer.loadFromFile() and Image.saveToFile().

Using VS2012(VC++ 11).

The same crash occurs if I compile the built in pong example or run the prebuilt binary.

Intel sandybridge integrated graphics, and nVidia 630M.

Annoying, because I had it working in 1.6, but couldn't get it to compile for windows, only linux. Getting a working Windows build has turned into hell.

Edit: Commenting out all the offending lines, I also notice that the titlebar is filed with garbage (different every run), sometimes with the correct title after the garbage, sometimes not.

Edit2: Guess the code might be helpful, no?
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <sstream>

using namespace sf;

int main(int, char *[])
{
    float frameTime(0);
    int score1(0), score2(0);

    Vector2f ballSpeed(-400,0);

        RenderWindow window(VideoMode(800,600, 32), "gPong");
    window.setFramerateLimit(60);
    window.clear(Color(0,0,0));

    Image whiteBallImage;
    Image whitePaddleImage;
    Image whiteLineImage;
        whiteBallImage.create(6,6, Color(255, 255, 255));
        whitePaddleImage.create(10,200, Color(255, 255, 255));
        whiteLineImage.create(2,600, Color(255, 255, 255));

        Texture whiteBall;
        Texture whitePaddle;
        Texture whiteLine;
        whiteBall.loadFromImage(whiteBallImage);
        whitePaddle.loadFromImage(whitePaddleImage);
        whiteLine.loadFromImage(whiteLineImage);

    Sprite ball(whiteBall);
        Sprite paddle1(whitePaddle);
    Sprite paddle2(whitePaddle);
    Sprite centerLine(whiteLine);
    ball.setPosition(400,300);
        paddle1.setPosition(20,200);
        paddle2.setPosition(770, 200);
        centerLine.setPosition(399, 0);

    std::ostringstream fpsStream("");
    std::ostringstream scoreStream1("");
    std::ostringstream scoreStream2("");

    Text fpsText(String("fps :0"), Font::getDefaultFont(), 16);
        Text scoreText1(String("0"), Font::getDefaultFont(), 72);
        Text scoreText2(String("0"), Font::getDefaultFont(), 72);
        scoreText1.setPosition(164,0);
        scoreText2.setPosition(564,0);

    SoundBuffer beepBuffer;
//      beepBuffer.loadFromFile("beep.wav");

    Sound beep(beepBuffer);

    Event event;
        Clock clock;

    while (window.isOpen()) {
        frameTime = clock.getElapsedTime().asSeconds();
        clock.restart();
        if (frameTime > 0.15f)
            frameTime = 0.15f;

        fpsStream.str("");
        fpsStream << ceil(1.0f/frameTime);
                fpsText.setString(String(("fps: " + fpsStream.str()).c_str()));

        scoreStream1.str("");
        scoreStream1 << score1;
                scoreText1.setString(String(scoreStream1.str().c_str()));

        scoreStream2.str("");
        scoreStream2 << score2;
        scoreText2.setString(scoreStream2.str().c_str());

        while (window.pollEvent(event)) {
            if (event.type == Event::Closed)
                window.close();
                        if (event.type == Event::KeyPressed && (event.key.code == Keyboard::Escape || event.key.code == Keyboard::Q))
                window.close();
                        if (event.type == Event::KeyPressed && event.key.code == Keyboard::F1) {
                Image screenShot = window.capture();
//                screenShot.saveToFile("screenshot.jpg");
            }
        }

                if (Keyboard::isKeyPressed(Keyboard::W))
            paddle1.move(0, -200 * frameTime);
                if (Keyboard::isKeyPressed(Keyboard::S))
            paddle1.move(0,  200 * frameTime);
        if (paddle1.getPosition().y < 0.0f)
                        paddle1.setPosition(paddle1.getPosition().x, 0.0f);
        if (paddle1.getPosition().y > 400.0f)
            paddle1.setPosition(paddle1.getPosition().x, 400.0f);

                if (Keyboard::isKeyPressed(Keyboard::Up))
            paddle2.move(0, -200 * frameTime);
                if (Keyboard::isKeyPressed(Keyboard::Down))
            paddle2.move(0,  200 * frameTime);
        if (paddle2.getPosition().y < 0.0f)
            paddle2.setPosition(paddle2.getPosition().x, 0.0f);
        if (paddle2.getPosition().y > 400.0f)
            paddle2.setPosition(paddle2.getPosition().x, 400.0f);

        ball.move(ballSpeed * frameTime);

        if (ball.getPosition().x < 30.0f) {
            ballSpeed.x = -ballSpeed.x;
                        ballSpeed.y = ball.getPosition().y - paddle1.getPosition().y - 100.0f;
                        if (ball.getPosition().y < paddle1.getPosition().y || ball.getPosition().y > paddle1.getPosition().y + 200.0f) {
                ball.setPosition(397.0f, 297.0f);
                score2 += 1;
            }else
                beep.play();
        }

        if (ball.getPosition().x > 770.0f) {
            ballSpeed.x = -ballSpeed.x;
                        ballSpeed.y = ball.getPosition().y - paddle2.getPosition().y - 100.0f;
                        if (ball.getPosition().y < paddle2.getPosition().y || ball.getPosition().y > paddle2.getPosition().y + 200.0f) {
                ball.setPosition(397.0f, 297.0f);
                score2 += 1;
            }else
                beep.play();
        }

        if (ball.getPosition().y <= 0.0f || ball.getPosition().y >= 600.0f) {
            beep.play();
            ballSpeed.y = -ballSpeed.y;
        }

        window.clear(Color(0,0,0));
            window.draw(ball);
            window.draw(paddle1);
            window.draw(paddle2);
            window.draw(centerLine);
            window.draw(fpsText);
            window.draw(scoreText1);
            window.draw(scoreText2);
        window.display();
    }

    return EXIT_SUCCESS;
}

 

Yes I know, default font and all that, I changed it just to reduce the number of places it could go wrong, I'll use my own again when it's fixed.
« Last Edit: March 17, 2013, 02:20:56 am by Hildar »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10838
    • View Profile
    • development blog
    • Email
AW: Crashes using loadFromFile/saveToFile
« Reply #1 on: March 17, 2013, 07:19:33 am »
If you look at the download page again you see VS 2010. The prebuilt binaries are not compatible with VS 2012; you'll have to rebuild SFML.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hildar

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: AW: Crashes using loadFromFile/saveToFile
« Reply #2 on: March 17, 2013, 02:55:05 pm »
If you look at the download page again you see VS 2010. The prebuilt binaries are not compatible with VS 2012; you'll have to rebuild SFML.

As I said, this happens just the same if I build my own binaries from the latest source, using VS2012.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10838
    • View Profile
    • development blog
    • Email
Re: AW: Crashes using loadFromFile/saveToFile
« Reply #3 on: March 17, 2013, 03:10:30 pm »
As I said, this happens just the same if I build my own binaries from the latest source, using VS2012.
That was not clear at all. The related sentence makes barely sense. ;D

The same crash occurs if I compile the built in pong example or run the prebuilt binary.

Make sure you're linking correctly against SFML and that you've done everything exactly the way it's described in the official tutorial. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything