Cancel plugin onScoreStateChanged function

• Jun 5, 2024 - 20:14

In MS3, once this function is defined it continues to run even when the plugin is closed. I checked this by using a global property var initialsed to 0 and then incrementing each time the function executes, outputting the value to console.log.

After starting and stopping the plugin 4 times and checking the debug log, there were 4 separate instances of the global variable!

How do I cancel onScoreStateChanged on closing the plugin?


Comments

In reply to by yonah_ag

Also, please note that in the link onScoreStateChanged Handler
(https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…)
It warns:
If a plugin modifies score in this handler, then it should:
1. enclose all modifications within Score::startCmd() / Score::endCmd()
2. take care of preventing an infinite recursion, as plugin-originated changes will trigger this signal again after calling Score::endCmd()

In javascript documentation I see removeEventListener(), but not implemented here apparently.
I suspected that the slowing down of the plugin (looks good by the way) might be due to a memory leak, but I see no evidence of that.

After ‘horsing around’ with the plugin (clicking everything like a madman) I got a

cmd('select-all') not valid in current state

and a map timing of 55 sec! but I cannot reproduce

In reply to by elsewhere

I do now wrap score mods, (adding debug code letters), and have a flag for recursion but I didn't realise the need until about update 0.6 when I noticed it in a different plugin, (by BSG).

I think that in normal use the plugin will work OK but I might report this on GitHub in case Jojo can add the removeEventListener to 3.7.0.

Do you still have an unanswered question? Please log in first to post your question.