Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I'm developing a whole new app that's a game. In this game, multiple users use the same device, one user at a time. Users will unlock each level by completing the preceding one. I have a Core Data model that my app will use to keep track of which level the user has unlocked. Prior to playing any level, the user must select that level from a menu.

So, I have an NSManagedObject representing the user. This object stores data on which level the user unlocked. If no such data is available, it's because the user hasn't completed a level. The problem is that
Code:
[self valueForKey:@"key"]

causes an EXC_BAD_ACCESS code 2 when the app checks to see which level the user is on.
 
Stack Overflow seems to point to Zombies.
Here: http://stackoverflow.com/questions/11717193/exc-bad-access-code-2

Here's what they say about what zombies are:
http://stackoverflow.com/questions/4168327/what-is-nszombie

In addition, we can't tell much about what 'self' is and how it's been setup. Maybe post some more of the code.
Yes, I've used zombies before.
"self" refers to the managed object (Menu view controller basically asks for an object of a certain type,then the managed object is to retrieve an NSData and unarchive it to get the desired object.
 
Ok, so you are trying to retrieve an object from Core Data and the call to get the data crashes.

You mention that the data may or may not be there, and this is the flag to indicate if a level has been completed.

Is the crash related to the data not being there? In other words, does it work if the data is there and crashes if the data is not there?

Isn't EXE_BAD_ACCESS something to do with an invalid pointer? I really don't know the error messages, but there has to be some docs on it somewhere.

Has there been a change in the structure of the object that you are getting?

Is there a native data type vs an non-native that needs to be converted?
 
Ok, so you are trying to retrieve an object from Core Data and the call to get the data crashes.

You mention that the data may or may not be there, and this is the flag to indicate if a level has been completed.

Is the crash related to the data not being there? In other words, does it work if the data is there and crashes if the data is not there?

Isn't EXE_BAD_ACCESS something to do with an invalid pointer? I really don't know the error messages, but there has to be some docs on it somewhere.

Has there been a change in the structure of the object that you are getting?

Is there a native data type vs an non-native that needs to be converted?

Here's what's supposed to happen:
1) User launches app.
2) User selects his name from a list
3) The level menu view controller requests, from the associated NSManagedObject, data that indicates which levels the user has unlocked. This data is stored in a key - which we shall call "level" - and is of the Binary Data type. However, there is a property by the same name in my NSManagedObject subclass that is of a different type. That's the way I wanted it because I wanted the managed object to archive/unarchive this property.

There was a change in the model, but I think I deleted the app after making the change.
 
I'm not an expert on the error messages, so what I would do myself is to write a new program that stores and retrieves the exact same data from a core data store.

There are many examples out there using core data, I would get some of those and see if you can change the data they use in their example over to the types of data you use.

In other words, it looks like the problem is in understanding how to use core data and you're getting a cryptic error message. There are sample apps that show exactly how to use core data and I would use those to determine what's going wrong with your setup.

Unless someone knows that message or if there's access to a more detailed error message, that's seems like the best approach.

I've only done a few tutorials on Core Data, so maybe someone else knows the error messages.

One other idea. Does the object have to be allocated before you get it from the data store or is it self allocating? Maybe Core Data is trying to put data into an address that isn't setup or doesn't have allocated memory.
 
I'm not an expert on the error messages, so what I would do myself is to write a new program that stores and retrieves the exact same data from a core data store.

There are many examples out there using core data, I would get some of those and see if you can change the data they use in their example over to the types of data you use.

In other words, it looks like the problem is in understanding how to use core data and you're getting a cryptic error message. There are sample apps that show exactly how to use core data and I would use those to determine what's going wrong with your setup.

Unless someone knows that message or if there's access to a more detailed error message, that's seems like the best approach.

I've only done a few tutorials on Core Data, so maybe someone else knows the error messages.

One other idea. Does the object have to be allocated before you get it from the data store or is it self allocating? Maybe Core Data is trying to put data into an address that isn't setup or doesn't have allocated memory.

I fixed the error by using
Code:
[self primitiveValueForKey]
. Of course, then I had to use
Code:
[self setPrimitiveValue:forKey:
instead of
Code:
[self setValue:forKey:]
in the setter method.
 
Ok, so that means the problem was an object type vs a primitive type?

Were you trying to put a primitive type into an object?

The reason I ask is that people will search this thread to find answers to their problems.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.