3

I'm trying to texture an OpenGL object with a video. It's almost done but I have a crash with my textureWithCGImage method and I don't know why.

        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);

this code is called at every update. Have you an idea about what's causing my crash ?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Pierre
  • 10,593
  • 5
  • 50
  • 80
  • I have this error : Error loading texture: The operation couldn’t be completed. (GLKTextureLoaderErrorDomain error 8.) aka GLKTextureLoaderErrorUncompressedTextureUpload – Pierre Feb 27 '12 at 12:04
  • Same here. Did you solve the problem? – hanno May 29 '12 at 00:00
  • I'm just using the plain old teximage2d for now. That works. – hanno May 29 '12 at 14:15
  • I was having this same issue, GLKTextureLoaderErrorDomain error 8. After a while I managed to change something so it stopped returning an error. However, then it just started returning an invalid texture pointer in the returned texture info! Don't use GLKTextureLoader, it's well and completely broken. – Tim R. Jun 15 '12 at 01:27

0 Answers0