New RapidBlog

I just pushed a new rapidblog up, see the changelog for details and download links. This is a recommended update as it fixes a number of problems and cleans up lingering UTF8 issues.

Most importantly it fixes, in a nice way, the 'hang' that occasionally occurred during publish.

Normally I don't talk too much cocoa in this blog but I wanted to put something out in googleland for the next poor sap who had a problem.

Basically the root of my problem was I was modifying entries bound in a NSArrayController. This, in itself, is not a problem except I was doing it in a background thread -- I can't really control this as RW pushes my code to a background thread during a publish and, again, this is not necessarily a problem except for the fact that I was occasionally updating the contents of the bound objects. Again, this in and of itself is not a problem except that one of the things being bound was a MutableString bound to a NSTextView (RWTextView).

That is a problem -- You see NSTextView stores it's content in a 'NSTextStorage' which is a mutable object and that, in fact, is not thread safe. The problem was that the main render code would sometimes try to render the scene exactly as I was modifying it causing a 'deadlock' -- Each process was waiting for the other to finish which was the hang.

The solution? It ended up being pretty easy (as these things often are) in retrospect but it was painful to find. I ended up listenting for notification from RapidWeaver that it was about to start publishing. Then I told the NSArrayController to unselect itself on the main thread -- That is the secret sauce, you have to perform this on the main thread with

[self performSelectorOnMainThread:@selector(deselectLineLH) withObject:nil waitUntilDone:YES];

deselectLineLH is a little snippit that basically has the NSTableVIew unselect itself so it never renders any updates. That little bit of magic was all it (finally) took. It's really kind of wild that you can do this kind of stuff and it works, cocoa+objc is so cool sometimes.


-John


Comments

Next Page -->