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

Author Topic: xmemory0 Exception thrown: read access violation, when closing SFML application  (Read 1227 times)

0 Members and 1 Guest are viewing this topic.

egordiac

  • Newbie
  • *
  • Posts: 1
    • View Profile
I am making a small game, for now I just want to draw a sprite on the screen. I've used SFML before and have never gotten this exception. It only happens, when I close the window.

Here's my code:
main.cpp
#include <iostream>
#include "Game.hpp"

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

        return 0;
}

Game.hpp
#pragma once
#include <SFML/Graphics.hpp>

class Game
{
public:
        Game();
        void run();

private:
        void processEvents();
        void update();
        void render();

        sf::RenderWindow window;
        sf::Texture texture;
        sf::Sprite player;
};

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

Game::Game()
:window(sf::VideoMode(816, 624), "SFML Application")
{
        if (!texture.loadFromFile("rainer.png")) {
                std::cout << "Failed to load texture" << std::endl;
        }

        player.setTexture(texture);
}

void Game::run()
{
        while (window.isOpen())
        {
                processEvents();
                update();
                render();
        }
}

void Game::processEvents()
{
        sf::Event event;
        while (window.pollEvent(event))
        {
                if (event.type == sf::Event::Closed)
                        window.close();
        }
}

void Game::update()
{
}

void Game::render()
{
        window.clear();

        // does it always need to draw something??
        window.draw(player);

        window.display();
}

Fx8qkaoy

  • Newbie
  • *
  • Posts: 42
    • View Profile
I'm late, but if u still watch this thread, then u should know it is not easy to indetify the problem without enough details. Where exactly it throws? The line. Does the player appears on the screen?
« Last Edit: February 06, 2020, 01:11:36 pm by eXpl0it3r »