Page 1 of 1

Multiple float dialogs

Posted: Sun Jun 09, 2024 11:02 pm
by MehdiZangenehBar
When I click on dialog with label "1" , all other dialogs will be closed, how we can prevent this?

Code: Select all

ScriptName = 'Test_Script'

Test_Script = {}

function Test_Script:OnMouseDown(moho, mouseEvent)
end

function Test_Script:DoLayout(moho, layout)
	for i = 1 , 5 do
		local simple_dialog = LM.GUI.SimpleDialog(tostring(i), {})
		simple_dialog:GetLayout():AddChild(LM.GUI.Button('Button'))
		simple_dialog:DoModeless()
	end
end

Re: Multiple float dialogs

Posted: Mon Jun 10, 2024 12:47 am
by synthsin75
You shouldn't be using doLayout to make modeless dialogs. You can use a button in the tool options (doLayout) instead.

Re: Multiple float dialogs

Posted: Mon Jun 10, 2024 10:29 am
by MehdiZangenehBar
synthsin75 wrote: Mon Jun 10, 2024 12:47 am You shouldn't be using doLayout to make modeless dialogs. You can use a button in the tool options (doLayout) instead.
Well, your answer will not explain the problem, I have to create dialogs using script not any button.

Re: Multiple float dialogs

Posted: Mon Jun 10, 2024 10:58 am
by MehdiZangenehBar
funny is that if I close any dialog, it will close next created dialogs.
1 will close 1 .. 5
2 will close 2 .. 5
3 will close 3 .. 5
4 will close 4 .. 5
5 will close 5

Re: Multiple float dialogs

Posted: Mon Jun 10, 2024 11:39 pm
by synthsin75
If you invoke modeless dialogs from DoLayout, you're asking for instability and crashes. That instance of DoLayout ceases to exist once the tool is changed or entering/leaving frame zero, leaving those dialogs orphaned.
You'd better off using the Run function of a button script to invoke them. But you're welcome to keep testing and prove this for yourself.

Re: Multiple float dialogs

Posted: Tue Jun 11, 2024 1:01 am
by MehdiZangenehBar
In my case that's exactly what I want, close ALL created float dialogs and reopen them on DoLayout. Please take a look at this example:

Code: Select all

ScriptName = 'Test_Script'

Test_Script = {}

Test_Script.first_float_dialog = nil

function Test_Script:OnMouseDown(moho, mouseEvent)
end

function Test_Script:DoLayout(moho, simple_dialog_layout)
	if Test_Script.first_float_dialog ~= nil then
		Test_Script.first_float_dialog.image_text_list:SetSelItem(true)
		Test_Script.first_float_dialog = nil
	end
	for i = 1 , 5 do
		local simple_dialog = LM.GUI.SimpleDialog(tostring(i), {})
		local simple_dialog_layout = simple_dialog:GetLayout()
		simple_dialog.image_text_list = LM.GUI.ImageTextList(100, 100, LM.GUI.MSG_OK)
		simple_dialog_layout:AddChild(simple_dialog.image_text_list)
		simple_dialog:DoModeless()
		if Test_Script.first_float_dialog == nil then Test_Script.first_float_dialog = simple_dialog end
	end
end
This code works perfect, but the crash will accure if we close one of the float dialogs by hitting the X button.
I will consider your advice and caution about the DoLayout, but really there is not ANY functionality to handle this? maybe try catch? or any other tip or trick to prevent the crash?

Re: Multiple float dialogs

Posted: Tue Jun 11, 2024 1:15 am
by MehdiZangenehBar
I just tested with pcall, it seems it will not crash, would you please check this out on your system:

Code: Select all

ScriptName = 'Test_Script'

Test_Script = {}

Test_Script.first_float_dialog = nil

function Test_Script:OnMouseDown(moho, mouseEvent)
end

function Test_Script:DoLayout(moho, simple_dialog_layout)
	if Test_Script.first_float_dialog ~= nil then
		pcall
		(
			function ()
				Test_Script.first_float_dialog.image_text_list:SetSelItem(Test_Script.first_float_dialog.image_text_list:GetItem(0), false)
			end
		)
		Test_Script.first_float_dialog = nil
	end
	for i = 1 , 5 do
		local simple_dialog = LM.GUI.SimpleDialog(tostring(i), {})
		local simple_dialog_layout = simple_dialog:GetLayout()
		simple_dialog.image_text_list = LM.GUI.ImageTextList(100, 100, LM.GUI.MSG_CANCEL)
		simple_dialog.image_text_list:AddItem("", false)
		simple_dialog_layout:AddChild(simple_dialog.image_text_list, LM.GUI.ALIGN_LEFT, 0)
		simple_dialog:DoModeless()
		if Test_Script.first_float_dialog == nil then Test_Script.first_float_dialog = simple_dialog end
	end
end

Re: Multiple float dialogs

Posted: Tue Jun 11, 2024 1:33 am
by MehdiZangenehBar
OK, you right!
it will crash randomly...
I should change my method to the button.
Thanks for your explantion.