Note that there are some explanatory texts on larger screens.

plurals
  1. POUIImage within Thread not being Released / Overwritten
    primarykey
    data
    text
    <p>This appears to be the the classic method for scanning images from the iPhone. I have a thread that is dispatched from the main thread to go and scan for Codes. It essentially creates a new UIImage each time then removes it.</p> <pre><code>NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; { while (![thread isCancelled]) { #ifdef DEBUG NSLog(@"Decoding Loop"); #endif // [self performSelectorOnMainThread:@selector(updateImageBuffer) withObject:nil waitUntilDone:YES]; CGImageRef cgScreen = UIGetScreenImage(); UIImage *uiimage = [UIImage imageWithCGImage:cgScreen]; if (uiimage){ CGSize size = [uiimage size]; CGRect cropRect = CGRectMake(0.0, 80.0, size.width, 360); // Crop to centre of the screen - makes it more robust #ifdef DEBUG NSLog(@"picked image size = (%f, %f)", size.width, size.height); #endif [decoder decodeImage:uiimage cropRect:cropRect]; } [uiimage release]; CGImageRelease(cgScreen); } } [pool release]; </code></pre> <p>the problem is that the [pool release] causes an ERROR_BAD_EXC (that old classic) and the program bombs. I'm told that there is no need to call [uiimage release] as I havent explicitly allocated a UIImage but this doesn't seem to be the case. If I take that line out, Memory usage goes through the roof and the program quits dues to lack of memory. It appears I can't have this work the way I'd like.</p> <p>Is there a way to create a UIImage "in-place"? I.e, have a buffer that is written to again and again as a UIImage? I suspect that would work?</p> <p><strong>Update!</strong></p> <p>Tried executing the UIKit related calls on the main thread as follows:</p> <pre><code>-(void)performDecode:(id)arg{ // Perform the decoding in a seperate thread. This should, in theory, bounce back with a // decoded or not decoded message. We can quit at the end of this thread. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; { while (![thread isCancelled]) { #ifdef DEBUG NSLog(@"Decoding Loop"); #endif [self performSelectorOnMainThread:@selector(updateImageBuffer) withObject:nil waitUntilDone:YES]; if (uiimage){ CGSize size = [uiimage size]; CGRect cropRect = CGRectMake(0.0, 80.0, 320, 360); // Crop to centre of the screen - makes it more robust #ifdef DEBUG NSLog(@"picked image size = (%f, %f)", size.width, size.height); #endif [decoder decodeImage:uiimage cropRect:cropRect]; } } } [pool drain]; #ifdef DEBUG NSLog(@"finished decoding."); #endif } -(void) updateImageBuffer { CGImageRef cgScreen = UIGetScreenImage(); uiimage = [UIImage imageWithCGImage:cgScreen]; //[uiimage release]; CGImageRelease(cgScreen); } </code></pre> <p>No joy however as EXC_BAD_ACCESS rears its ugly head when one wishes to grab the "Size" of the UIImage</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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