Hi,
I've been having problems with FreeApp() and CreateApp() in RapaGUI so narrowed it down to the minimum code to ask for help. The following code works fine on AROS but freezes the app after 1 to 10 button presses on OS3.9 under WinUAE. Can anyone verify the issue? The code after this is the same but converted to MUIRoyale. That works fine on both AROS and OS3.9. What's going on? Thanks for the help.
RapaGUI code ##############################################################################
@DISPLAY 1, {Hidden=True}
@APPIDENTIFIER "1.2.3.4"
@REQUIRE "rapagui"
mode=True
Function p_CreateGUI()
moai.FreeApp()
If mode
moai.CreateApp([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
<window id="wi_main" title="GUI 1" notify="CloseRequest" open="1">
<vgroup>
<text>This is long text so that we can see the name of the window.</text>
<button id="bt_gui" notify="pressed">Switch to 2</button>
</vgroup>
</window>
</application>
]])
Else
moai.CreateApp([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app">
<window id="wi_main1" title="GUI 2" notify="CloseRequest" open="1">
<vgroup>
<text>This is long text so that we can see the name of the window.</text>
<button id="bt_gui" notify="pressed">Switch to 1</button>
</vgroup>
</window>
</application>
]])
EndIf
EndFunction
Function p_EventFunc(msg)
Switch msg.Action
Case "RapaGUI":
Switch msg.Class
Case "Window":
End()
Case "Button":
Switch msg.id
Case "bt_gui":
mode=Not mode
p_CreateGUI()
EndSwitch
EndSwitch
EndSwitch
EndFunction
Same code but in MUIRoyale ##################################################################
@DISPLAY 1, {Hidden=True}
@REQUIRE "muiroyale"
mode=True
Function p_CreateGUI()
mui.FreeGUI()
If mode
mui.CreateGUI([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app" base="TEST">
<window id="wi_main" title="GUI 1" muiid="MAIN" notify="CloseRequest" open="1">
<vgroup>
<text>This is long text so that we can see the name of the window.</text>
<button id="bt_gui" notify="pressed">Switch to 2</button>
</vgroup>
</window>
</application>
]])
Else
mui.CreateGUI([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application id="app" base="TEST">
<window id="wi_main" title="GUI 2" muiid="MAIN" notify="CloseRequest" open="1">
<vgroup>
<text>This is long text so that we can see the name of the window.</text>
<button id="bt_gui" notify="pressed">Switch to 1</button>
</vgroup>
</window>
</application>
]])
EndIf
EndFunction
Function p_EventFunc(msg)
Switch msg.Action
Case "MUIRoyale":
Switch msg.Class
Case "Window":
End()
Case "Button":
Switch msg.id
Case "bt_gui":
mode=Not mode
p_CreateGUI()
EndSwitch
EndSwitch
EndSwitch
EndFunction
p_CreateGUI()
InstallEventHandler({MUIRoyale=p_EventFunc})
Repeat
WaitEvent
Forever
p_CreateGUI()
InstallEventHandler({RapaGUI=p_EventFunc})
Repeat
WaitEvent
Forever
NathanH wrote: ↑Wed Mar 01, 2023 8:39 pm
Hi,
I've been having problems with FreeApp() and CreateApp() in RapaGUI so narrowed it down to the minimum code to ask for help. The following code works fine on AROS but freezes the app after 1 to 10 button presses on OS3.9 under WinUAE. Can anyone verify the issue? The code after this is the same but converted to MUIRoyale. That works fine on both AROS and OS3.9. What's going on? Thanks for the help.
What you're doing here is a very bad idea: You're trying to free the app while it is still running. You should not free and re-create the app several times. Apps should be created at startup and freed before program termination. Trying to free the app while it still has windows open and everything is asking for trouble...
Btw, please embed code samples in [ code ]...[ /code ] sections for better readability. I've fixed that for now.
tags.
The instructions for moai.FreeApp() state:
"Use this call to delete the entire application object created using the last call to moai.CreateApp(). moai.FreeApp() will delete the whole application object and all of the children attached to it. After this call returns, you could create a new application using the moai.CreateApp() function if you want. Note that moai.FreeApp() won't free MOAI objects which are currently in a detached state. Those have to be freed by using moai.FreeObject()."
Perhaps that should be updated to reflect what you just mentioned. Thanks.
NathanH
Hi,
Whoops, it didn't like my reference to that tag. I took seriously in the instructions about not creating all objects at the beginning. I wrote a wizard in MUIRoyale which worked perfectly using mui.FreeGUI. I was trying to convert to RapaGUI to work on Windows when I ran into the problem. I'll have to rewrite with CreateObject and FreeObject I guess to minimize memory windows usage.
BTW, don't you ever sleep? How can you do everything you do and still answer clueless questions like mine? I do appreciate your efforts, however. They're very helpful.
The instructions for moai.FreeApp() state:
"Use this call to delete the entire application object created using the last call to moai.CreateApp(). moai.FreeApp() will delete the whole application object and all of the children attached to it. After this call returns, you could create a new application using the moai.CreateApp() function if you want. Note that moai.FreeApp() won't free MOAI objects which are currently in a detached state. Those have to be freed by using moai.FreeObject()."
Perhaps that should be updated to reflect what you just mentioned. Thanks.
NathanH wrote: ↑Sat Mar 04, 2023 5:51 pm
Perhaps that should be updated to reflect what you just mentioned. Thanks.
True. Theoretically freeing and re-creating the app should work, which is why the documentation mentions it but practically it's all rather untested because I don't see why anyone would want to do that. Normally, apps should be created and freed just once.