2013-07-09 59 views
4

我最近開始從使用SDL(1.2.15)遷移到SDL2(2.0.0),並且之前依賴於使用擴展庫SDL_ttf(2.0.11)來呈現字體。當我嘗試使用與使用SDL2的第一版SDL(確實尚未正式發佈)一起使用的相同文本庫時,它編譯得很好。當我運行可執行文件,但(我使用VS2012桌面的那一刻),我收到以下錯誤:獲得SDL_ttf與SDL2的良好配合

Unhandled exception at 0x6C7D8C24 (SDL2.dll) in test.exe: 0xC0000005: Access violation reading location 0x00000045. 

據我所知,這是由於下面的代碼位。我創建了一個窗口類來封裝一些常用的功能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_Surface格格不入絆倒SDL2對曲面的定義,所以當它試圖將SDL_Surface轉換成SDL_Texture時,它會被翻轉出來。

我不認爲我是唯一遇到此問題的人,因此是否有解決此問題的SDL_ttf的解決方法/更新版本,或者是否應該轉移到SDL2,直到可以獲取字體加工?

回答

3

您是否檢查了SDL_TTF的Mercurial Repository?它似乎已經更新爲SDL2,它肯定會值得它同步最新的代碼並構建它。

+0

這個伎倆!重建圖書館總是有點痛苦,但它現在像一種魅力。 –

相關問題