Plug-in code working differently when called directly and when run under Plugin Creator

• Aug 6, 2015 - 23:38
Priority
P2 - Medium
Type
Plugins
Frequency
Few
Severity
S3 - Major
Reproducibility
Always
Status
closed
Regression
No
Workaround
Yes
Project

While attempting to use in a dialogue plug-in of mines a combo box dynamically filled, I discovered that a procedure which works correctly if run from the Plugin Creator, no longer works if the plug-in is run directly.

Context: all versions from 2.0.0 to current github master code, run under Linux Mint 17.1.

Reference: some discussion at https://musescore.org/en/node/71081

Sample code: this is a minimal plug-in (of the dialogue type) which just displays a combo box and fills it with strings at run time (just some boring "Name 0", "Name 1", ... strings).

The combo box is correctly filled if the plug-in is run from the Plugin Creator, but remains empty if the plug-in is run directly from the "Plugins" menu.

Note that, in both cases, the dynamically created strings are correctly inserted in the ListModel attached to the ComboBox (as the few diagnostic logs at the end show), but this seems not to affect the combo box itself.

1) Anybody can confirm (or falsify) this under other platforms?

2) Can anybody explain the difference?

Thanks!

import QtQuick 2.0
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
import MuseScore 1.0

MuseScore
{
version:	"2.0"
description:	qsTr("To test ComboBox working")
menuPath:	"Plugins.Test Combo"
pluginType:	"dialog"

//
//	The UI
//

id:	window
property	int	wdgMargin:	8
property	int	wndWidth:	300
property	int	wndHeight:	200
width:		wndWidth;
height:		wndHeight;

RowLayout
{
	id:			rowSelect
	anchors.top:		window.top
	anchors.left:		window.left
	anchors.right:		window.right
	anchors.margins:	window.wdgMargin
	spacing:		window.wdgMargin
	Label
	{
		id:			label
		text:			qsTr("Combo:")
		Layout.alignment:	Qt.AlignVCenter
	}
	ComboBox
	{
		id:			combo
		Layout.fillWidth:	true
		model: ListModel
		{
			id: listModel
		}
	}
}

//
// Components and Methods
//

onRun:		{ init(); }

//-------------------------------------------------------------------
//	init()
//	initializes the combo box. Called by main object's onRun().
//-------------------------------------------------------------------

function init()
{
	var	i;
	var	names	= [];

	// fill the combo box
//	combo.textRole = "text";			// does anything at all?
	for (i = 0; i < 5; i++)
		names[i] = { "text": "Name " + i };
	listModel.append(names);
// some diagnostics
console.log("Combo text role: " + combo.textRole);
console.log("Num. of names in list model: " + listModel.count);
var model = combo.model;
console.log("Model: " + model);
for (i = 0; i < combo.count; i++)
	console.log("Name " + i + ": " + model.get(i).text);
}

}		// plugin end


Comments

I can't tell you the cause, but this behavior is something I have already seen.
That's why I pushed this commit: c6ad7f596
where I substituted the onRun with onCompleted. It seemed that the component was shown before it was updated with the relevant changes. Probably by comparing the differences in the code between mscorePlugins.cpp and pluginCreator.cpp we could understand why in one case it is updating and not in the other one.
Actually, when I proposed the PR, I didn't check the behavior inside pluginCreator.
Maybe the instruction view->raise();?

EDIT: No, the raise instruction didn't change anything in my build (Windows 8.1)

Frequency Once
Priority P3 - Low
Regression No
Reproducibility Always
Workaround No

Confirmed for 3.0. I am assigning it a low priority since I am not sure how many people are really affected, in case there are more requests the priority may be raised.

I'm seeing this, too, running OS: macOS Sierra (10.12), Arch.: x86_64, MuseScore version (64-bit): 3.2.0.22758, revision: 8594c8c. Code is attached. Output to panel happens when running via the Creator, but doesn't happen when running the plugin from the plugins folder.

The attached code is an excerpt from a larger plugin which gets musicxml for a score, ships it to a server, where we evaluate it, then respond via the Panel with the results of the evaluation. In the larger script, everything except for output to the panel works the same whether I'm running the code from the Creator or as an installed plugin. However, since I can't push text to the panel when I'm running as an installed plugin, there's no way to get the results of the evaluation back to the user.

Attachment Size
demo_bug.qml 889 bytes
Frequency Once Few
Priority P3 - Low P2 - Medium
Severity S4 - Minor S3 - Major
Workaround No Yes

Came up on a forum: https://musescore.org/en/node/292664, was also reported in #97316: Investigate differences between plugins ran from the Creator and the Menu.

The bug got introduced in this commit which caused an extra plugin instance be created and actually shown by view-&gt;setSource(QUrl::fromLocalFile(pp)); line while run() signal still keeps being emitted in the plugin instance created by Component::create() call. This effectively causes dialog and dock plugins be unable to execute onRun on plugin startup in a correct plugin instance so its severity doesn't look quite minor for the plugins environment.

As pointed out by ABL, using Component.onCompleted instead of onRun may indeed be used as workaround.

There are several ways to correct the issue so I'll push a fix a bit later.

Fix version
3.3.0