Without this an exception in DelayedMouseMove::commitMouseMove() could
produce (e.g.) the crash in #3818. This same error handling was
already done for Editor::onProcessMessage() in
DocView::onProcessMessage() to avoid crashing due unhandled exceptions
in Editor message processing.
Regression introduced with 8722c8ec16
and d3562b140c.
Our re-entrant RWLock implementation is tricky because it doesn't
support to unlock in different order than it was locked.
E.g. If we create a DocWriter (e.g. paste command), and try to create
a DocReader (e.g. PixelsMovement) inside the DocWriter scope, the
reader will return a LockResult::Reentrant, but if we unlock the
write, then the reader cannot be used to upgradeToWrite() because the
lock will have just 0 locks (the re-entrant one didn't modify the
count of the RWLock). This is because it was thought that the
DocReader was going to be unlocked before the writer lock (in the
exact inverse order).
Basically these re-entrant RWLocks will not work fine if we mix up the
order of locks/unlocks in the same thread.
With re-entrant RWLocks we can try to lock the document on each
transaction/command/modification. This fixes several problems running
scripts that weren't locking the sprite in an app.transaction() call.
This already fixes a lot of possible problems that can happen when a
script is running and modifying some part of a sprite that is being
backed up in a background thread.
We still need some work to being able to lock a sprite two or more
times in the same thread to write it. E.g. an app.transaction() should
lock the sprite for write access, but the script transaction function
could call a command, and that command could use a ContextWriter to
lock the sprite again. At the moment this is not possible because we
need a re-entrant RWLock implementation.