Scripting bug

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
synthsin75
Posts: 9981
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Scripting bug

Post by synthsin75 »

I've found at least one circumstance where creating a new layer followed by opening a dialog, both by the same tool, causes a hard crash.
This happens when creating any layer type except for vector.

Code: Select all

-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "Syn_TestDialog"

-- **************************************************
-- General information about this script
-- **************************************************

Syn_TestDialog = {}

Syn_TestDialog.BASE_STR = 2355

function Syn_TestDialog:Name()
	return "Test Dialog"
end

function Syn_TestDialog:Version()
	return "1.0"
end

function Syn_TestDialog:Description()
	return "Test Dialog"
end

function Syn_TestDialog:Creator()
	return "(c)2022 J.Wesley Fowler (synthsin75)"
end

function Syn_TestDialog:UILabel()
	return "SYN: Test Dialog"
end

-- **************************************************
-- The guts of this script
-- **************************************************

function Syn_TestDialog:OnMouseDown(moho, mouseEvent)
end

-- **************************************************
-- Options dialog
-- **************************************************

local Syn_TestDialogDialog = {}

function Syn_TestDialogDialog:new(moho)
	local d = LM.GUI.SimpleDialog("", Syn_TestDialogDialog)
	local l = d:GetLayout()
	
	l:AddChild(LM.GUI.StaticText("Text", LM.GUI.ALIGN_Left))
		
	return d
end

function Syn_TestDialogDialog:UpdateWidgets()
	
end

function Syn_TestDialogDialog:HandleMessage(msg)
	
end

-- **************************************************
-- Tool options - create and respond to tool's UI
-- **************************************************

Syn_TestDialog.NEWLAYER = MOHO.MSG_BASE
Syn_TestDialog.DLOG_END = MOHO.MSG_BASE + 1

function Syn_TestDialog:DoLayout(moho, layout)
	self.dlog = Syn_TestDialogDialog:new(moho)
	
	self.opt = LM.GUI.PopupDialog("Options", false, self.DLOG_END)
	self.opt:SetDialog(self.dlog)
	
	layout:AddChild(self.opt, LM.GUI.ALIGN_CENTER)
	
	self.newButton = LM.GUI.ShortButton("New layer", self.NEWLAYER)
	layout:AddChild(self.newButton)
end

function Syn_TestDialog:HandleMessage(moho, view, msg)
	if (msg == self.DLOG_END) then --update enabled/disabled camera tools
		local frame = moho.frame
		if (frame == 0) then
			moho:SetCurFrame(1)
		else
			moho:SetCurFrame(0)
		end
		moho:SetCurFrame(frame)
	elseif (msg == self.NEWLAYER) then
		moho.document:PrepUndo()
		moho.document:SetDirty()
		local layer = moho:CreateNewLayer(MOHO.LT_SWITCH, true)
		--local layer = moho:CreateNewLayer(MOHO.LT_VECTOR, true)
		--local layer = moho:CreateNewLayer(MOHO.LT_TEXT, true)
		--local layer = moho:CreateNewLayer(MOHO.LT_AUDIO, true)
		--local layer = moho:CreateNewLayer(MOHO.LT_IMAGE, true)
		--local layer = moho:CreateNewLayer(MOHO.LT_PARTICLE, true)
		--local layer = moho:CreateNewLayer(MOHO.LT_PATCH, true)
		--local layer = moho:CreateNewLayer(MOHO.LT_TEXT, true)
		--local layer = moho:CreateNewLayer(MOHO.LT_GROUP, true)
		--local layer = moho:CreateNewLayer(MOHO.LT_BONE, true)
		--local layer = moho:CreateNewLayer(MOHO.LT_3D, true)
		moho:UpdateUI()
	end
	MOHO.Redraw()
end
I seem to recall some other scripting bug with, at least, group type layers, but I'm not finding it now. Might be related.
I haven't been able to come up with a way around this.
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Scripting bug

Post by Rai López »

synthsin75 wrote: Sat Oct 29, 2022 11:36 am I seem to recall some other scripting bug with, at least, group type layers, but I'm not finding it now. Might be related.
Could you be referring to this one?: Moho crash when trying to place a layer out of a group by "PlaceLayerBehindAnother()"

It didn't seem like too related to me in principle, but the fact it happens with all kind of layers but Vector ones make me think it may, who knows...

