4

一起使用 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;
}

这是调用堆栈: 调用栈

4

1 回答 1

2

所以事实证明,解决方案就像在创建窗口之后将 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;
}
于 2018-10-01T18:26:45.510 回答