Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is addObserver crashing instantly?
    primarykey
    data
    text
    <p>I have various kinds of operations (derived from NSOperation) to do async queries over the Internet. As is the norm, I determine when they're finished by observing their isFinished property.</p> <p>When one particular type of operation finishes, I want to create a follow-up type of operation using info from the first. But when I do so, calling addObserver on the operation crashes my app with a bad access. Since observers are called in a random thread, I tried creating the follow-up operation and setting the observer on the main thread. No difference. This is being done in observeValueForKeyPath:</p> <pre><code>GetMessagesOperation* msgOp = [[GetMessagesOperation alloc] initWithUserID:_user.getID() sinceLast:true includeSystem:true includeUser:false skipRows:0 maxCount:50 DBManager:_pDatabaseMgr]; [msgOp addObserver:self forKeyPath:@"isFinished" options:0 context:getMessageContext]; [_operationQueue addOperation:msgOp]; [msgOp release]; </code></pre> <p>The context is a void* to a string; I use the same syntax for many other operations that work fine. Here's how the contexts are defined:</p> <pre><code>static void* systemInfoContext = (void*)@"sys"; static void* validateUserContext = (void*)@"user"; static void* getMessageContext = (void*)@"msg"; </code></pre> <p>Anybody have a guess here? Thanks!</p> <p>Edit: Thanks for the reply. There's no crash log generated. It just quits with a bad access on the addObserver line, and this happens regardless of whether I execute in on the main thread or the background thread in which observeValueForKeyPath is entered.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload