[英]Visual C++ project is crashing unexpectedly while loading a texture with SFML
I am trying to use SFML to develop a 2D game with C++ in visual studio. 我正在尝试使用SFML在Visual Studio中使用C ++开发2D游戏。 I followed all the setup instructions on SFML's site and was able to draw a green circle in a window via their instructions.
我按照SFML网站上的所有设置说明进行操作,并能够通过其说明在窗口中绘制绿色圆圈。 But when trying to load a texture/image from a file the program crashes and i'm not sure while.
但是,当尝试从文件中加载纹理/图像时,程序崩溃了,我不确定。
C++ Main.cpp 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;
}
Error Output 错误输出
'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).
I added all of DLL's in SFML lib to my project folder. 我将SFML lib中的所有DLL添加到了我的项目文件夹中。 Heres a video of what happened as well.
这是发生了什么的视频。 https://drive.google.com/file/d/0B5fE3M5zscRCdmQ3eWRwcGMxVFE/view?usp=sharing
https://drive.google.com/file/d/0B5fE3M5zscRCdmQ3eWRwcGMxVFE/view?usp=sharing
It's good to check if the the texture loading worked, but you still use it even if it failed: 最好检查纹理加载是否起作用,但是即使加载失败也可以使用它:
sf::Texture texture;
if (!texture.loadFromFile("/Assets/Menus/oldTvMenu.png"))
Logger::Log(Logger::Message_Status::ERROR, "Texture load failed");
texture.setSmooth(true);
setSmooth is called even if the loadFromFile() returns a null pointer 即使loadFromFile()返回空指针,也会调用setSmooth
so you get this error: 所以你得到这个错误:
Exception thrown at 0x6B6CD42D (vcruntime140.dll) in TeleMuncher.exe: 0xC0000005: Access violation reading location 0x08C37000.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.