Anyway, the problem here seems more related to using "SetCurFrame" from there right after the creation of one of those type of layers, isn't? In fact it'd say it couldn't be even related to layers creation but with which layer type is selected in palette at the time to open the dialog instead, or something like that. IOW, this also ends up in a crash to me:

  1. Make this change to the script:

    Code: Select all

    		--local layer = moho:CreateNewLayer(MOHO.LT_SWITCH, true)
    		local layer = moho:CreateNewLayer(MOHO.LT_VECTOR, true)
    
  2. Open a fresh instance of Moho.
  3. Press the "New layer" button of your tool one or several times and go opening the dialogue just to see how Moho, as you say, doesn't crash at all...
  4. Now simply create i.e. a Switch Layer by means of the Layer window's button.
  5. After that, create one more Vector layer by means of the tool's button
  6. Now, even thought the last created layer was Vector type, as soon as you try to open the dialogue, Moho also crashes here (although not 100% of the times, it may vary depending on if you've selected the Switch layer or not).

In any case, the more crashing scenarios of this type we can detect, the better for they can get it sorted (if finally related) at some point I guess... so it's always good to know.
...
User avatar
synthsin75
Posts: 9981
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Scripting bug

Post by synthsin75 »

That might have been the one I was thinking of, but hiding the switch layer doesn't help in this case.
Yeah, I did find the simpler case, of a dialog invoking SetCurFrame with a switch layer selected. This doesn't happen with a control directly on the tool options bar, only inside a dialog.

Too bad. I'd hoped to keep more room on the options bar.

Thanks for looking into it.
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Scripting bug

Post by Rai López »

Ahhh... So the purpose of switching frames there was to try to redraw the toolbar or dialogue itself? Yeah, the old issue with limited toolbar space... But anyway I think we already discussed all that somewhere and, if I remember well, there were situations where it wasn't possible anyway, so even though when it worked it was simply great, it really wasn't a 100 % functional solution. But it may depend in every case, of course! So just wanted to point out that, even without the crashes, it may or may not worth all the mess after all.
...
User avatar
synthsin75
Posts: 9981
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Scripting bug

Post by synthsin75 »

Yeah, redrawing the tool options bar. It's fine, a control on the bar itself, instead of in a dialog, works fine.
If we really need it in a dialog, we can use what I did in my switch icons tool, where hitting enter, in OnKeyDown, handles the frame change to update the tool's UI.

It's all a hack, but as long as things don't change too much between versions of Moho, it's reliable...at least since the last change.
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Scripting bug

Post by Rai López »

OK, thanks for the info, I always has wanted to test all that toolbar redrawing again, because at the time we had that discussion I was still too disconnected to scripting and I well may overlooking some aspects or possibilities...

But, although I can't recall which ones, at least I was not able to redraw the toolbar at will for all cases, no matter if performing 0 frame or current layer switching or whatever trick that passed through my mind. But if you say it's indeed possible to make it work always... well the more reason for wanting to start playing with all that again! Regarding dialogues, you are talking about make them redraw after closing and opening, isn't? I mean, not while opening and on the fly, because I know changes after reopening has always been possible and in that case I don't remember any limitation or problem (apart of the necessity of reopening, of course).
...
User avatar
synthsin75
Posts: 9981
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Scripting bug

Post by synthsin75 »

Ramón López wrote: Sun Oct 30, 2022 12:31 am But if you say it's indeed possible to make it work always... well the more reason for wanting to start playing with all that again!
As far as I've found, it's always possible...it's just a bit clunky...like saying "Hit <enter> twice to apply" in a dialog (once to dismiss the dialog and another for OnKeyDown to catch the key event).
Regarding dialogues, you are talking about make them redraw after closing and opening, isn't? I mean, not while opening and on the fly, because I know changes after reopening has always been possible and in that case I don't remember any limitation or problem (apart of the necessity of reopening, of course).
No, you always have to close and reopen a dialog to change it's content. I'm just talking about controls in a dialog to either change the options bar or another dialog.
In the current tool I'm working on, I just decided to have a small button on the options bar make the change (in this case, hiding some stock tools from the tool window). The button is too small to be self-explanatory, but in v11 or higher we have tooltips to explain controls. So it takes as little options space as possible.
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Scripting bug

Post by Rai López »

synthsin75 wrote: Sun Oct 30, 2022 12:57 am As far as I've found, it's always possible...it's just a bit clunky...like saying "Hit <enter> twice to apply" in a dialog (once to dismiss the dialog and another for OnKeyDown to catch the key event).
Ohhh... maybe that need of user interaction is what I tried to avoid and not being able to get it I just remembered that the redrawing tricks simply refused to work for all situations. I think I get it now, but I still may need to make some tests or maybe find and re-read all that thread at least... Well, thanks for taking the time of refreshing my memory!

synthsin75 wrote: Sun Oct 30, 2022 12:57 am I'm just talking about controls in a dialog to either change the options bar or another dialog.
Oh, then that may be new to me, I'll have to check... If I find the time I think I'll reinstall your Switch Icons tool (great script, BTW 😌) and try to refresh my memory that way too.

synthsin75 wrote: Sun Oct 30, 2022 12:57 am The button is too small to be self-explanatory, but in v11 or higher we have tooltips to explain controls. So it takes as little options space as possible.
Yeah, we have some little useful things to can save some UI space (and made it more attractive in the process) now, which is like a relieve... precisely today I discovered this one: Image :o

Well, thanks for taking the time of explaining all that!
...
User avatar
synthsin75
Posts: 9981
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Scripting bug

Post by synthsin75 »

Ramón López wrote: Sun Oct 30, 2022 2:11 am ... precisely today I discovered this one: Image :o
Is that a UTF8 magnifying glass in a TextControl? Nice idea.
Well, thanks for taking the time of explaining all that!
Let me know if you need me to isolate any examples for you.
User avatar
Rai López
Posts: 2243
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Scripting bug

Post by Rai López »

synthsin75 wrote: Sun Oct 30, 2022 2:34 am Is that a UTF8 magnifying glass in a TextControl? Nice idea.
Yes! I know it's long time known you could use emojis everywhere in Moho (and well, almost anywhere nowadays), but I didn't know TextControls allowed you to embed them like this, and even numerical ones can do it :o. And it has come in handy to precisely allow me to put things exactly as I wanted while saving some space at the same time, supercool! (Sometimes we're happy with so little :roll:).

synthsin75 wrote: Sun Oct 30, 2022 2:34 am Let me know if you need me to isolate any examples for you.
When I had to start dealing with all that for sure, thanks! Although my idea was more to stay centered in embedded scripts for now and see if tool scripting possibilities like these ones we're discussing here got some love at any point in the meantime... But who knows, we'll see!
...
Post Reply