src/joystick/iphoneos/SDL_sysjoystick.m
branchiOS-improvements
changeset 9506 18e3f94bd860
parent 9490 9eab796ea0b8
child 9510 e19faa3b5d88
     1.1 --- a/src/joystick/iphoneos/SDL_sysjoystick.m	Tue Jul 29 00:05:48 2014 -0300
     1.2 +++ b/src/joystick/iphoneos/SDL_sysjoystick.m	Tue Jul 29 00:36:12 2014 -0300
     1.3 @@ -90,14 +90,16 @@
     1.4      joystick->nballs = 0;
     1.5      joystick->nbuttons = 0;
     1.6  
     1.7 -    if (motionManager == nil) {
     1.8 -        motionManager = [[CMMotionManager alloc] init];
     1.9 +    @autoreleasepool {
    1.10 +        if (motionManager == nil) {
    1.11 +            motionManager = [[CMMotionManager alloc] init];
    1.12 +        }
    1.13 +
    1.14 +        /* Shorter times between updates can significantly increase CPU usage. */
    1.15 +        motionManager.accelerometerUpdateInterval = 0.1;
    1.16 +        [motionManager startAccelerometerUpdates];
    1.17      }
    1.18  
    1.19 -    /* Shorter times between updates can significantly increase CPU usage. */
    1.20 -    motionManager.accelerometerUpdateInterval = 0.1;
    1.21 -    [motionManager startAccelerometerUpdates];
    1.22 -
    1.23      return 0;
    1.24  }
    1.25  
    1.26 @@ -113,12 +115,14 @@
    1.27      const SInt16 maxsint16 = 0x7FFF;
    1.28      CMAcceleration accel;
    1.29  
    1.30 -    if (!motionManager.accelerometerActive) {
    1.31 -        return;
    1.32 +    @autoreleasepool {
    1.33 +        if (!motionManager.accelerometerActive) {
    1.34 +            return;
    1.35 +        }
    1.36 +
    1.37 +        accel = motionManager.accelerometerData.acceleration;
    1.38      }
    1.39  
    1.40 -    accel = [[motionManager accelerometerData] acceleration];
    1.41 -
    1.42      /*
    1.43       Convert accelerometer data from floating point to Sint16, which is what
    1.44       the joystick system expects.
    1.45 @@ -161,7 +165,9 @@
    1.46  void
    1.47  SDL_SYS_JoystickClose(SDL_Joystick * joystick)
    1.48  {
    1.49 -    [motionManager stopAccelerometerUpdates];
    1.50 +    @autoreleasepool {
    1.51 +        [motionManager stopAccelerometerUpdates];
    1.52 +    }
    1.53      joystick->closed = 1;
    1.54  }
    1.55  
    1.56 @@ -169,9 +175,11 @@
    1.57  void
    1.58  SDL_SYS_JoystickQuit(void)
    1.59  {
    1.60 -    if (motionManager != nil) {
    1.61 -        [motionManager release];
    1.62 -        motionManager = nil;
    1.63 +    @autoreleasepool {
    1.64 +        if (motionManager != nil) {
    1.65 +            [motionManager release];
    1.66 +            motionManager = nil;
    1.67 +        }
    1.68      }
    1.69  
    1.70      numjoysticks = 0;