iphone - OpenGL ES glReadPixels exc_bad_access

标签 iphone ios opengl-es ffmpeg fbo

我正在尝试使用 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 ()

最佳答案

我想通了!!!

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

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

因此在读取像素之前必须绑定(bind) colorRenderbuffer。 final方法列表:

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;

关于iphone - OpenGL ES glReadPixels exc_bad_access,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8308993/

相关文章:

iphone - UITextField 字体样式没有改变

ios - 使用 WebKit 加载 YouTube 视频时控制台中打印警告

IOS 6 UISegmentedControl

iphone - 如何提高 iPhone 上的 OpenCV 性能?

ios - 用于全分辨率图像处理的 GLSL?

ios - iPhone X 键盘通知高度不同

iphone - iPhone 中单个文件的最大大小是多少?

iphone - 在没有 UIWebView 的情况下播放 YouTube 链接的视频

ios - 防止UIScrollView中的UISlider触发滚动

OpenGL 错误处理最佳实践