Re: NSOutlineView threading problem
Re: NSOutlineView threading problem
- Subject: Re: NSOutlineView threading problem
- From: David <email@hidden>
- Date: Sun, 15 Jun 2008 17:36:41 -0400
Thanks for the responses. I've SOLVED IT. WooHoo!
What I thought I was doing seems to be working. I am able to run a secondary
thread, adding nodes to the tree I'm displaying in the primary thread. All
problems appear to have been resolved. No need for locking or any other
magic.
I think folks are a little too spooked by Apple saying that Cocoa isn't
thread safe. That doesn't mean you have to avoid threads like the plague.
The problem was that when I was done adding nodes on the 2nd thread, I was
sending a notification. When the notification was received, I was doing a
reloadData and display on the outline view.
I forgot that I was doing that from the secondary thread. That meant the
receiver of the notification was also on the secondary thread. That meant
that I had both threads possibly doing reloads and displays of the same view
at the same time.
THAT, I can understand as being a really bad thing to do.
I used performSelectorOnMainThread to send the notification from the main
thread and voila, problems "appear" to be gone.
Thanks for the responses.
NSLog came to the rescue showing me the timestamp and thread id, showing me
that I was doing things I didn't think I was doing on the secondary thread.
On Sat, Jun 14, 2008 at 10:19 PM, David <email@hidden> wrote:
> I'm having various intermittent problems with NSOutlineView which I can
> only presume is somehow caused by my use of a secondary thread to augment
> the node tree supplied via a data source.
>
> My assumption has been that I'm not doing anything that should cause
> NSOutlineView a problem. I am strictly adding additional nodes to the tree.
> I am not removing nor modifying existing trees.
>
> I am using NSMutableArrays to hold the nodes in the tree. One thread is
> adding child nodes while the main thread maybe accessing the arrays through
> the data source. I find it hard to imagine that NSMutableArray could be
> causing the problem.
>
> I cannot figure out what type of scenario could or should cause
> NSOutlineView a problem. Any suggestions appreciated. So far I've noticed
> three types of errant behavior at random inconsistent times:
>
> 1) A crash occurs with a nil pointer deep in the bowels of NSOutlineView
> processing. I don't have source, so the stack trace doesn't mean much to me.
> I never have even an intermediate state where any property or pointer is
> nil. I fully construct the node before adding it to the tree.
> 2) The view displays the tree. I have code to expand the tree down to a
> level of nodes created in the main thread. Sometimes after the view displays
> the tree, it suddenly disappears as if some other layer redrew over it. The
> outline view itself is still visible where I have it configured to a banded
> background.
> 3) In the main thread, I create a few nodes, then spawn a thread to
> populate the deepest node with children. In the main thread I tell the
> NSOutlineView to expand the nodes that were created by the main thread, one
> layer higher than where the children are being added.
> The expanded view sometimes gets messed up. Sometimes it does not display
> the last node as expandable even though I have code asking to reload the
> nodes added in the main thread, and display the view.
>
> Thanks
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden