Hi MacRumours,
I'm writing an iPhone app which uses the accelerometer to control another external application (just for some context).
In order to calculate the difference between the previous accelerometer value and this one I use the following two lines (I only need X and Y):
This works most of the time, but sometimes (either randomly or when the difference becomes large, mostly the latter) I get EXC_BAD_ACCESS on the first of the two lines above.
In GDB I tried the following:
after I got the EXC_BAD_ACCESS code and as you can see, the sum works...
I then tried the following:
I'm not entirely sure what to do here since it works most of the time. Any ideas would be much appreciated.
I'm writing an iPhone app which uses the accelerometer to control another external application (just for some context).
In order to calculate the difference between the previous accelerometer value and this one I use the following two lines (I only need X and Y):
Code:
float diffx = ([acceleration x] - [prevAccel x])*100;
float diffy = ([acceleration y] - [prevAccel y])*100;
This works most of the time, but sometimes (either randomly or when the difference becomes large, mostly the latter) I get EXC_BAD_ACCESS on the first of the two lines above.
In GDB I tried the following:
Code:
(gdb) p acceleration
$3 = (UIAcceleration *) 0x128500
(gdb) p acceleration.x
$4 = 0.869384765625
(gdb) p acceleration.y
$5 = -0.036224365234375
(gdb) p acceleration.z
$6 = -0.543365478515625
(gdb) p prevAccel.x
$7 = 4.6495020515960297e-315
(gdb) p prevAccel.y
$8 = 1.7286328172809227e-38
(gdb) p prevAccel.z
$9 = 0
(gdb) p (acceleration.x - prevAccel.x)
$10 = 0.869384765625
after I got the EXC_BAD_ACCESS code and as you can see, the sum works...
I then tried the following:
Code:
(gdb) continue
Continuing.
Program received signal: EXC_BAD_ACCESS.
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x0000000f
0x31ec3ebc in objc_msgSend ()
(gdb) x/s $r1
0x34370cc4 <__PRETTY_FUNCTION__.55878+13008>: "x"
I'm not entirely sure what to do here since it works most of the time. Any ideas would be much appreciated.