- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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/
I have the following piece of code where among with lot of other stuff (which i didn't include in th
我是一名优秀的程序员,十分优秀!