Skip to content

Commit eb0ad66

Browse files
committed
Demo: example tree used by Property Editor & Selection demos properly freed on app closure. (#8158)
1 parent 142827f commit eb0ad66

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Other changes:
5353

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

imgui_demo.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ static ExampleTreeNode* ExampleTree_CreateNode(const char* name, int uid, Exampl
308308
return node;
309309
}
310310

311+
static void ExampleTree_DestroyNode(ExampleTreeNode* node)
312+
{
313+
for (ExampleTreeNode* child_node : node->Childs)
314+
ExampleTree_DestroyNode(child_node);
315+
IM_DELETE(node);
316+
}
317+
311318
// Create example tree data
312319
// (this allocates _many_ more times than most other code in either Dear ImGui or others demo)
313320
static ExampleTreeNode* ExampleTree_CreateDemoTree()
@@ -343,7 +350,7 @@ static ExampleTreeNode* ExampleTree_CreateDemoTree()
343350
// [SECTION] Demo Window / ShowDemoWindow()
344351
//-----------------------------------------------------------------------------
345352

346-
// Data to be shared accross different functions of the demo.
353+
// Data to be shared across different functions of the demo.
347354
struct ImGuiDemoWindowData
348355
{
349356
// Examples Apps (accessible from the "Examples" menu)
@@ -371,6 +378,8 @@ struct ImGuiDemoWindowData
371378

372379
// Other data
373380
ExampleTreeNode* DemoTree = NULL;
381+
382+
~ImGuiDemoWindowData() { if (DemoTree) ExampleTree_DestroyNode(DemoTree); }
374383
};
375384

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

0 commit comments

Comments
 (0)