使用Steamworks和SFML在程序退出时发生访问冲突

时间:2018-09-27 16:19:23

标签: c++ sfml steamworks-api

当同时使用Steamworks和SFML时,程序退出时会引发异常: Exception thrown at 0x00007FFA919D024E (ntdll.dll) in Project1.exe: 0xC0000005: Access violation reading location 0x0000000000000010.

我已将程序还原为最基本的内容,但仍然遇到问题:

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

这是调用堆栈: call stack

1 个答案:

答案 0 :(得分:0)

因此,事实证明,该解决方案就像创建窗口之后将Steamworks API初始化移至一样简单。

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