Skip to content

SDL_UnregisterTray unexpectedly triggers SDL_EVENT_QUIT event (Create/Destroy tray for feature detection) #13119

Open
@silbinarywolf

Description

@silbinarywolf

SDL: 3.2.10

The problem

I have logic in my Zig application where I create a tray with SDL_CreateTray and then destroy it with SDL_DestroyTray on start-up to detect if the operating system supports the feature.

Calling SDL_DestroyTray has unexpected behaviour where it calls SDL_UnregisterTray which sends an SDL_EVENT_QUIT event because it detects that are no more windows active and it immediately closes the application on the first-frame.

if (toplevel_count == 0) {
SDL_SendQuit();
}

Workarounds for others that find this

  • If you want to do this check, create your application window first.
  • Temporarily disable the hint SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE
    if (!SDL_GetHintBoolean(SDL_HINT_QUIT_ON_LAST_WINDOW_CLOSE, true)) {
    return;
    }

Proposed solutions

  • A new function to detect if trays are supported. SDL_HasTraySupport or something.
  • Avoid triggering quit unless a window has at least been created once or only trigger if the event queue has been polled at least once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions