{"id":97,"date":"2025-08-12T17:21:01","date_gmt":"2025-08-12T17:21:01","guid":{"rendered":"https:\/\/blogs.scummvm.org\/superlemon\/?p=97"},"modified":"2025-08-12T18:32:13","modified_gmt":"2025-08-12T18:32:13","slug":"97","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/superlemon\/2025\/08\/12\/97\/","title":{"rendered":"ImGui: Improving the Visual Debugger"},"content":{"rendered":"<p>This week, I continued my work on Director ImGui debugger from last week. Working on ImGui has been bit of a fun exercise since, it is an open canvas. There are a lot of opportunities to improve upon, and it all depends on what a developer might find useful while working on Director engine.<\/p>\n<p>First of all, there were a bunch of impurities with the ImGui debugger. e.g.<\/p>\n<ul>\n<li>Many child widgets have the same problem as the breakpoint window error pop-up from last week. i.e. widgets having the same label and id causing the ImGui throw an pop-up error saying changes made to one widget will be reflected to the other. I solved the same problem in the following places:<\/li>\n<li>i.\u00a0 \u00a0Vars Window<br \/>\nii. Watched Variables<br \/>\niii. Scripts handler widget<\/li>\n<li>I also improved the search for handler in the <code>getHandler<\/code> function. Instead of searching for the handler in all casts, we can single out the cast that has the handler in it.<\/li>\n<li>When displaying Prop list in the execution handler window, there was a missing line, which I promptly added.<\/li>\n<\/ul>\n<p>And a bunch of other small stuff, too small to be worth noting here.<\/p>\n<p>Another feature that was stubbed in the debugger was being able to load and save the current state of the debugger into a persistent file. So, we can save a position in the game we are currently working on, and load the same position every time we start\u00a0 a debugging session.<br \/>\nWe went with the JSON format to store the state. We are currently storing the following things (and loading them back):<br \/>\n1) Window Positions<br \/>\n2) Score frame number<br \/>\n3) Windows that are open\/closed<br \/>\n4) Global, Local and Watched Variables<br \/>\n5) Breakpoints<br \/>\n6) Log<br \/>\n7) Colors<br \/>\nHere, @OMGThePizzaGuy and @lephilousophe showed me `ImGui::SaveIniSettingsToMemory\/ImGui::LoadIniSettingsFromMemory` which made my job much easier.<\/p>\n<p>In the Watched Vars window, I am also showing Local Variables and Global Variables with different colors. On top of that, Local Variables that are out of scope are shown with different color.<\/p>\n<p>All variables are now shown with `renderVariable()` which allows variables to be clicked on to add them to the WatchedVars list and also show their current value.<\/p>\n<p>Previously, the Scripts window only showed the handler being executed at that moment. However, for better navigation, @sev suggested that all the scripts from the same lingo context should be shown in the same window. This took me a while. Since, now not only was I rendering multiple (ImGui) widgets for multiple (Director) windows, I was also showing rendering multiple handler in the same Scripts widget. This caused a bunch of problems with stepping over e.g. pressing step over caused the script to move multiple steps forward, and with showing the current line in the handler (with a little yellow arrow), because the <code>_state-&gt;_dbg._isScriptDirty<\/code> was getting set to <code>false<\/code> immediately after the first script was rendered. Also, the scroll to the current line was also not working. This took some time and debugging to fix.<\/p>\n<p>When @sev started review on my PR, he immediately pointed out that I was making a separate <code>ImGuiState::state<\/code> for each window, which in hindsight I realized was a mistake. So, I reworked it to only make a separate instances of the objects that are needed to hold the execution context of a window. This also took a while to get right. There was a bunch of unexpected behavior including, the scripts were not showing up the first time the &#8216;step&#8217; button was pressed in the control panel.<\/p>\n<p>I also fixed a deprecation warning that occurred while compiling the Director engine. I had to create a custom copy constructor for the <code>MacWindow<\/code> class since the synthesized copy constructor was calling a deprecated copy constructor for the <code>ManagedSurface<\/code> class. Instead I had to use a <code>copyFrom<\/code> method as suggested.<br \/>\nThere was another instance of use of deprecated method <code>operator=<\/code> for the <code>ManagedSurface<\/code> class, used <code>copyFrom<\/code> there as well.<\/p>\n<p>Overall, a somewhat normal week. I hope to make even more improvements to the ImGui debugger. e.g. Adding a trace for watched variables is next on the list.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week, I continued my work on Director ImGui debugger from last week. Working on ImGui has been bit of a fun exercise since, it is an open canvas. There are a lot of opportunities to improve upon, and it all depends on what a developer might find useful while working on Director engine. First [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-week-10"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/posts\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/comments?post=97"}],"version-history":[{"count":3,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":102,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/posts\/97\/revisions\/102"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/media?parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/categories?post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/superlemon\/wp-json\/wp\/v2\/tags?post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}