Dialogs example throws error on MorphOS

Discuss GUI programming with the RapaGUI plugin here
Post Reply
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Dialogs example throws error on MorphOS

Post by mrupp »

When running the "Dialogs" example on MorphOS and activating MorphOS' debug log (Debug.sbar), it will output the following error when clicking "Cancel" in the "Add customer" dialog:

Code: Select all

Notify_DISPOSE                : ################################################################
Notify_DISPOSE                : MAJOR BUG: object dispose from it's own OM_SET method,
Notify_DISPOSE                : probably in an illegal notification. NOT freeing memory!
Notify_DISPOSE                : obj=0x2665bb28(0x26049f1c_Text.mui)Cancel
Same with the "OK" button:

Code: Select all

Notify_DISPOSE                : ################################################################
Notify_DISPOSE                : MAJOR BUG: object dispose from it's own OM_SET method,
Notify_DISPOSE                : probably in an illegal notification. NOT freeing memory!
Notify_DISPOSE                : obj=0x26659150(0x26049f1c_Text.mui)OK
I investigated some further and found out that the reason is the calling of "p_CloseDialog()" (which invokes the "Dialog.EndModal" method) directly from the "p_EventFunc(msg)" function.
Replacing "p_CloseDialog" with "RunCallback(p_CloseDialog)" on line 257 and 268 solves the issue. Not sure if this is a MorphOS-MUI-only issue or if this is something that MUI doesn't like on other platforms, either.

I would suggest to adjust the "Dialogs" example accordingly for the next RapaGUI release and to mention in the RapaGUI docs on the "Dialog.EndModal" page, that this method mustn't be called directly from the event handler but to use RunCallback() instead.

Cheers, Michael
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Dialogs example throws error on MorphOS

Post by airsoftsoftwair »

True, that's a bug. The cause is that MUI doesn't permit freeing objects from their own event handler but that's what's happening here. The button is pressed, Dialog.EndModal() is called, causing the dialog (and the button) to be destroyed. I need to fix this in the MUI backend so that the dialog is just marked for deletion on Dialog.EndModal() and freed when the event handler has been left. Until then, using RunCallback() is a safe workaround for the problem but it's only necessary with MUI.
User avatar
mrupp
Posts: 147
Joined: Sun Jan 31, 2021 7:44 pm
Location: Switzerland
Contact:

Re: Dialogs example throws error on MorphOS

Post by mrupp »

airsoftsoftwair wrote: Fri Aug 13, 2021 9:35 pm True, that's a bug. The cause is that MUI doesn't permit freeing objects from their own event handler but that's what's happening here. The button is pressed, Dialog.EndModal() is called, causing the dialog (and the button) to be destroyed. I need to fix this in the MUI backend so that the dialog is just marked for deletion on Dialog.EndModal() and freed when the event handler has been left. Until then, using RunCallback() is a safe workaround for the problem but it's only necessary with MUI.
Excellent, and thanks for the additional background info.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Dialogs example throws error on MorphOS

Post by airsoftsoftwair »

Code: Select all

- Fix [Amiga]: Dialog.EndModal() led to a memory leak when called from the event handler of one of the dialog's children, e.g. a button
Post Reply