Note that there are some explanatory texts on larger screens.

plurals
  1. POUIImageWriteToSavedPhotosAlbum causes EXC_BAD_ACCESS
    text
    copied!<p>I develop a CGImage and it works fine when the program displays it on the screen using this:</p> <pre><code>[output_view.layer performSelectorOnMainThread:@selector(setContents:) withObject: (id) image waitUntilDone:YES]; </code></pre> <p>Now, doing this crashes the application:</p> <pre><code>UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage: image)],nil,nil,nil); </code></pre> <p>I don't understand it at all. Here's the stack during the crash:</p> <pre><code>#0 0x33b5db6e in memmove (Line 65) #1 0x341ddee2 in CGAccessSessionGetBytes #2 0x31ab4488 in alphaProviderGetBytes #3 0x341ddf52 in CGAccessSessionGetBytes #4 0x31abbc80 in writeOne #5 0x31abbdae in _CGImagePluginWriteJPEG #6 0x31ab2ddc in CGImageDestinationFinalize #7 0x3037eda2 in imageDataFromImageWithFormatAndProperties #8 0x3037effc in imageDataFromImageRef #9 0x3038ea3c in __-[PLAssetsSaver _saveImage:imageData:properties:completionBlock:]_block_invoke_1 #10 0x33c32680 in _dispatch_call_block_and_release #11 0x33c32ba0 in _dispatch_worker_thread2 #12 0x33bd7250 in _pthread_wqthread </code></pre> <p>Here is the method with the problem:</p> <pre><code>-(void)captureOutput: (AVCaptureOutput *) captureOutput didOutputSampleBuffer: (CMSampleBufferRef) sampleBuffer fromConnection: (AVCaptureConnection *) conenction{ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // Get a CMSampleBuffer's Core Video image buffer for the media data CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); // Lock the base address of the pixel buffer CVPixelBufferLockBaseAddress(imageBuffer, 0); // Get the number of bytes per row for the pixel buffer UInt8 * image_data = CVPixelBufferGetBaseAddress(imageBuffer); // Get the number of bytes per row for the pixel buffer size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); // Get the pixel buffer width and height size_t width = CVPixelBufferGetWidth(imageBuffer); size_t height = CVPixelBufferGetHeight(imageBuffer); //Removed part here which modifies the CVPixelBuffer pixels with a particular algorithm. [bottom_view setNeedsDisplay]; [bottom_view performSelectorOnMainThread:@selector(setBackgroundColor:) withObject: [UIColor colorWithRed:0 green:av/255.0 blue:0 alpha:1] waitUntilDone: YES]; // Create a device-dependent RGB color space CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); // Create a Quartz image from the pixel data CGDataProviderDirectCallbacks providerCallbacks = { 0, GetBytePointer, ReleaseBytePointer, GetBytesAtPosition, 0 }; CGDataProviderRef d_provider = CGDataProviderCreateDirect(image_data,pixels*4,&amp;providerCallbacks); CGImageRef image = CGImageCreate (width,height,8,32,bytesPerRow,colorSpace,kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst,d_provider,NULL,true,kCGRenderingIntentDefault); //Draw image if (needs_photo) { UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage: image],nil,nil,nil); needs_photo = NO; } if (recording) { [writer_input appendSampleBuffer:sampleBuffer]; } [output_view.layer performSelectorOnMainThread:@selector(setContents:) withObject: (id) image waitUntilDone:YES]; // Unlock the pixel buffer CVPixelBufferUnlockBaseAddress(imageBuffer,0); // Free up the context and color space CGColorSpaceRelease(colorSpace); CGImageRelease(image); CGDataProviderRelease(d_provider); [pool drain]; } </code></pre> <p>Thank you for any help with this problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload