4

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

Julxzs
  • 737
  • 1
  • 7
  • 21
  • Looks like a null pointer dereference. Not sure why. – drescherjm Sep 27 '18 at 16:24
  • 1
    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 Sep 27 '18 at 19:55
  • Thanks for the suggestion, but unfortunately that didn't work. – Julxzs Sep 27 '18 at 20:21

1 Answers1

2

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;
}
Julxzs
  • 737
  • 1
  • 7
  • 21