【问题标题】:Visual C++ project is crashing unexpectedly while loading a texture with SFMLVisual C++ 项目在使用 SFML 加载纹理时意外崩溃
【发布时间】:2016-09-07 00:12:36
【问题描述】:

我正在尝试使用 SFML 在 Visual Studio 中使用 C++ 开发 2D 游戏。我遵循了 SFML 网站上的所有设置说明,并能够通过他们的说明在窗口中绘制一个绿色圆圈。但是当尝试从文件中加载纹理/图像时,程序会崩溃,我不确定。

C++ Main.cpp

#include <SFML/Graphics.hpp>
#include "MainGameWindow.h"
#include "Logger.h"
using namespace std;
int main()
{
    //auto window = MainGameWindow::GetMGWInstance();
    sf::RenderWindow window(sf::VideoMode(720, 480), "TeleMuncher");
    // Load a sprite to display
    sf::Texture texture;
        if (!texture.loadFromFile("/Assets/Menus/oldTvMenu.png"))
            Logger::Log(Logger::Message_Status::ERROR, "Texture load failed");
    texture.setSmooth(true);
    sf::Sprite sprite(texture);
    while (window.isOpen())
    {
        //Process Events
        //This is where screen updates will most likely happen
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        window.clear();
        window.draw(sprite);
        window.display();
    }
    return 0;
}

错误输出

'TeleMuncher.exe' (Win32): Loaded 'C:\Users\yorel\Documents\Apocalypto\src\TeleMuncher\Debug\TeleMuncher.exe'. Symbols loaded.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Program Files (x86)\Norton Security with Backup\NortonData\22.7.1.32\Definitions\BASHDefs\20160826.008\UMEngx86.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Users\yorel\Documents\Apocalypto\src\TeleMuncher\TeleMuncher\sfml-graphics-2.dll'. Module was built without symbols.
'TeleMuncher.exe' (Win32): Loaded 'C:\Users\yorel\Documents\Apocalypto\src\TeleMuncher\TeleMuncher\sfml-window-2.dll'. Module was built without symbols.
'TeleMuncher.exe' (Win32): Loaded 'C:\Users\yorel\Documents\Apocalypto\src\TeleMuncher\TeleMuncher\sfml-system-2.dll'. Module was built without symbols.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\opengl32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ucrtbase.dll'
'TeleMuncher.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\ucrtbase.dll'
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\glu32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ddraw.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\winmmbase.dll'
'TeleMuncher.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\winmmbase.dll'
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dciman32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nvinit.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ig75icd32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\igdusc32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\windows.storage.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\powrprof.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmapi.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wtsapi32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\version.dll'
'TeleMuncher.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\nvinit.dll'
The thread 0x34ec has exited with code 0 (0x0).
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\version.dll'
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\version.dll'
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dinput.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\hid.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\setupapi.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devobj.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wintrust.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msasn1.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt32.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Cannot find or open the PDB file.
'TeleMuncher.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\version.dll'
Exception thrown at 0x6B6CD42D (vcruntime140.dll) in TeleMuncher.exe: 0xC0000005: Access violation reading location 0x08C37000.

Unhandled exception at 0x6B6CD42D (vcruntime140.dll) in TeleMuncher.exe: 0xC0000005: Access violation reading location 0x08C37000.

The program '[10816] TeleMuncher.exe' has exited with code 0 (0x0).

我将 SFML lib 中的所有 DLL 添加到我的项目文件夹中。这里还有一段视频,讲述了发生的事情。 https://drive.google.com/file/d/0B5fE3M5zscRCdmQ3eWRwcGMxVFE/view?usp=sharing

【问题讨论】:

  • 在调试器中运行它,看看它在哪里崩溃。

标签: c++ visual-studio sfml


【解决方案1】:

最好检查一下纹理加载是否有效,但即使失败了你仍然可以使用它:

sf::Texture texture;
    if (!texture.loadFromFile("/Assets/Menus/oldTvMenu.png"))
        Logger::Log(Logger::Message_Status::ERROR, "Texture load failed");
texture.setSmooth(true);

即使 loadFromFile() 返回空指针,也会调用 setSmooth
所以你得到这个错误:

Exception thrown at 0x6B6CD42D (vcruntime140.dll) in TeleMuncher.exe: 0xC0000005: Access violation reading location 0x08C37000.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 2012-02-29
    • 2021-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多