Access violation on program exit with Steamworks and SFML

3

I get an exception thrown when the program exits when using Steamworks and SFML together: Exception thrown at 0x00007FFA919D024E (ntdll.dll) in Project1.exe: 0xC0000005: Access violation reading location 0x0000000000000010.

I've cut back the program to its very basics while still getting the problem:

#include <SFML/Graphics.hpp>
#include <steam/steam_api.h>

int main()
{
    SteamAPI_Init();

    sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "Title", sf::Style::Close);

    while (window.isOpen())
    {
        sf::Event e;
        while (window.pollEvent(e))
        {
            switch (e.type)
            {
                case sf::Event::Closed:
                {
                    window.close();
                    break;
                }
            }
        }
    }

    SteamAPI_Shutdown();

    return 0;
}

Here's the call stack: call stack

c++
sfml
steamworks-api
asked on Stack Overflow Sep 27, 2018 by Julxzs

1 Answer

0

So it turns out the solution was as simple as moving the Steamworks API initialisation to after the creation of the window.

#include <SFML/Graphics.hpp>
#include <steam/steam_api.h>

int main()
{
    sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "Title", sf::Style::Close);

    SteamAPI_Init();

    while (window.isOpen())
    {
        sf::Event e;
        while (window.pollEvent(e))
        {
            switch (e.type)
            {
                case sf::Event::Closed:
                {
                    window.close();
                    break;
                }
            }
        }
    }

    SteamAPI_Shutdown();

    return 0;
}
answered on Stack Overflow Oct 1, 2018 by Julxzs

User contributions licensed under CC BY-SA 3.0