Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSX backend crashes processing IME events when rendering from DisplayLink #5940

Open
TheMostDiligent opened this issue Nov 30, 2022 · 4 comments · May be fixed by #6528
Open

OSX backend crashes processing IME events when rendering from DisplayLink #5940

TheMostDiligent opened this issue Nov 30, 2022 · 4 comments · May be fixed by #6528

Comments

@TheMostDiligent
Copy link
Contributor

Version/Branch of Dear ImGui:

Version: 1.89.1
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_osx.mm + custom
Compiler: AppleClang 13.1.6.13160021 (XCode 13.4)
Operating System: MacOS (M1, arm64)

My Issue/Question:

When using DisplayLink, render commands are called from a separate thread that does not allow processing input events. In current implementation, however, ImGui::Render calls ImGui::EndFrame that eventually calls this callback which results in crash:

    io.SetPlatformImeDataFn = [](ImGuiViewport* viewport, ImGuiPlatformImeData* data) -> void
    {
        ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData();
        if (data->WantVisible)
        {
            [bd->InputContext activate]; <- Crash here
        }
        else
        {
            [bd->InputContext discardMarkedText];
            [bd->InputContext invalidateCharacterCoordinates];
            [bd->InputContext deactivate];
        }
        [bd->KeyEventResponder setImePosX:data->InputPos.x imePosY:data->InputPos.y + data->InputLineHeight];
    };

As an additional note, it would be really nice if there still was an option to handle OSX events manually.

@ocornut ocornut changed the title OSX backend crashes processing keyboard events when rendering from DisplayLink Nov 30, 2022
@ocornut
Copy link
Owner

ocornut commented Nov 30, 2022

A PR/fix would be welcome for the crash. I don't often have access to a Mac and we need community to spend the time to research and fix issues like that properly, otherwise they don't get fixed.

As an additional note, it would be really nice if there still was an option to handle OSX events manually.

Why? And if you can of how it could be done happy to hear about it.

@TheMostDiligent
Copy link
Contributor Author

A PR/fix would be welcome for the crash.

I haven't updated dear imgui for a while and I see that a lot has changed in OSX implementation. I don't know the reasons, but it appears that overall changes were going in the wrong direction: input event processing is now completely hidden from the application (unlike Windows and Linux where it is explicit), which has no control over when it is done. Like I wrote in my issue, this design is incompatible with the Display Link approach (which is in fact recommended by Apple), where rendering and input processing are decoupled.
I don't see how this can be easily fixed without making ImGui_ImplOSX_HandleEvent public again, so that the application can decide which thread and at what point this should be called from.

@ocornut
Copy link
Owner

ocornut commented Nov 30, 2022

You can use git log and blame to find the reasons, if any.
Again, this code has no explicit maintainer, I have no idea what DisplayLink is, so it'll need someone to actually dig and devise solutions, while keeping in mind other use cases. That or, you use a portable backend.

@TheMostDiligent
Copy link
Contributor Author

Yes, I did use git log to see where the changes happened (so far I am testing 1.85, but apparently will need to go further back due to other issues).

That or, you use a portable backend.

That appears to be a more feasible approach at this moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants