Script works differently on different computers?!

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

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

Post Reply
User avatar
Lukas
Posts: 789
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Script works differently on different computers?!

Post by Lukas » Wed Nov 14, 2018 11:05 am

Is there something I should know about regarding these two lines of code I'm using?

Line for disabling the 'Paths' checkbox under 'Display quality':

Code: Select all

view:SetQualityFlags(MOHO.clearbit(view:QualityFlags(), MOHO.LDQ_WIREFRAME))
Line for enabling the 'Paths' checkbox under 'Display quality':

Code: Select all

view:SetQualityFlags(MOHO.setbit(view:QualityFlags(), MOHO.LDQ_WIREFRAME))
When I run them on my own computers (both on a Windows 10 machine and on a Macbook Pro running OS X Mojave), they don't always work. (I'm running the code when I press a toolbar button, which always works on all computers, and I'm running the code when I enter and exit frame 0, which used to work in the past (not sure what changed, maybe it was 12.4 or some Windows update, but not anymore)

But here comes the weirdest part, when I'm using my tool on another Windows computer, it works fine when leaving and exiting frame 0. They are both using the exact same Custom Content Folder. Tested it with the same project files too.

Is there something in MOHO.clearbit/setbit that I don't understand that can behave different on different machines in different situations?
User avatar
synthsin75
Posts: 7156
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Script works differently on different computers?!

Post by synthsin75 » Wed Nov 14, 2018 5:31 pm

Lukas wrote:Is there something I should know about regarding these two lines of code I'm using?

Line for disabling the 'Paths' checkbox under 'Display quality':

Code: Select all

view:SetQualityFlags(MOHO.clearbit(view:QualityFlags(), MOHO.LDQ_WIREFRAME))
Line for enabling the 'Paths' checkbox under 'Display quality':

Code: Select all

view:SetQualityFlags(MOHO.setbit(view:QualityFlags(), MOHO.LDQ_WIREFRAME))
When I run them on my own computers (both on a Windows 10 machine and on a Macbook Pro running OS X Mojave), they don't always work. (I'm running the code when I press a toolbar button, which always works on all computers, and I'm running the code when I enter and exit frame 0, which used to work in the past (not sure what changed, maybe it was 12.4 or some Windows update, but not anymore)

But here comes the weirdest part, when I'm using my tool on another Windows computer, it works fine when leaving and exiting frame 0. They are both using the exact same Custom Content Folder. Tested it with the same project files too.

Is there something in MOHO.clearbit/setbit that I don't understand that can behave different on different machines in different situations?
I assume that you'd need to provide MOHO.LDQ_WIREFRAME to MOHO.clearbit/MOHO.setbit as a MOHO.bit:

view:SetQualityFlags(MOHO.clearbit(view:QualityFlags(), MOHO.bit(MOHO.LDQ_WIREFRAME)))

And then depending on how you are running it when entering/exiting frame zero, it may be running more than once. So if you're doing a check, like this...

Code: Select all

	if (MOHO.hasbit(view:QualityFlags(), MOHO.bit(MOHO.LDQ_WIREFRAME))) then
		view:SetQualityFlags(MOHO.clearbit(view:QualityFlags(), MOHO.bit(MOHO.LDQ_WIREFRAME)))
	else
		view:SetQualityFlags(MOHO.setbit(view:QualityFlags(), MOHO.bit(MOHO.LDQ_WIREFRAME)))
	end
...it may be working, but being run a different number of times (odd or even) on different systems. You might need to make sure the code only runs once.




If all else fails, there's also doing it brute force, instead of bitwise:

Code: Select all

	local flags = {4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2}
	local qual = moho.view:QualityFlags()
	local tempQual = qual
	for i,v in ipairs(flags) do
		if (tempQual >= v) then
			tempQual = tempQual-v
		end
		if (tempQual == 2) then
			moho.view:SetQualityFlags(qual-2)
			break
		end
		if (i == #flags) and (tempQual ~= 2) then
			moho.view:SetQualityFlags(qual+2)
			break
		end
	end
hayasidist
Posts: 2143
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Script works differently on different computers?!

Post by hayasidist » Thu Nov 15, 2018 11:27 am

a bit off topic but … I can't find any write-up of the various MOHO.###bit functions -- any pointers???
User avatar
Lukas
Posts: 789
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Script works differently on different computers?!

Post by Lukas » Thu Nov 15, 2018 1:29 pm

Thanks Wes! That stuff goes way over my head. I've tried your brute force variant of the code and the results are the same. It works fine on my colleague's Windows 10 machine, but not on mine.

Here is the code:
http://www.lukaskrepel.nl/temp/ASP/LK_Test.lua (With the tool being active, move in and out of frame 0, the paths checkbox should be true on frame 0, and false on all other frames)
http://www.lukaskrepel.nl/temp/ASP/Debug.lua (I use this as a menu script and use "Debug:Log()" instead of "print" for debugging purposes, feel free to use it)

@hayasidist, I wish I knew where to point...
hayasidist
Posts: 2143
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Script works differently on different computers?!

Post by hayasidist » Thu Nov 15, 2018 2:21 pm

dumb question time .. 32 or 64 bit systems??
User avatar
Lukas
Posts: 789
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Script works differently on different computers?!

Post by Lukas » Thu Nov 15, 2018 2:28 pm

All are 64 bit systems running the 64 bit version of Moho :)
User avatar
synthsin75
Posts: 7156
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Script works differently on different computers?!

