OpenGL ES glReadPixels exc_bad_access

发布于 2024-12-18 22:16:11 字数 1268 浏览 1 评论 0原文

我正在尝试使用 OpenGL ES 和 ffmpeg 从图像创建视频,但在 iPad(4.3) 上我在 glReadPixels 上崩溃

-(NSData *) glToUIImage {

    int numberOfComponents = NUMBER_OF_COMPONENTS; //4
    int width = PICTURE_WIDTH; 
    int height = PICTURE_HEIGHT;

    NSInteger myDataLength = width * height * numberOfComponents;   

    NSMutableData * buffer= [NSMutableData dataWithLength :myDataLength];    

    [self checkForGLError]; 

    GLenum type = NUMBER_OF_COMPONENTS == 3 ? GL_RGB : GL_RGBA; //RGBA
    glReadPixels(0, 0, width, height, type, GL_UNSIGNED_BYTE, [buffer mutableBytes]);   //EXC_BAD_ACCESS here

    return buffer; 
}

它可以在 iPhone 4 (4.3) 和 iPod Touch 上运行,但有问题在 iPhone 3G(3.0) 和 iPad(4.3) 上。你能帮我解决这个问题吗?

另外,在 iPhone 3G(3.0) 和 iPad(4.3) 上,我遇到了视频问题 - 前 5-20 个视频帧有垃圾。也许优化有问题?还是建筑?

已编辑 堆:

#0  0x33be3964 in void BlockNxN<64ul, 16ul, 1, BLOCK_CONVERTER_NULL_32>(unsigned long, int, int, unsigned long, int, int, unsigned int, unsigned int, unsigned int, unsigned int) ()
#1  0x33be1c76 in glrBIFDetile ()
#2  0x33b586b2 in sgxGetImage(SGXImageReadParams const*) ()
#3  0x33b50d38 in gldReadPixels ()
#4  0x31813e16 in glReadPixels_Exec ()
#5  0x31e3c518 in glReadPixels ()

I'm trying to create video from images using OpenGL ES and ffmpeg, but on iPad(4.3) I have a crash on glReadPixels

-(NSData *) glToUIImage {

    int numberOfComponents = NUMBER_OF_COMPONENTS; //4
    int width = PICTURE_WIDTH; 
    int height = PICTURE_HEIGHT;

    NSInteger myDataLength = width * height * numberOfComponents;   

    NSMutableData * buffer= [NSMutableData dataWithLength :myDataLength];    

    [self checkForGLError]; 

    GLenum type = NUMBER_OF_COMPONENTS == 3 ? GL_RGB : GL_RGBA; //RGBA
    glReadPixels(0, 0, width, height, type, GL_UNSIGNED_BYTE, [buffer mutableBytes]);   //EXC_BAD_ACCESS here

    return buffer; 
}

It is working on iPhone 4 (4.3) and iPod Touch, but have problems on iPhone 3G(3.0) and iPad(4.3). Can you help me with this issue?

Also on iPhone 3G(3.0) and iPad(4.3) I have problems with Video - first 5-20 video frames have trash. Maybe issue with optimization? Or architecture?

EDITED
Stack:

#0  0x33be3964 in void BlockNxN<64ul, 16ul, 1, BLOCK_CONVERTER_NULL_32>(unsigned long, int, int, unsigned long, int, int, unsigned int, unsigned int, unsigned int, unsigned int) ()
#1  0x33be1c76 in glrBIFDetile ()
#2  0x33b586b2 in sgxGetImage(SGXImageReadParams const*) ()
#3  0x33b50d38 in gldReadPixels ()
#4  0x31813e16 in glReadPixels_Exec ()
#5  0x31e3c518 in glReadPixels ()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临走之时 2024-12-25 22:16:11

我已经想通了!!!

我已经解决这个问题大约两周了。

您必须在 [(EAGLView *)eagleView PresentFramebuffer]; 之前调用 glReadPixels()

,因此您必须在读取像素之前绑定 colorRenderbuffer。
最终方法清单:

int numberOfComponents = NUMBER_OF_COMPONENTS;
int width = PICTURE_WIDTH;
int height = PICTURE_HEIGHT;

NSInteger myDataLength = width * height * numberOfComponents; 


NSMutableData * buffer= [NSMutableData dataWithLength :myDataLength];
glBindRenderbuffer(GL_RENDERBUFFER_OES, [((EAGLView *)eagleView) colorRenderbuffer]);
[self checkForGLError];
glPixelStorei(GL_PACK_ALIGNMENT, 4); // force 4 byte alignment

glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, [buffer mutableBytes]);
return buffer;

I've figured out!!!

I've fixing this issue about two weeks.

You must call glReadPixels() before [(EAGLView *)eagleView presentFramebuffer];

And so you must bind colorRenderbuffer before you will read pixels.
Final method listing:

int numberOfComponents = NUMBER_OF_COMPONENTS;
int width = PICTURE_WIDTH;
int height = PICTURE_HEIGHT;

NSInteger myDataLength = width * height * numberOfComponents; 


NSMutableData * buffer= [NSMutableData dataWithLength :myDataLength];
glBindRenderbuffer(GL_RENDERBUFFER_OES, [((EAGLView *)eagleView) colorRenderbuffer]);
[self checkForGLError];
glPixelStorei(GL_PACK_ALIGNMENT, 4); // force 4 byte alignment

glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, [buffer mutableBytes]);
return buffer;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文