aligned_alloc和glTexSubImage2D导致分割错误



我尝试初始化纹理(在opengl中)。如果传输到glTexSubImage2D的块使用malloc分配,则初始化工作良好。如果我使用aligned_alloc,大多数情况下,我得到的是段错误。为什么?

重现问题的最小代码段:

GLuint texture_id;
GLenum err;
int sx = 2048;
int sy = 1024;
char *data = (char *)aligned_alloc(sizeof(char)*sx*sy*3, ALIGN_VALUE);
//char *data = (char *)malloc(sizeof(char)*sx*sy*3);
glGenTextures(1, &texture_id);
glActiveTexture(texture_unit);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, sx, sy);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, sx, sy, GL_BGR, GL_UNSIGNED_BYTE, data);

Valgrind列出了aligned_alloc的许多错误。两个(和第一个一样)在aligned_alloc调用的位置。所有其他(许多像第二个)在glTexSubImage2D命令的位置。

==7042== Invalid read of size 1
==7042==    at 0x4045F71: ??? (in /tmp/.glamhkos (deleted))
==7042==    by 0xCFFFFFF: ???
==7042==    by 0xD68A04F: ???
==7042==    by 0xFFEFFFE3F: ???
==7042==  Address 0xd000002 is 0 bytes after a block of size 2 alloc'd
==7042==    at 0x4C2B1B6: memalign (vg_replace_malloc.c:760)
...
==7042==    by 0x4016E1: main (in /.../)

==7042== Invalid read of size 1
==7042==    at 0x4045F71: ??? (in /tmp/.glamhkos (deleted))
==7042==    by 0xD0017FF: ???
==7042==    by 0xD68C04F: ???
==7042==    by 0xFFEFFFE3F: ???
==7042==    by 0x1: ???
==7042==    by 0x7B23325: ??? (in /usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.352.79)
==7042==    by 0x7B2D9A6: ??? (in /usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.352.79)
==7042==    by 0x7C7DD40: ??? (in /usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.352.79)
==7042==    by 0x7C51383: ??? (in /usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.352.79)
==7042==    by 0x7C52A16: ??? (in /usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.352.79)
==7042==    by 0x7C6F553: ??? (in /usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.352.79)
...
==7042==  Address 0xd001802 is 6,146 bytes inside a block of size 6,852,752 in arena "client"

更改ALIGN_VALUE没有帮助。

当我使用malloc时,Valgrind没有列出错误

我在我的最小示例中错误地使用了aligned_alloc(sizeof(char)sxsy*3, ALIGN_VALUE)。参数错误。

改为:aligned_alloc (ALIGN_VALUE sizeof (char) sx sy * 3)

相关内容

  • 没有找到相关文章