Fixed EXC_BAD_ACCESS error in CDVAccelerometer

Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/24a007ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/24a007ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/24a007ad

Branch: refs/heads/master
Commit: 24a007ad31fc623e6674ee8aa9418481f343e2a0
Parents: d888bf3
Author: Shazron Abdullah <shaz...@apache.org>
Authored: Wed May 16 15:02:55 2012 -0700
Committer: Fil Maj <maj....@gmail.com>
Committed: Fri May 18 15:18:20 2012 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVAccelerometer.m |   31 ++++++++++++++-------------
 1 files changed, 16 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/24a007ad/CordovaLib/Classes/CDVAccelerometer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVAccelerometer.m 
b/CordovaLib/Classes/CDVAccelerometer.m
index 51c0ae4..8f8d95b 100644
--- a/CordovaLib/Classes/CDVAccelerometer.m
+++ b/CordovaLib/Classes/CDVAccelerometer.m
@@ -48,8 +48,9 @@
         y = 0;
         z = 0;
         timestamp = 0;
-        accelCallbacks = nil;
-        watchCallbacks = nil;
+        self.accelCallbacks = nil;
+        self.watchCallbacks = nil;
+        self.isRunning = NO;
     }
     return self;
 }
@@ -65,13 +66,13 @@
        UIAccelerometer* pAccel = [UIAccelerometer sharedAccelerometer];
        // accelerometer expects fractional seconds, but we have msecs
        pAccel.updateInterval = desiredFrequency_num / 1000;
-    if (!accelCallbacks) {
-        accelCallbacks = [NSMutableArray arrayWithCapacity:1];            
+    if (!self.accelCallbacks) {
+        self.accelCallbacks = [NSMutableArray arrayWithCapacity:1];            
     }
     if (!watchCallbacks) {
-        watchCallbacks = [NSMutableDictionary dictionaryWithCapacity:1];
+        self.watchCallbacks = [NSMutableDictionary dictionaryWithCapacity:1];
     }
-       if(!_bIsRunning)
+       if(!self.isRunning)
        {
                pAccel.delegate = self;
                self.isRunning = YES;
@@ -96,10 +97,10 @@
     {
         CDVPluginResult* result = [CDVPluginResult 
resultWithStatus:CDVCommandStatus_NO_RESULT];
         [result setKeepCallback:[NSNumber numberWithBool:YES]];
-        if (!accelCallbacks) {
-            accelCallbacks = [NSMutableArray arrayWithCapacity:1];            
+        if (!self.accelCallbacks) {
+            self.accelCallbacks = [NSMutableArray arrayWithCapacity:1];        
    
         }
-        [accelCallbacks addObject:callbackId];
+        [self.accelCallbacks addObject:callbackId];
         [self start];
         [self writeJavascript:[result toSuccessCallbackString:callbackId]];
     } else {
@@ -112,14 +113,14 @@
     NSString* callbackId = [arguments objectAtIndex:0];
     NSString* timerId = [arguments objectAtIndex:1];
     
-    if (!watchCallbacks) {
-        watchCallbacks = [NSMutableDictionary dictionaryWithCapacity:1];
+    if (!self.watchCallbacks) {
+        self.watchCallbacks = [NSMutableDictionary dictionaryWithCapacity:1];
     }
     
     // add the callbackId into the dictionary so we can call back whenever get 
data
-    [watchCallbacks setObject:callbackId forKey:timerId];
+    [self.watchCallbacks setObject:callbackId forKey:timerId];
     
-    if (!_bIsRunning) {
+    if (!self.isRunning) {
         [self start];
     }
     CDVPluginResult* result = [CDVPluginResult 
resultWithStatus:CDVCommandStatus_NO_RESULT];
@@ -130,8 +131,8 @@
 {
     NSString* callbackId = [arguments objectAtIndex:0];
     NSString* timerId = [arguments objectAtIndex:1];
-    if (watchCallbacks && [watchCallbacks objectForKey:timerId]) {
-        [watchCallbacks removeObjectForKey:timerId];
+    if (self.watchCallbacks && [self.watchCallbacks objectForKey:timerId]) {
+        [self.watchCallbacks removeObjectForKey:timerId];
     }
     CDVPluginResult* result = [CDVPluginResult 
resultWithStatus:CDVCommandStatus_OK];
     NSString* jsString = [result toSuccessCallbackString:callbackId];

Reply via email to