Signal handler still connected after execution ends in Plugin Creator

• Oct 29, 2020 - 16:44
Reported version
3.x-dev
Type
Plugins
Frequency
Once
Severity
S4 - Minor
Reproducibility
Always
Status
active
Regression
No
Workaround
Yes
Project

When implementing the onScoreStateChanged signal handler, the signal handler remains connected after the plugin execution ends.
On subsequent runs, whenever the signal handler is called, all the old signal handlers are also called.

Demonstration code :

import QtQuick 2.2
import QtQuick.Controls 2.0
import MuseScore 3.0
 
MuseScore {
    version: "3.5"
    description: qsTr("onScoreStateChanged signal still connected")
    menuPath: "Plugins.State"
    pluginType: "dock"
 
 
    property int counter;
 
    onScoreStateChanged: {
        if (parent === null) {
            console.log("Old signal handler :", counter++);
        } else {
            console.log("Current signal handler :", counter++);
        }
    }
 
    onRun: {
        counter = 0;
    }
 
    Column {
        Text {
            text: "State"
        }
    }
}

Output after launching the plugin for the 3rd time and clicking in the score :


Debug: Old signal handler : 16
Debug: Old signal handler : 9
Debug: Current signal handler : 4

A workaround is to check if parent is null.
This bug doesn't seem to happen when the plugin is executed normally (outside the Plugin Creator)

OS: Debian GNU/Linux 10 (buster), Arch.: x86_64, MuseScore version (64-bit): 3.6.0.316888218, revision: 6b901e7


Comments