glTexImage2D与宽度/高度相关的Segfault [英] glTexImage2D Segfault related to width/height

查看:1199
本文介绍了glTexImage2D与宽度/高度相关的Segfault的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试加载771x768图像时,我遇到了段错误。

I got a segfault when I tried to load a 771x768 image.

尝试使用24x24和768x768图像并且它们有效,没问题。

Tried with a 24x24 and 768x768 image and they worked, no problem.

这是预期的吗?为什么它不会因GL错误而优雅地失败?

Is this expected? Why wouldn't it just fail gracefully with a GL Error?

分段错误发生在glTexImage2D调用中。我正在加载PPM二进制文件,因此每像素打包24位。这个奇数与奇数维相结合可能会产生一个非4字节(甚至2字节)的对齐结构(并且在我足够分配的缓冲区之外引用可能是错误的原因但是gdb没有向我显示内存地址(我可以用它来查明是否是导致它的原因)。)

The segmentation fault occurs in the glTexImage2D call. I am loading a PPM binary file so it is packed 24 bits per pixel. This odd number combined with an odd dimension probably produces a not-4-byte (or even 2-byte) aligned structure (and referencing outside of my exactly enough allocated buffer may be the cause of the error but gdb does not show me a memory address (which I could use to find out if this is what causes it)).

glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, dataptr);
// in this specific case of failure, width = 771, height = 768,
// dataptr contains 1776384 bytes of binary RGB image data (771*768*3 = 1776384)


推荐答案


此奇数可能与奇数维相结合产生一个非4字节(甚至2字节)的对齐结构(并且在我足够分配的缓冲区之外引用可能是错误的原因

This odd number combined with an odd dimension probably produces a not-4-byte (or even 2-byte) aligned structure (and referencing outside of my exactly enough allocated buffer may be the cause of the error

这可能是原因。幸运的是你可以设置对齐OpenGL使用读取像素数据。在调用 glTexImage之前...(...)

This is likely the cause. Luckily you can set the alignment OpenGL uses reading pixel data. Right before calling glTexImage…(…) do

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);

这篇关于glTexImage2D与宽度/高度相关的Segfault的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