From 7a9d557c6d1dc1db0e9d256161f0a0eec1558632 Mon Sep 17 00:00:00 2001 From: rpechayr Date: Sun, 30 May 2010 11:40:09 +0000 Subject: [PATCH] [iphone] all memory leaks fixed. A number of minor bugs corrected git-svn-id: http://zxing.googlecode.com/svn/trunk@1397 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- iphone/ScanTest/Classes/RootViewController.m | 12 ++++--- .../ScanTest.xcodeproj/project.pbxproj | 3 +- iphone/ZXingWidget/Classes/Decoder.mm | 32 +++++++++---------- .../Classes/ZXingWidgetController.h | 6 ++-- .../Classes/ZXingWidgetController.m | 24 +++++++++++--- .../ZXingWidget.xcodeproj/project.pbxproj | 5 +-- 6 files changed, 52 insertions(+), 30 deletions(-) diff --git a/iphone/ScanTest/Classes/RootViewController.m b/iphone/ScanTest/Classes/RootViewController.m index cec46935..2af80bbc 100644 --- a/iphone/ScanTest/Classes/RootViewController.m +++ b/iphone/ScanTest/Classes/RootViewController.m @@ -7,11 +7,16 @@ // #import "RootViewController.h" +@interface RootViewController() +@property (nonatomic,retain) ZXingWidgetController *scanController; + +@end @implementation RootViewController @synthesize resultsView; @synthesize resultsToDisplay; +@synthesize scanController; #pragma mark - #pragma mark View lifecycle @@ -19,10 +24,9 @@ [super viewDidLoad]; [self setTitle:@"ZXing"]; - scanController = [[ZXingWidgetController alloc] initWithDelegate:self]; - [scanController setOneDMode:NO]; - [scanController setShowCancel:YES]; - scanController = [scanController initWithDelegate:self]; + ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO]; + self.scanController = widController; + [widController release]; NSBundle *mainBundle = [NSBundle mainBundle]; [scanController setSoundToPlay:[[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO] retain]]; diff --git a/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj b/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj index 2b043303..af586490 100755 --- a/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj +++ b/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj @@ -279,6 +279,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; COPY_PHASE_STRIP = YES; + EXPORTED_SYMBOLS_FILE = ../ZXingWidget/exportList; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = ScanTest_Prefix.pch; INFOPLIST_FILE = "ScanTest-Info.plist"; @@ -317,7 +318,7 @@ HEADER_SEARCH_PATHS = "../ZXingWidget/Classes/**"; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; PREBINDING = NO; - SDKROOT = iphonesimulator3.1.3; + SDKROOT = iphoneos3.1.3; }; name = Release; }; diff --git a/iphone/ZXingWidget/Classes/Decoder.mm b/iphone/ZXingWidget/Classes/Decoder.mm index edc6336a..cc2c7d68 100644 --- a/iphone/ZXingWidget/Classes/Decoder.mm +++ b/iphone/ZXingWidget/Classes/Decoder.mm @@ -155,10 +155,8 @@ using namespace zxing; } - (void)decode:(id)arg { - NSAutoreleasePool* mainpool = [[NSAutoreleasePool alloc] init]; { - NSSet *formatReaders = [FormatReader formatReaders]; Ref source (new GrayBytesMonochromeBitmapSource(subsetData, subsetWidth, subsetHeight, subsetBytesPerRow)); @@ -252,25 +250,27 @@ using namespace zxing; [self decodeImage:i cropRect:CGRectMake(0.0f, 0.0f, i.size.width, i.size.height)]; } -- (void) decodeImage:(UIImage *)i cropRect:(CGRect)cr { - self.image = i; - self.cropRect = cr; - + +- (void) asyncDecodeImage { [self prepareSubset]; [self willDecodeImage]; + [self performSelectorOnMainThread:@selector(willDecodeImage) + withObject:nil + waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(progressDecodingImage:) - withObject:NSLocalizedString(@"Decoder MessageWhileDecoding", @"Decoding ...") - waitUntilDone:NO]; - NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(decode:) object:nil]; + withObject:NSLocalizedString(@"Decoder MessageWhileDecoding", @"Decoding ...") + waitUntilDone:NO]; +/* NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(decode:) object:nil]; + [operationQueue addOperation:op]; + [op release];*/ + [self decode:nil]; +} +- (void) decodeImage:(UIImage *)i cropRect:(CGRect)cr { + self.image = i; + self.cropRect = cr; + NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(asyncDecodeImage) object:nil]; [operationQueue addOperation:op]; [op release]; - //[self performSelectorInBackground:@selector(decode:) withObject:nil]; - - - //[self performSelector:@selector(decode:) onThread:decodingThread withObject:nil waitUntilDone:NO]; - /*[NSThread detachNewThreadSelector:@selector(decode:) - toTarget:self - withObject:nil];*/ } - (void) dealloc { diff --git a/iphone/ZXingWidget/Classes/ZXingWidgetController.h b/iphone/ZXingWidget/Classes/ZXingWidgetController.h index daf29b9d..252d4aa1 100755 --- a/iphone/ZXingWidget/Classes/ZXingWidgetController.h +++ b/iphone/ZXingWidget/Classes/ZXingWidgetController.h @@ -35,13 +35,13 @@ } @property (nonatomic, assign) id delegate; -@property (nonatomic, assign) BOOL showCancel; @property (nonatomic, assign) NSURL *soundToPlay; -@property (nonatomic, assign) BOOL oneDMode; @property (nonatomic, retain) ParsedResult *result; @property (nonatomic, retain) NSArray *actions; +@property (nonatomic, retain) OverlayView *overlayView; + +- (id)initWithDelegate:(id)delegate showCancel:(BOOL)shouldShowCancel OneDMode:(BOOL)shouldUseoOneDMode; -- (id)initWithDelegate:(id)delegate; - (BOOL)fixedFocus; @end diff --git a/iphone/ZXingWidget/Classes/ZXingWidgetController.m b/iphone/ZXingWidget/Classes/ZXingWidgetController.m index 173af15e..672d3761 100755 --- a/iphone/ZXingWidget/Classes/ZXingWidgetController.m +++ b/iphone/ZXingWidget/Classes/ZXingWidgetController.m @@ -27,14 +27,29 @@ #define FIRST_TAKE_DELAY 1.0 #define ONE_D_BAND_HEIGHT 10.0 -CGImageRef UIGetScreenImage(); +CGImageRef UIGetScreenImage(void); + +@interface ZXingWidgetController () + +@property BOOL showCancel; +@property BOOL oneDMode; + +@end + + + + @implementation ZXingWidgetController -@synthesize result, actions, showCancel, delegate, soundToPlay, oneDMode; +@synthesize result, actions, delegate, soundToPlay; +@synthesize overlayView; +@synthesize oneDMode, showCancel; -- (id)initWithDelegate:(id)scanDelegate { +- (id)initWithDelegate:(id)scanDelegate showCancel:(BOOL)shouldShowCancel OneDMode:(BOOL)shouldUseoOneDMode { if (self = [super init]) { [self setDelegate:scanDelegate]; + self.oneDMode = shouldUseoOneDMode; + self.showCancel = shouldShowCancel; beepSound = -1; self.wantsFullScreenLayout = YES; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) @@ -65,7 +80,8 @@ CGImageRef UIGetScreenImage(); if (beepSound != -1) { AudioServicesDisposeSystemSoundID(beepSound); } - [overlayView dealloc]; + self.cameraOverlayView = nil; + [overlayView release]; [super dealloc]; } diff --git a/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj b/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj index 86cc47f9..3fea652d 100644 --- a/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj +++ b/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj @@ -1130,6 +1130,7 @@ HEADER_SEARCH_PATHS = ../../cpp/core/src; INSTALL_PATH = /usr/local/lib; PRODUCT_NAME = ZXingWidget; + SDKROOT = iphoneos3.1.3; }; name = Release; }; @@ -1144,7 +1145,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 3.1.3; OTHER_LDFLAGS = "-ObjC"; PREBINDING = NO; - SDKROOT = iphoneos4.0; + SDKROOT = iphoneos3.1.3; }; name = Debug; }; @@ -1158,7 +1159,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 3.1.3; OTHER_LDFLAGS = "-ObjC"; PREBINDING = NO; - SDKROOT = iphoneos4.0; + SDKROOT = iphoneos3.1.3; }; name = Release; }; -- 2.20.1