gpt4 book ai didi

c++ - SDL_ConvertSurface() 导致中断

转载 作者:行者123 更新时间:2023-11-28 06:33:44 24 4
gpt4 key购买 nike

I have the following piece of code where among with lot of other stuff (which i didn't include in this topic), i'm trying to start up sdl, create a render and load some sprites.

Everything compiles just fine but when i run my application a break is caused saying: Unhandled exception at 0x681252D5 (SDL.dll) in Carribean World SDL.exe: 0xC0000005: Access violation reading location 0x16161804

The break occurs and the point where i use the SDL_ConvertSurface() function

Can anyone help me out, i can't see what's wrong

声明:

SDL_Texture* background = NULL;
SDL_Surface* tmp = NULL;
SDL_Surface* surface = NULL;

SDL_Window *window = SDL_CreateWindow("Carribean World",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
1360, 768,
SDL_WINDOW_RESIZABLE);

SDL_Surface* screen = SDL_GetWindowSurface(window);

SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);

SDL_PixelFormat* fmt = screen->format;

主要内容:初始化所有SDL子系统

if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return 0;
}

将图像加载到表面

if ((tmp = IMG_Load("images/water.jpg")) == NULL)
{
cout << "SDL_SetVideoMode() Failed: " << SDL_GetError() << endl;
return 0;
}

此处中断

if ((surface = SDL_ConvertSurface(tmp, fmt, 0)) == NULL)
{
cout << "SDL_ConvertSurface() Failed: " << SDL_GetError() << endl;
}
background = SDL_CreateTextureFromSurface(renderer, tmp);

最佳答案

您还没有检查 SDL_GetWindowSurface 的返回值。但无论如何,此 function 的 SDL 文档说“您不能在此窗口上将其与 3D 或渲染 API 结合使用。”。因此,您要么专门使用 SDL_Renderer API,要么使用 SDL_BlitSurface 等,然后调用 SDL_UpdateWindowSurface,但您不能同时使用两者。

关于c++ - SDL_ConvertSurface() 导致中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27116824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com