Wrong usage/parameters at WaitEvent on AmigaOS - window opens correctly, crash before user interaction

Discuss GUI programming with the RapaGUI plugin here
Post Reply
User avatar
Adam Mierzwa
Posts: 5
Joined: Sat Jun 05, 2021 9:38 pm
Location: Poland
Contact:

Wrong usage/parameters at WaitEvent on AmigaOS - window opens correctly, crash before user interaction

Post by Adam Mierzwa »

Hi,

I'm developing a RapaGUI 2.2 application (Fotografista, a photo editor) compiled with Hollywood 11, targeting Windows, macOS ARM, and AmigaOS. I'm experiencing a crash on AmigaOS that I cannot reproduce on Windows or macOS.

Error message:
"Wrong usage/parameters for this command! Read the documentation!"
File: fotografista.hws (current line: 83 - In function: WaitEvent)

Observations:
- The main window opens correctly (title bar, scrollcanvas with border scroller, statusbar all visible)
- The crash occurs immediately after the window opens, before any user interaction
- The same error message appears on Windows when InstallEventHandler is missing — suggesting WaitEvent receives an event it cannot handle
- The application works correctly on Windows and macOS
- Reproduced on both AmiKit (emulated AmigaOS 3.x) and native AmigaOS 4.1 on X5000 hardware

Main loop (fotografista.hws):

Code: Select all

p_InitLanguage()       ; calls moai.CreateApp(), InstallEventHandler(), moai.Notify()
LoadBrush(10, "icons/icon128.png")
p_PrefsLoad()
p_SetMenusEnabled(False)
Repeat
  WaitEvent
Forever
p_InitLanguage() (i18n.hws):

Code: Select all

Function p_InitLanguage()
  If IsNil(g_prefs.lang$) Then g_prefs.lang$ = "polish"
  If g_prefs.lang$ <> "polish"
    p_WriteCatalogFile(g_prefs.lang$)
    OpenCatalog("Fotografista.catalog")
  EndIf
  g_current_lang$ = g_prefs.lang$
  moai.CreateApp(g_gui_xml$)
  moai.Set("sb", "fontsize", g_prefs.ui_font_size)
  InstallEventHandler({
    RapaGUI = p_EventFunc,
    OnRawKeyDown = Function(msg)
      If msg.Key = "LSHIFT" Or msg.Key = "RSHIFT" Then g_shift_down = True
    EndFunction,
    OnRawKeyUp = Function(msg)
      If msg.Key = "LSHIFT" Or msg.Key = "RSHIFT" Then g_shift_down = False
    EndFunction
  })
  moai.Notify("canvas", "MouseLeft", True)
  moai.Notify("canvas", "MouseMove", True)
  moai.Notify("canvas", "MouseRight", True)
EndFunction
Window XML (relevant fragment):

Code: Select all

xml
<window id="mainwin" title="Fotografista@i18n:187" sizegadget="true"
    width="900" height="650" remember="true"
    menubar="mainmenu"
    notify="closerequest; sizechange"
    usebottomborderscroller="true"
    userightborderscroller="true">
  <vgroup>
    <scrollcanvas id="canvas" autoscale="false"
      virtwidth="1" virtheight="1"
      weight="100"
      usewinborder="true"
      notify="paint"/>
    <statusbar id="sb" fontsize="14" height="32">
      <item id="sb_filename" i18n="188">Brak obrazu</item>
      <item id="sb_size"/>
      <item id="sb_format"/>
      <item id="sb_zoom"/>
      <item id="sb_undo"/>
      <item id="sb_sel"/>
    </statusbar>
  </vgroup>
</window>
Hypotheses already tested and excluded:
- InstallEventHandler position and parameters
- OnRawKeyDown / OnRawKeyUp availability on AmigaOS
- moai.Set() inside Paint callback (moved to RunCallback)
- help= attribute on menu items (removed, no change)
- Nested submenus (3 levels deep under Eksperymentalne)
- Incorrect XML (quotes in item text)
- fontsize/height attributes on statusbar
- Missing Catalogs directory at runtime
- @FILE / OpenCatalog logic
- p_SetMenusEnabled iterating menu IDs
- All menu IDs verified present in XML

Question:
What could cause "Wrong usage/parameters for this command" at WaitEvent on AmigaOS, when the window opens correctly and InstallEventHandler is called with a valid RapaGUI handler, but the crash occurs immediately on the first WaitEvent call?

Is there anything specific to AmigaOS/MUI that could trigger this — perhaps a Paint event fired before WaitEvent that causes a re-entrant call, or a specific GUI attribute that MUI handles differently?

Thank you.
User avatar
Adam Mierzwa
Posts: 5
Joined: Sat Jun 05, 2021 9:38 pm
Location: Poland
Contact:

Re: Wrong usage/parameters at WaitEvent on AmigaOS - window opens correctly, crash before user interaction

Post by Adam Mierzwa »

SOLVED

After bisecting the git history, the root cause was identified: `InstallEventHandler` must be called before `moai.CreateApp()` on AmigaOS. On Windows and macOS the order doesn't matter, but on AmigaOS MUI fires events immediately during GUI creation — if the handler isn't registered yet, WaitEvent receives an unhandled event and crashes.

I had listed "InstallEventHandler position and parameters" as an excluded hypothesis - that was incorrect. The position relative to `moai.CreateApp()` was the key, not the position relative to `WaitEvent`.

Thanks to anyone who read the post.
Post Reply