glTexImage2D 与宽度/高度相关的段错误
当我尝试加载 771x768 图像时出现段错误。
尝试使用 24x24 和 768x768 图像,它们工作正常,没有问题。
这是预期的吗?为什么它不会因 GL 错误而优雅地失败呢?
分段错误发生在 glTexImage2D 调用中。我正在加载 PPM 二进制文件,因此它每像素打包 24 位。这个奇数与奇数维度相结合可能会产生一个非 4 字节(甚至 2 字节)对齐的结构(并且引用我完全分配的缓冲区之外可能是错误的原因,但 gdb 没有向我显示内存地址(我可以用它来查明这是否是导致它的原因))。
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)
I got a segfault when I tried to load a 771x768 image.
Tried with a 24x24 and 768x768 image and they worked, no problem.
Is this expected? Why wouldn't it just fail gracefully with a GL Error?
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是原因。幸运的是,你可以在调用
glTexImage…(…)
之前设置 OpenGL 使用的对齐方式。This is likely the cause. Luckily you can set the alignment OpenGL uses reading pixel data. Right before calling
glTexImage…(…)
do我在 opengl 论坛中读过此内容:
(来源)
我发现了这个,我相信它澄清了正在发生的事情:
来自 GL_ARB_texture_non_power_of_two
I've read this in the opengl forums:
(source)
I found this which I believe it clarifies what's happening:
from GL_ARB_texture_non_power_of_two