Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 让SDL_ttf与SDL2配合良好_C++_Sdl_Sdl Ttf - Fatal编程技术网

C++ 让SDL_ttf与SDL2配合良好

C++ 让SDL_ttf与SDL2配合良好,c++,sdl,sdl-ttf,C++,Sdl,Sdl Ttf,我最近已经开始从使用SDL(1.2.15)迁移到SDL2(2.0.0),并且以前依赖于使用扩展库SDL_ttf(2.0.11)来呈现字体。当我尝试使用与版本1 SDL和SDL2(承认尚未正式发布)相同的文本库时,它编译得很好。但是,当我运行可执行文件时(目前我正在使用VS2012 for Desktop),我得到以下错误: Unhandled exception at 0x6C7D8C24 (SDL2.dll) in test.exe: 0xC0000005: Access violation

我最近已经开始从使用SDL(1.2.15)迁移到SDL2(2.0.0),并且以前依赖于使用扩展库SDL_ttf(2.0.11)来呈现字体。当我尝试使用与版本1 SDL和SDL2(承认尚未正式发布)相同的文本库时,它编译得很好。但是,当我运行可执行文件时(目前我正在使用VS2012 for Desktop),我得到以下错误:

Unhandled exception at 0x6C7D8C24 (SDL2.dll) in test.exe: 0xC0000005: Access violation reading location 0x00000045.
据我所知,这是由于以下代码位造成的。我创建了一个Window类来封装一些常用的SDL函数:

window.cpp:

SDL_Texture* Window::RenderText(const std::string &message, const std::string &fontFile, SDL_Color color, int fontSize){
//Open the font
TTF_Font *font = nullptr;
font = TTF_OpenFont(fontFile.c_str(), fontSize);
if (font == nullptr)
    throw std::runtime_error("Failed to load font: " + fontFile + TTF_GetError());

//Render the message to an SDL_Surface, as that's what TTF_RenderText_X returns
SDL_Surface *surf = TTF_RenderText_Blended(font, message.c_str(), color);
SDL_Texture *texture = SDL_CreateTextureFromSurface(mRenderer.get(), surf);
//Clean up unneeded stuff
SDL_FreeSurface(surf);
TTF_CloseFont(font);

return texture;
}
它被风绊倒了

SDL_Texture *texture = SDL_CreateTextureFromSurface(mRenderer.get(), surf);
线,其中创建的SDL_曲面与SDL2的曲面定义不兼容,因此当它尝试将SDL_曲面转换为SDL_纹理时,它会翻转


我不认为我是唯一一个遇到这个问题的人,那么是否有一个SDL_ttf的解决方案/更新版本可以解决这个问题,或者我应该推迟到SDL2,直到我可以使用字体为止?

您是否查看了SDL_ttf的版本?它似乎已经为SDL2更新了,同步最新的代码并构建它绝对值得。

这就成功了!重建图书馆总是有点痛苦,但它现在起作用了。