ocornut/imgui

Incorrect use of `SDL_OpenURL` in SDL3 backend

Closed this issue · 2 comments

Version/Branch of Dear ImGui:

Version 1.92.2b

Back-ends:

imgui_impl_sdl3.cpp

Compiler, OS:

Any

Full config/build information:

No response

Details:

The following line is incorrect; should be return SDL_OpenURL(url); directly.

platform_io.Platform_OpenInShellFn = [](ImGuiContext*, const char* url) { return SDL_OpenURL(url) == 0; };

The background is Functions that previously returned a negative error code now return bool. (For SDL_OpenURL, SDL2 uses 0 on success and -1 on failure (ref), but SDL3 uses true on success and false on failure (ref).)

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

The following example will open the homepage successfully and trigger the assertion failure.

static void issue() {
    static bool open = false;
    if (ImGui::Begin("Control", 0, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings)) {
        if (ImGui::Button("Open url")) {
            if (!ImGui::GetPlatformIO().Platform_OpenInShellFn(ImGui::GetCurrentContext(),
                                                               "https://github.com/ocornut/imgui")) {
                assert(false);
            }
        }
    }
    ImGui::End();
}

By the way, I think it's somewhat under-documented that Platform_OpenInShellFn use true to mean success. (Currently implied by Platform_OpenInShellFn_DefaultImpl implementations.)

imgui/imgui.h

Line 3946 in b46f099

bool (*Platform_OpenInShellFn)(ImGuiContext* ctx, const char* path);

Thank you! This is fixed by bdb8243