Event queue for a freed display

Report any Hollywood bugs here
Post Reply
User avatar
jPV
Posts: 675
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Event queue for a freed display

Post by jPV »

I noticed some stability issues with a certain program after compiling it with a newer Hollywood version, and finally had some time to hunt the issue down. It looks that if there are input events for a display, which is freed before the events are handled, it causes different kinds of symptoms.

The issue occurs when you get on the WaitEvent or CheckEvent(s) command in a script after freeing a display with events in queue. On MorphOS the usual error is "Function ??() not found!", which seems to make a clean exit, but on OS4 the whole program crashes in a nasty way making a Guru Mediation error popping up in a Grim Reaper window.

This didn't happen with Hollywood 8.0, but happens with 9.0 or later. I guess it's related to new event handling code in Hollywood.

BTW. is there a way to clear the event queue somehow, without running callback functions? I didn't succeed with BreakEventHandler etc...

Code: Select all

Function p_Input(msg)
    Switch msg.action
    Case "OnKeyUp":
        Switch msg.key
        Case "f":
            p_Fullscreen()
        EndSwitch
    EndSwitch
EndFunction

Function p_Fullscreen()
    fs = 1 - fs
    If fs
        CreateDisplay(2, {Mode="Fullscreen", Width=#NATIVE, Height=#NATIVE, Borderless=True, HidePointer=True})
        OpenDisplay(2)
        ActivateDisplay(2)
        InstallEventHandler({OnKeyUp = p_Input})

        Print("Press the f key at least twice within 2 seconds when this display opens.")

        ; To simulate that something time consuming is done after opening the display.
        ; You may get several input events in the queue before the function returns.
        Wait(100)

    Else
        SelectDisplay(1, True)
        FreeDisplay(2)
        ; Events for the freed display are left in the queue and causing an issue?
        ; The WaitEvent line exits with the error "40: Function ??() not found!" on MorphOS,
        ; and just crashes on OS4 (Grim Reaper/Guru Mediation/DSI error).
        ; This doesn't happen with Hollywood 8.0, but happens since 9.0 (new event handler code?)
    EndIf
EndFunction

InstallEventHandler({OnKeyUp = p_Input})

Print("Press the f key for fullscreen.")

Repeat
    WaitEvent
Forever
User avatar
airsoftsoftwair
Posts: 5626
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Event queue for a freed display

Post by airsoftsoftwair »

jPV wrote: Thu Aug 24, 2023 2:17 pm I noticed some stability issues with a certain program after compiling it with a newer Hollywood version, and finally had some time to hunt the issue down. It looks that if there are input events for a display, which is freed before the events are handled, it causes different kinds of symptoms.

The issue occurs when you get on the WaitEvent or CheckEvent(s) command in a script after freeing a display with events in queue. On MorphOS the usual error is "Function ??() not found!", which seems to make a clean exit, but on OS4 the whole program crashes in a nasty way making a Guru Mediation error popping up in a Grim Reaper window.
Yeah, clearly a bug. Will fix this. Thanks for reporting!
jPV wrote: Thu Aug 24, 2023 2:17 pm BTW. is there a way to clear the event queue somehow, without running callback functions? I didn't succeed with BreakEventHandler etc...
Yes, since Hollywood 2.0 there is a FreeEventCache() function which will wipe all events from the queue. For some reason it's still undocumented and marked as internal but I think it should do what you want :)
User avatar
jPV
Posts: 675
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Event queue for a freed display

Post by jPV »

airsoftsoftwair wrote: Mon Aug 28, 2023 10:48 pm
jPV wrote: Thu Aug 24, 2023 2:17 pm BTW. is there a way to clear the event queue somehow, without running callback functions? I didn't succeed with BreakEventHandler etc...
Yes, since Hollywood 2.0 there is a FreeEventCache() function which will wipe all events from the queue. For some reason it's still undocumented and marked as internal but I think it should do what you want :)
Thanks, seems to work fine and I can make a work-around with this if I update my program before we'll get an update to Hollywood :)
User avatar
airsoftsoftwair
Posts: 5626
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Event queue for a freed display

Post by airsoftsoftwair »

Code: Select all

- Fix: FreeDisplay() didn't flush events pertaining to that display from the queue; this bug was introduced
  in Hollywood 9.0 which saw a rewrite of the event core
Post Reply