Post by synthsin75 » Thu Nov 15, 2018 5:44 pm

hayasidist wrote:a bit off topic but … I can't find any write-up of the various MOHO.###bit functions -- any pointers???
Check the lm_utilities. He made global functions to duplicate iterating bits in Lua, found here: http://lua-users.org/wiki/BitwiseOperators
User avatar
synthsin75
Posts: 7156
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Script works differently on different computers?!

Post by synthsin75 » Thu Nov 15, 2018 7:22 pm

Lukas wrote:Thanks Wes! That stuff goes way over my head. I've tried your brute force variant of the code and the results are the same. It works fine on my colleague's Windows 10 machine, but not on mine.

Here is the code:
http://www.lukaskrepel.nl/temp/ASP/LK_Test.lua (With the tool being active, move in and out of frame 0, the paths checkbox should be true on frame 0, and false on all other frames)
http://www.lukaskrepel.nl/temp/ASP/Debug.lua (I use this as a menu script and use "Debug:Log()" instead of "print" for debugging purposes, feel free to use it)
I was wrong about needing MOHO.bit. Just MOHO.LDQ_WIREFRAME is right, as that's all that works when changing other display settings.

Okay, it wasn't working on my computer either, but I found the problem. It should work for you if you disable GPU acceleration in the preferences (not just in the display settings). But this is only a problem with the code in a DrawMe function. If you move it to an OnMouse function, it should work with GPU enabled.

This could be a limitation with DrawMe and GPU (or it might be a bug), but we could really use scripting access to turning GPU on and off.
User avatar
Lukas
Posts: 789
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Script works differently on different computers?!

Post by Lukas » Thu Nov 15, 2018 8:27 pm

Oh cool. I'm currently at home on my Macbook, on which it's impossible to disable GPU in the preferences... But I'll check it out tomorrow at work. It sounds promising.
hayasidist
Posts: 2143
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Script works differently on different computers?!

Post by hayasidist » Thu Nov 15, 2018 9:44 pm

synthsin75 wrote:
hayasidist wrote:a bit off topic but … I can't find any write-up of the various MOHO.###bit functions -- any pointers???
Check the lm_utilities. He made global functions to duplicate iterating bits in Lua, found here: http://lua-users.org/wiki/BitwiseOperators
Thanks Wes.
synthsin75 wrote:This could be a limitation with DrawMe and GPU (or it might be a bug)...
hmm -- are you saying that DrawMe isn't being invoked properly / at all if GPU is enabled???
User avatar
synthsin75
Posts: 7156
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Script works differently on different computers?!

Post by synthsin75 » Fri Nov 16, 2018 4:42 am

hayasidist wrote:
synthsin75 wrote:This could be a limitation with DrawMe and GPU (or it might be a bug)...
hmm -- are you saying that DrawMe isn't being invoked properly / at all if GPU is enabled???
No, DrawMe is definitely being invoked, but no display setting changes take effect with the GPU pref enabled. They change just fine from OnMouse and Run functions, or GPU disabled in the preferences. The thing is that this shows it's working internally:

Code: Select all

print(tostring(MOHO.hasbit(view:QualityFlags(), MOHO.LDQ_WIREFRAME)))
If I add moho:UpdateUI() to DrawMe it works (even with GPU enabled), but it causes the workspace display to be unusable, and when I enable the GPU display quality, it shows the "Show curves" checkbox changing but just flickers the workspace and doesn't actually change the display setting in the menu.


If changing the display settings from a tool, I'd suggest just enabling NonDragMouseMove and placing it in OnMouseMoved.
hayasidist
Posts: 2143
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Script works differently on different computers?!

Post by hayasidist » Fri Nov 16, 2018 8:29 am

thanks for the explanation. sounds like a bug to me....
User avatar
Lukas
Posts: 789
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Script works differently on different computers?!

Post by Lukas » Fri Nov 16, 2018 11:05 am

Aaahhh, so that's why it was only working when triggering it trough a toolbar button (so HandleMessage would call it). Happy to have this mystery solved. I'll keep the GPU off for now. Weird bug.
Post Reply