@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?
Activity
4After using ImGuiTestEngine_UnbindImGuiContext() that got me past the ASSERT checks in ImGuiTestEngine_Start() and my app no longer segfaults but the tests still weren't running. So after chasing down the call chain with a debugger, I discovered engine->TestQueueCoroutineShouldExit gets set to true when tests are stopped and never set back false (which of course it doesn't since you hadn't planned for my use case).
So in my reinitialization of the tests, I also set that flag to false and voila I can reload and rerun the tests as many times as I want without exiting the app.
This is a particularly nice feature for my use case. You can have your app running and be working on your test engine script, as you make incremental improvements you just reload the script and see your test progress. This will let my folks rapidly develop/test/verify their test functions. Thanks again for exposing ImGuiTestEngine_UnbindImGuiContext(). (I didn't end up needing ImGuiTestEngine_BindImGuiContext() since ImGuiTestEngine_Start() makes that call.
Thank you. I pushed this fix as 88ba3d6. I'd like to keep this open as I would eventually want to exercise hot test reload in a test bed, and ensure that the start/bind/unbind/stop sequence are well designed. With your current setup, are the Test Engine .ini data correctly preserved?
For reference here's what mine contains:
[TestEngine][Data]
FilterTests=your_filter
FilterPerfs=
LogHeight=150
CaptureTool=0
PerfTool=0
StackTool=0
CaptureEnabled=1
CaptureOnError=0
VideoCapturePathToEncoder=C:\Omar\Tools\ffmpeg.exe
VideoCaptureParamsToEncoder=-hide_banner -loglevel error -r $FPS -f rawvideo -pix_fmt rgba -s $WIDTHx$HEIGHT -i - -threads 0 -y -preset ultrafast -pix_fmt yuv420p -crf 20 $OUTPUT
GifCaptureParamsToEncoder=-hide_banner -loglevel error -r $FPS -f rawvideo -pix_fmt rgba -s $WIDTHx$HEIGHT -i - -threads 0 -y -filter_complex "split=2 [a] [b]; [a] palettegen [pal]; [b] [pal] paletteuse" $OUTPUT
VideoCaptureExtension=.mp4There doesn't appear to be any difference between a run without reloading and run with reloading.
(Side note, what's kind of cool is that wherever the mouse is when I reload, it moves to the staring position)
If I just run the test without using my reload feature the .ini contains:
[TestEngine][Data]
FilterTests=
FilterPerfs=
LogHeight=150
CaptureTool=0
PerfTool=0
StackTool=0
CaptureEnabled=1
CaptureOnError=0
VideoCapturePathToEncoder=
VideoCaptureParamsToEncoder=
GifCaptureParamsToEncoder=
VideoCaptureExtension=.mp4
.ini Data after I run the test reloading it a few times and then letting it conclude.
[TestEngine][Data]
FilterTests=
FilterPerfs=
LogHeight=150
CaptureTool=0
PerfTool=0
StackTool=0
CaptureEnabled=1
CaptureOnError=0
VideoCapturePathToEncoder=
VideoCaptureParamsToEncoder=
GifCaptureParamsToEncoder=
VideoCaptureExtension=.mp4
@beekayer: the reason
ImGuiTestEngine_Stop()is not entirely symmetrical withImGuiTestEngine_Start()is partly due to the need to not unbind immediately in order to preserve Test Engine .ini settings (we want it to be bound duringImGui::DestroyContext()).I have temporarily exposed
ImGuiTestEngine_BindImGuiContext()/ImGuiTestEngine_UnbindImGuiContext()in imgui_te_internal.h until I find a better solution for this.