Attempting to create USE_BLOCK_IN_FRAME ... EXC_BAD_ACCESS with NSFetchedResultsController

Jim picture Jim · May 7, 2011 · Viewed 7.6k times · Source

This is an update to my problem. I am receiving this warning now when the program aborts. warning: Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame.

I can't find much information on what this means.


This has me baffled. I get the EXC_BAD_ACCESS error. I have NSZombieEneabled (which helped with an earlier problem), but there is no call stack to trace.

I have some nearly identical code that is working with respect to another fetched result controller.

This seems to have something to do with the relationships between the job entity and its associated client entity. The relationship is [job entity] <<--> [client entity].

Initially, I see that the code works without error where the job entity corresponding to the selected row has no client entity linked through a relationship. So in the case where it fails, this points to a client entity, but when it doesn't fail, the pointer is nil.

When I encounter this problem, I start the application and go directly to the job picker view and select a cell. It's at that point that the problem occurs.

I did an experiment by starting the application and going to the client picker view first, knowing that a fetch would occur of all of the client entities. Then I went to the job picker view and selected a cell. The problem did not occur.

Since I am just trying to pass a pointer to a job entity that was already fetched, I don't understand what's happening.

By the way, the code was working fine before I switched to using NSFetchedResultsControllers. I like what they can do for me, but there are some dynamics going on here that I haven't figured out.

The logging is not showing me anything I understand toward resolving the problem.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    userState.selectedJob = [self.fetchedResultsController objectAtIndexPath:indexPath];
    NSLog(@"\n\n(1 Pick) indexPath: %@\n",indexPath);
    NSLog(@"\n\n(1 Pick) userState: %@\n",userState);    
    NSLog(@"\n\nnumber of Objects in job fetchresultscontroller = %d", [[fetchedResultsController fetchedObjects] count] );    
    NSLog(@"\n\n(1 Pick) selected job: %@\n",[self.fetchedResultsController objectAtIndexPath:indexPath]); // This line is causing the problem...
    NSLog(@"\n\n(1 Pick) selected job: %@\n",userState.selectedJob); // Omitting the line above, this line fails 
    [self.navigationController pushViewController:userState.jobInfoTVC animated:YES];     
}

The debug output is

2011-05-07 09:27:04.142 job1[6069:207] 

(1 Pick) indexPath: <NSIndexPath 0x5952590> 2 indexes [0, 3]
2011-05-07 09:27:04.142 job1[6069:207] 

(1 Pick) userState: <UserStateObject: 0x5919970>
2011-05-07 09:27:04.143 job1[6069:207] 

number of Objects in job fetchresultscontroller = 4
(gdb) 

The final code should be as simple as this, which led me to all of the logging:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    userState.selectedJob = [self.fetchedResultsController objectAtIndexPath:indexPath]; // Original failure was at this line
    [self.navigationController pushViewController:userState.jobInfoTVC animated:YES];     
}

I use the singleton userState to keep track of what the user has done. So I keep last selectedJob and selectedClient entity pointers there. This has worked okay before I switched to NSFetchedResultsController.

Answer

Brett picture Brett · Nov 24, 2011

I have also had a problem with Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame. Although mine wasn't anything to do with NSFetchedResultsControllers.

Possibly Your Problem

I noticed you mention you are using a singleton, so maybe your problem is solved at this link:

http://npenkov.com/2011/08/01/solving-issues-like-warning-attempting-to-create-use_block_in_frame-variable-with-block-that-isnt-in-the-frame/

From the link:

Exactly in session manager I used the macro, before @synthesize – this was the problem, static definitions should not appear before synthesized methods. So if you have something like:

SYNTHESIZE_SINGLETON_FOR_CLASS(SessionManager)
@synthesize loggedUserId, ...

Just replace it with:

@synthesize loggedUserId, ...
SYNTHESIZE_SINGLETON_FOR_CLASS(SessionManager)

enter code here

My problem

The problem I had was to do with duplicating a variable declaration, in this case the variable inherited from NSManagedObject :

- (void)functionThatDoesSomething {

    VariableInheritedFromNSMObj *variableA = nil;

    for (VariableInheritedFromNSMObj *variableA in [self containerObject]) {
         NSLog(@"a = %@\n", [variableA name]);
    }

    [variableA setName:@"StackOverflow"];

}

Moving the first line, where variableA is initialised to nil, to after the loop fixed the problem. In my production code I then changed the name of one of the variables.

Hope that helps you or someone else who comes across this problem. This error seems to manifest itself in many different ways.