SDL_TTF和SDL 2不在一起工作.给出未处理的异常
SDL_TTF and SDL 2 not working together. Giving Unhandled Exception
所以我试图在SDL2中制作一个文本渲染器。当我在游戏的每一帧更新文本时,最终它会给我这个错误:
Unhandled exception at 0x6C7B543D (SDL2.dll) in Games.exe: 0xC0000005: Access violation reading location 0x00000004.
这很奇怪,因为它不会立即给我异常,只是在一段时间后(这个时间似乎有所不同,我认为SDL_Mixer导致了它)当我"打破"异常时,我似乎这是导致错误的行(当我从表面创建纹理时):
void Text::SetText(SDL_Renderer* rend, std::string message)
{
SDL_Color textCol = { Col.Red, Col.Green, Col.Blue, Col.Alpha };
//Load image at specified path
SDL_Surface* loadedSurface = TTF_RenderText_Solid(font, message.c_str(), textCol);
if (loadedSurface == NULL) Debug::Fatal("Could not load text");
//Create texture from surface pixels
/*EXCEPTION ON THIS LINE --->*/ SDL_Texture* newTexture = SDL_CreateTextureFromSurface(rend, loadedSurface);
if (newTexture == NULL) Debug::Fatal("Could not create texture from text");
Scale.x = loadedSurface->w;
Scale.y = loadedSurface->h;
//Get rid of old loaded surface
SDL_FreeSurface(loadedSurface);
Texture = newTexture;
}
我使用的是SDL_TTF的32位visual studio版本。
如果你能帮助修复这个错误,我们将不胜感激。非常感谢。
所需的行为是,它可以加载文本,而不会最终给出异常。
其他人也有这个错误,但解决方案没有帮助(因为我在更新的repo上找不到visual studio版本):让SDL_ttf在SDL2 中发挥作用
编辑1:
在更新到SDL_TTF 2的稍新版本后,错误仍未修复,有什么建议吗?
编辑2:
呼叫后:
SDL_GetError()
IMG_GetError()
TTF_GetEror()
这是控制台中的输出:
CreateTexture(): UNKNOWN
CreateTexture(): UNKNOWN
CreateTexture(): UNKNOWN
似乎"TTF_RenderText_Solid"正在返回NULL。顺便说一下,我使用的是SDL_TTF的最新版本。
正如您引用的帖子中所建议的,您应该更新SDL_ttf版本,使其能够与SDL2一起使用。
以下是可用于visual studio的SDL_TTF SDL2版本。http://hg.libsdl.org/SDL_ttf/file/62fc3433538d/VisualC
您将找到允许您构建SDL_ttf库的SDL_ttf.sln;)。
相关文章:
- 在c++中实现LinkedList时,应出现未处理的错误
- 如何修复链表类实现的未处理异常0xDDDDDDDD
- 在信号处理程序中捕获C++未处理的异常并恢复应用程序
- 在C++程序中使用的迭代器中未处理的异常
- 在 ******.exe 中0x00000000772CA267 (ntdll.dll) 处未处理的异常:0xC0000
- 未处理的异常与 cudaMemcpy2D
- 处理未处理的异常更改C++
- for 循环中未处理的异常
- VisualC++ 2010 有没有办法找出有关未处理异常错误的更多详细信息
- 为什么此代码导致未处理的异常失败
- 瓦尔格林德:注意到但未处理的国际奥克特尔;是否有必要处理以及如何找到?
- 在OpenCV_core310.dll中使用findContours函数时,OpenCV引发未处理的异常
- 0x0F50DF58:0xC0000005:访问冲突读取位置0x0047CA04时未处理的异常
- 使用 getline 时未处理的异常
- 错误 : 异常 : 引发未处理的异常: 读取访问冲突.0xDDDDDDDD临时温度
- 核心消息传递中未处理的异常.dll在程序关闭期间
- 在 Hello World.exe 中0x0F828F0E (ucrtbased.dll) 处未处理的异常: 0xC00
- SDL C++字体呈现函数中未处理的异常
- SDL_TTF和SDL 2不在一起工作.给出未处理的异常
- C++ "File" .exe 中 SDL 0x6C7DB2AA (SDL2.dll) 处未处理的异常: 0xC0000005:访问冲突读取位置0x00000044