4
votes

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

1
Looks like a null pointer dereference. Not sure why. - drescherjm
I see that by the time you call SteamAPI_Shutdown(), the sf::RenderWindow object variable "window" is still in scope. In other words you have interleaved initialization/deinitialization: 1. init steam, 2. init window, 3. close steam, 4. close window. I think 3&4 should be swapped. Just a wild guess, but have you tried putting it in different scope by putting curly braces around the window variable and the while loop, to keep steam (de)initialization outside? - AlenL
Thanks for the suggestion, but unfortunately that didn't work. - Julxzs

1 Answers

2
votes

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;
}