纹理WithCGImage崩溃iOS
我正在尝试用视频对OpenGL对象进行纹理处理。几乎完成了,但是我的textureWithCGImage方法崩溃了,我不知道为什么纹理WithCGImage崩溃iOS,ios,opengl-es,textures,cgimage,Ios,Opengl Es,Textures,Cgimage,我正在尝试用视频对OpenGL对象进行纹理处理。几乎完成了,但是我的textureWithCGImage方法崩溃了,我不知道为什么 CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); // Lock the image buffer CVPixelBufferLockBaseAddress(imageBuffer,0); //
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the image buffer
CVPixelBufferLockBaseAddress(imageBuffer,0);
// Get information of the image
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGImageRef newImage = CGBitmapContextCreateImage(newContext);
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:GLKTextureLoaderOriginBottomLeft];
self.texture = [GLKTextureLoader textureWithCGImage:newImage options:options error:nil];
if (self.texture == nil) NSLog(@"Error loading texture: %@", [error localizedDescription]);
else
{
GLKEffectPropertyTexture *tex = [[[GLKEffectPropertyTexture alloc] init] autorelease];
tex.enabled = GL_TRUE;
tex.envMode = GLKTextureEnvModeDecal;
tex.name = self.texture.name;
self.effect.texture2d0.name = tex.name;
}
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
CGImageRelease(newImage);
CGContextRelease(newContext);
CGColorSpaceRelease(colorSpace);
CFRelease(sampleBuffer);
每次更新时都会调用此代码。你知道是什么导致了我的崩溃吗?我有一个错误:加载纹理时出错:操作无法完成。(GLKTextureLoaderErrorDomain错误8。)又名GLKTextureLoaderErrorRunCompressedTextureUploadSame。你解决问题了吗?我现在只使用普通的旧teximage2d。行得通。我也遇到了同样的问题,GLKTextureLoaderErrorDomain错误8。过了一会儿,我设法改变了一些东西,所以它不再返回错误。但是,它只是开始在返回的纹理信息中返回一个无效的纹理指针!不要使用GLKTextureLoader,它已完全损坏。