I've structured my plist as follows
Code:
Array (represents all pictures)
Array1 (represents picture)
Dictionary1 (2 coordinates for difference in image)
Number1 (x1 coordinate)
Number2 (y1 coordinate)
Number3 (x2 coordinate)
Number4 (y2 coordinate)
Number5 (found variable set to 1 if this difference found)
...
ArrayN
Dictionary1
Number1
Number2
Number3
Number4
Number5
An outer array represents all of my pictures, while the inner array represents an individual picture. Each of the 5 dictionaries in the inner array holds coordinates for differences in the pictures. The found variable is set to 1 when a difference for this image is found.
I detect when the user touches each point with the following code, shortened for brevity:
Code:
//pseudo code for brevity
-(void)touchesEnded:
get touch location
for (each dictionary in the picture array) {
if (player touches one of the points) {
set the found variable for this point to 1/YES
}
}
In the if statement, when a difference is successfully found, I set the "found" variable in my dictionary to "1" to indicate that I found a difference.
In the simulator everything works fine. But when I load the app onto my phone, and tap a difference point, the screen freezes. The only way to quit is to stop it within Xcode. Using the debugger, I pinpointed the crash to the line of code "[currentDiff setObject:tempBool forKey:@"found"];" below. Specifically the tempBool variable.
Code:
//2 rects always point to 1 difference. if finger in one of the two rects, found a difference
if (((CGRectContainsPoint(leftRect, location)) || CGRectContainsPoint(rightRect, location)) && (found == 0))
{
//now that we've found a difference, update local copy of the picture data and set its found flag to 1(true)
NSNumber *tempFound = [[NSNumber alloc] initWithInt:1];
[currentDiff setObject:tempFound forKey:@"found"]; //crashing game on iphone
[tempFound release];
[localCopyPic replaceObjectAtIndex:i withObject:currentDiff];
}
Why does this code work in the simulator but not on my phone?