Igevorse Otonnoleare

Bugs & magic with cross-thread function calls

13 July 2014 | 10:15 pm

Overview of work this week

In short:

  • I was fixing bugs.

Yes, it is very simple. I just fixed bugs.

I found these bugs (8-12) while working on JACK Transport.

I did not work with count in or tempo slider in play panel, but I've implemented JACK reposition, and these features used my new code.

But I spent a lot of time on the second-to-last bug (11 on the "Bugs" page). It seems like very simple: I was getting a crash when I press "Play" on JACK Transport and there is time 0:00. I've checked all my code that implements reposition from JACK Transport and found the cause: uninitialized iterator Seq::guiPos. MuseScore crashes when was touching it in HeartBeatTimeout() - this function updates the cursor on the screen.

This iterator is initialized explicitly in seek() and we calling seek() when start playing. So, what's the problem? The problem was - I think you already got it - in my implementation. Seq::start() does not always call seek() because of some conditions I wrote. The solution is quite simple: I should change or roll back conditions. But in this case I will get JACK Transport reposition non-working.

Finally, I got it to work, but caught an another bug, very strange one. That's where the magic begins. In some cases MuseScore crashed with different errors about memory management, sometimes canvas didn't repaint. Actually, I spent most of the time on fixing these two bugs.

When I realized that I was stuck I wrote to my mentor and he gave me an idea: I did not use seek() function correctly. Really, I didn't think about threads a lot and used seek() wherever I wanted. Seek() calls functions that should be called only from GUI thread, but I called seek() from realtime thread.

So, the solution is splitting seek() into two functions: the first should be called from the GUI thread, and the second - from the realtime thread. Now we have seek() and seekRT().

After fixing the last bug I've checked all new features again and made a pull request.

Key tasks that stalled

Cross-thread function calls. I wrote above.

Upcoming tasks this week

Implement "Assigning channels to staves" feature I described in first posts.

Hot switching drivers is partially working, so there is no need to hurry up with it.

As usual, you can find me on IRC #musescore as igevorse.

Feel free to write me about implementing some JACK-related features that you need and want.

« New UI: improved usability · Bugs & magic with cross-thread function calls · Assigning channels to instruments:… »

Leave your response!

Style `onWall HashCode` by Lited & Sayori
Get your own blog immediately for free with Lited!