使用SFML加载纹理时,Visual C ++项目意外崩溃

时间:2016-09-07 00:12:37

标签: c++ visual-studio sfml

我正在尝试使用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

1 个答案:

答案 0 :(得分:0)

最好检查纹理加载是否有效,但即使失败也仍然使用它:

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.