简体   繁体   English

将SDL_ttf与SDL和SDL2一起使用时发生C ++访问冲突

[英]C++ Access violation when using SDL_ttf with SDL and SDL2

I am using SDL2_ttf with SDL2 (in Visual Studio 2015). 我在SDL2中使用SDL2_ttf(在Visual Studio 2015中)。 When I tried to run the following code, 当我尝试运行以下代码时,

#include "SDL.h"
#include "SDL_ttf.h"

int main(int argc, char* args[]) {
    SDL_Init(SDL_INIT_EVERYTHING);
    TTF_Init();

    SDL_Window* window;
    SDL_Renderer* renderer;
    SDL_CreateWindowAndRenderer(1600, 900, SDL_WINDOW_OPENGL, &window, &renderer);

    TTF_Font* font = TTF_OpenFont("comic.ttf", 12);
    SDL_Color color = { 0, 0, 0, 255 };
    SDL_Surface* textSurface = TTF_RenderText_Solid(font, "asdf", color);
    SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, textSurface);

    TTF_Quit();
    SDL_Quit();
    return 0;
}

I got a "SDL.dll missing" runtime error. 我收到“ SDL.dll丢失”运行时错误。 I put SDL.dll, alongside SDL2.dll, libfreetype-6.dll, SDL_ttf.dll, zlib1.dll and other libraries in my system32 folder, which solved the runtime error, but I instantaneously ran into another error: "Unhandled exception at 0x000000006C812E39 (SDL2.dll) in MCP2016.exe: 0xC0000005: Access violation reading location 0x000000010000006A." 我将SDL.dll以及SDL2.dll,libfreetype-6.dll,SDL_ttf.dll,zlib1.dll和其他库放在我的system32文件夹中,这解决了运行时错误,但是我立即遇到了另一个错误:“在“ MCP2016.exe中的0x000000006C812E39(SDL2.dll):0xC0000005:访问冲突读取位置0x000000010000006A。

When I decided to "Break" in the Visual studio dialog telling me this, it pointed to the line 当我决定在Visual Studio对话框中“中断”告诉我这一点时,它指向该行

SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, textSurface);

I came across an old forum post that suggested that SDL_ttf and SDL2 can cause access violations like this because they are not completely compatible. 我碰到了一个老论坛帖子 ,该帖子建议SDL_ttf和SDL2可能会导致这种访问冲突,因为它们不完全兼容。 I think this has to do something with the problems I have, since it complained about SDL.dll first. 我认为这与我遇到的问题有关,因为它首先抱怨SDL.dll。 It was suggested to recompile the DLL with the SDL2 header files, but I am afraid that is beyond my competence, especially because windows and C++ do not get along very well. 建议使用SDL2头文件重新编译DLL,但我担心这超出了我的能力范围,尤其是因为Windows和C ++相处得不太好。

I have been working on this for about eight hours now and I am running out of ideas to try to solve this. 我已经为此工作了大约八个小时,但我已经没有足够的想法来尝试解决此问题。 Does anyone have any ideas about this? 有人对此有任何想法吗?

SDL and SDL2 are not compatible. SDL和SDL2不兼容。 You either have one, or the other. 您要么拥有一个,要么拥有另一个。

As mentioned in the comments, the fix is to use SDL2_ttf instead. 如评论中所述,解决方法是改用SDL2_ttf。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM