下面的程序在调用 glTextureImage 时立即触发 SEGV。它在 Raspberry Pi 3B 上运行,使用 SDL2 从 KMSDRM 设备打开 OpenGL ES 2.0 上下文。
// actual values: w = 1280, h = 720
// plane contains mono-channel data
// GL_PACK_ALIGNMENT and GL_UNPACK_ALIGNMENT are kept default
void copy_plane_to_texture(const libcamera::FrameBuffer::Plane &plane, int w, int h, GLuint texture)
{
assert(w*h == plane.length); // assert passed
glBindTexture(GL_TEXTURE_2D, texture);
void *addr = mmap(nullptr, plane.length, PROT_NONE, MAP_PRIVATE, plane.fd.get(), plane.offset);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, addr); // immediately crash here
glFinish();
munmap(addr, plane.length);
}