hzxu
hzxu

Reputation: 5823

EXEC-bad-access when invoking block inside a block

INTERFACE

@interface MyClass

@property (nonatomic, copy) SomeBlock someBlock;

@end

IMPLEMENTATION

- (void)myMethodWithBlock:(SomeBlock)theBlock
{
  self.someBlock = theBlock;
  [someHelper doSomethingWithCompletionBlock:^(){
        self.someBlock(arg1);
  }
}

Where self.someBlock(arg1) gives me EXEC_BAD_ACCESS, I did define someBlock to be copied.

What can be the problem?

Upvotes: 1

Views: 459

Answers (1)

user529758
user529758

Reputation:

So it looks like the block is sometimes nil. When a block is invoked, it's dereferenced, but dereferencing nil and NULL crashes the app. Check for if (self.someBlock != nil) and it should not crash anymore.

Upvotes: 1

Related Questions