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

C++ 使用Steamworks和SFML退出程序时发生访问冲突,c++,sfml,steamworks-api,C++,Sfml,Steamworks Api,当同时使用Steamworks和SFML时,程序退出时,我会引发一个异常: 在Project1.exe中的0x00007FFA919D024E(ntdll.dll)处引发异常:0xC0000005:访问冲突读取位置0x0000000000000010。 我已将程序缩减到最基本的部分,但仍然存在问题: #include <SFML/Graphics.hpp> #include <steam/steam_api.h> int main() { SteamAPI_In

当同时使用Steamworks和SFML时,程序退出时,我会引发一个异常:
在Project1.exe中的0x00007FFA919D024E(ntdll.dll)处引发异常:0xC0000005:访问冲突读取位置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;
}
#包括
#包括
int main()
{
SteamAPI_Init();
sf::RenderWindow窗口(sf::VideoMode::getDesktopMode(),“标题”,sf::Style::Close);
while(window.isOpen())
{
sf::事件e;
while(window.pollEvent(e))
{
开关(e型)
{
案例sf::事件::已结束:
{
window.close();
打破
}
}
}
}
蒸汽API_关闭();
返回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;
}
#包括
#包括
int main()
{
sf::RenderWindow窗口(sf::VideoMode::getDesktopMode(),“标题”,sf::Style::Close);
SteamAPI_Init();
while(window.isOpen())
{
sf::事件e;
while(window.pollEvent(e))
{
开关(e型)
{
案例sf::事件::已结束:
{
window.close();
打破
}
}
}
}
蒸汽API_关闭();
返回0;
}

看起来像一个空指针解引用。不知道为什么。我发现在调用SteamAPI_Shutdown()时,sf::RenderWindow对象变量“window”仍在作用域中。换句话说,您已经交错初始化/取消初始化:1。初始蒸汽,2。初始化窗口,3。关闭蒸汽,4。关上窗户。我认为3号和4号应该互换。这只是一个粗略的猜测,但是您是否尝试过通过在窗口变量和while循环周围放置大括号来将其放在不同的范围内,从而将steam(de)初始化保持在外部?谢谢您的建议,但不幸的是,这没有起作用。