ocornut / ocornut/imgui_test_engine

Unbind/rebind context

Open
#67 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

test engine
Dominant language
C++
Stars
629
Forks
83
PR merge metrics
No merged PRs in 30d

Description

@beekayer posted in #64
(please avoid posting unrelated questions in existing topics, thank you)

I do need one more piece of advice. My application is a Lua runtime environment. So all of the TestEngine mechanisms are managed by an object I bind to the Lua context. If there's a Lua script error, my application lets you fix the Lua error and reload without exiting the application (thus ImGui context is preserved). Note, the Lua scripts are not in charge of creating and destroying ImGui context, nor creating new frames and rendering them. I am not using 1:1 ImGui -> Lua bindings, basically only widget ImGui API is exposed to Lua. All of this has been working well for years.
I've been able to get TestEngine working well except for one situation. On a reload, I don't destroy the ImGui context and I don't destroy the ImGuiTestEngine either. What I'm trying to do is get the TestEngine to a state where the same tests can be registered again and the TestEngine can be started again. Sequence of actions I'm trying to accomplish:
User has Lua error, fixes Lua error and invokes reload:

  • ImGuiTestEngine_Stop()
  • ImGuiTestEngine_UnregisterTest() <-- go through and unregister all tests because they will be loaded again when the Lua script is run again.
  • .. what I want to do here is ImGuiTestEngine_UnbindImGuiContext() because you can't call ImGuiTestEngine_Start() with the TestEngine still having a reference to the ImGuiContext, but can't because that's a private function.
  • Run Lua script again which does:
  • For each test registered in Lua script: IM_REGISTER_TEST(), ImGuiTestEngine_QueueTest()
  • ImGuiTestEngine_Start() <-- fails assert: IM_ASSERT(engine->UiContextTarget == NULL);
    I see that ImGuiTestEngine_DestroyContext() calls ImGuiTestEngine_UnbindImGuiContext() but that's for a complete shutdown. Like I said, I'm keeping the application alive (i.e. I'm not destroying the ImGui context) for a reload. Any advice?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ImGuiTestEngine_Stop(), ImGuiTestEngine_UnregisterTest(), ImGuiTestEngine_Start(), ImGuiTestEngine_DestroyContext(), and private ImGuiTestEngine_UnbindImGuiContext() flow described in the issue. Determine whether a public unbind/rebind path can support re-registering Lua-loaded tests while preserving the ImGui context. Done means the engine can be stopped, unbound, reloaded, and started again without the UiContextTarget assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.