第二次呼叫SDL_BlitSurface时出现故障
Seg Fault when calling SDL_BlitSurface a second time
我正在使用SDL和SDL_Image来加载图像以用作opengl的纹理。
我正在尝试加载一个精灵表,其中多个图像排列在水平行中(在同一图像中(
void load_spritesheet(std::string key, const char *file_name, int width, int height, int nframes) {
GLuint *texture = new GLuint[nframes];
auto src = IMG_Load(file_name);
auto dstrect = new SDL_Rect{0, 0, width, height};
for(int i = 0; i < nframes; i++) {
auto dst = SDL_CreateRGBSurface(0, width, height, 1, src->format->Rmask, src->format->Gmask, src->format->Bmask, src->format->Amask);
auto rect = new SDL_Rect { i*width, 0, width, height };
SDL_BlitSurface(src, rect, dst, dstrect);
load_gltex(dst, &texture[i]);
SDL_FreeSurface(dst);
}
SPRITESHEET_CACHE[key] = texture;
SDL_FreeSurface(src);
}
我逐步完成了代码,在循环的第一次迭代中,它工作正常。在第二次迭代中,我在调用 SDL_BlitSurface
时遇到 seg 错误,传入的指针都不是 NULL,也没有一个表面被锁定或类似的东西。我确定我的矩形在每个表面的范围内。
以下是 gdb 在段错误之前的一些值:
print i
1
print *src
{flags = 0, format = 0x847100, w = 416, h = 32, pitch = 1664, pixels = 0x87c5f0, userdata = 0x0, locked = 0, lock_data = 0x0, clip_rect = {x = 0, y = 0, w = 416, h = 32}, map = 0x8537b0, refcount = 1}
print *dst
{flags = 0, format = 0x855ec0, w = 32, h = 32, pitch = 4, pixels = 0x84d1f0, userdata = 0x0, locked = 0, lock_data = 0x0, clip_rect = {x = 0, y = 0, w = 32, h = 32}, map = 0x6bdfc0, refcount = 1}
print *rect
{x = 32, y = 0, w = 32, h = 32}
print *dstrect
{x = 0, y = 0, w = 32, h = 32}
在同一表面上两次调用SDL_BlitSurface
或类似的东西是不安全的吗?谢谢。
啊,错误是由于不正确地设置了调用的深度而导致的SDL_CreateRGBSurface
当我真的应该传递正确的值时,我正在传递1
(在这种情况下32
(
一旦我纠正说段错误消失了。
https://wiki.libsdl.org/SDL_CreateRGBSurface#Remarks
相关文章:
- 分段故障(堆芯转储)矢量
- C++中的动态铸造故障
- 数组的指针从不分段故障
- vscode g++链路故障:体系结构x86_64的未定义符号
- 访问被拒绝后,c++中的故障保护代码
- Windows 10-使用gtkmm-3.0库和g++[包括再现]的分段故障
- 调试 CUDA MMU 故障
- Geeksforgeeks C 程序故障排除:IEE 754 表示法为十进制
- Arch Linux.AUR 包 mysql 不能用 makepkg 构建.错误:构建 () 中出现故障
- 正在处理故障(堆芯转储)
- 在 Boost::fiber 中引发的BOOST_ASSERT故障 Visual Studio "Debug" 构建
- 如何进行故障排除:未定义对"非虚拟 thunk to ..."的引用
- C++函数过载会导致 SEG 故障
- 分段故障 运行C++代码时出现 SIGSEGV
- 当新的故障时,是否有必要留出一些紧急内存?
- Python & C-C++ 扩展模块案例段故障
- 带升压的 SEG 故障::make_shared / 特征3 内存.h.
- 在 c++ 中,发生故障后是否需要 stream.clear()?
- 分段故障背包问题
- 分段故障 11,从类函数显示动态 C 字符串