sammyfreg / netImgui

'Dear Imgui' remote access library and application
MIT License
613 stars 55 forks source link

Multiple calls of ConnectFromApp results in multiple contextHooks being added #37

Closed TonyAlbrecht closed 2 years ago

TonyAlbrecht commented 2 years ago

Hey Sammy, I love what you've done with netImgui, but I think I've found a bug.

Whenever ConnectFromApp() is called, it Disconnects() and then reconnects and calls client.ContextInitialize() which adds a new context hook (if NETIMGUI_IMGUI_CALLBACK_ENABLED is defined). Currently, the Disconnect doesn't remove the hook, so we end up with a new hook being added every time ConnectFromApp() is called.

You can repro this by running a client, connecting to a server then shutting the server down and then starting it and reconnecting. Every time you do this, a new hook is added and the result is that the server only displays a valid update once every 'N' frames.

Checking mhImguiHookNewframe in ContextInitialize() and only adding a new hook if it's zero works, as should removing the hook in Disconnect() (currently the destructor for ClientInfo is the only place that removes the hook.)

sammyfreg commented 2 years ago

Thank you for the report. Should be easy enough to fix.

sammyfreg commented 2 years ago

Which version of NetImgui are you using?

sammyfreg commented 2 years ago

Issue has been fixed: 74d0be3fc704d5d723c6d704a0d77233af59c40d

Normally, the hook cleanup happen in NewFrame(). As long as it is always called, there should not be any problem. Once I tried with the 'NoBackend' sample (only draw where there's an active connection) , I was able to reproduce the issue and fix it accordingly.