Skip to content

Commit

Permalink
Demo: example tree used by Property Editor & Selection demos properly…
Browse files Browse the repository at this point in the history
… freed on app closure. (#8158)
  • Loading branch information
ocornut committed Nov 18, 2024
1 parent 142827f commit eb0ad66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Other changes:

- Error Handling: fixed cases where recoverable error handling would crash when
processing errors outside of the NewFrame()..EndFrame() scope. (#1651)
- Demo: example tree used by Property Editor & Selection demos properly freed
on application closure. (#8158) [@Legulysse]
- Examples: Win32+DX12: Using a basic free-list allocator to manage multiple
SRV descriptors.

Expand Down
11 changes: 10 additions & 1 deletion imgui_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ static ExampleTreeNode* ExampleTree_CreateNode(const char* name, int uid, Exampl
return node;
}

static void ExampleTree_DestroyNode(ExampleTreeNode* node)
{
for (ExampleTreeNode* child_node : node->Childs)
ExampleTree_DestroyNode(child_node);
IM_DELETE(node);
}

// Create example tree data
// (this allocates _many_ more times than most other code in either Dear ImGui or others demo)
static ExampleTreeNode* ExampleTree_CreateDemoTree()
Expand Down Expand Up @@ -343,7 +350,7 @@ static ExampleTreeNode* ExampleTree_CreateDemoTree()
// [SECTION] Demo Window / ShowDemoWindow()
//-----------------------------------------------------------------------------

// Data to be shared accross different functions of the demo.
// Data to be shared across different functions of the demo.
struct ImGuiDemoWindowData
{
// Examples Apps (accessible from the "Examples" menu)
Expand Down Expand Up @@ -371,6 +378,8 @@ struct ImGuiDemoWindowData

// Other data
ExampleTreeNode* DemoTree = NULL;

~ImGuiDemoWindowData() { if (DemoTree) ExampleTree_DestroyNode(DemoTree); }
};

// Demonstrate most Dear ImGui features (this is big function!)
Expand Down

0 comments on commit eb0ad66

Please sign in to comment.