hoffstadt/DearPyGui

Component-specific themes corrupt the heap

v-ein opened this issue · 1 comments

Version of Dear PyGui

Version: 1.10.1
Operating System: Windows 10

My Issue/Question

This only happes with a particular use case, see the example below. There's a theme that contains a component for mvCollapsingHeader, and that theme gets bound to groups that follow a certain flow of widgets. With that particular widget tree, the heap within Python gets corrupted, and the program crashes on closing. Sometimes there are visible side effects, e.g. colors or widget visibility may be affected. It depends on a particular run.

To Reproduce

Steps to reproduce the behavior:

  1. Run the example below.
  2. Close the window. See it crash.

Expected behavior

No heap corruption.

Screenshots/Video

image

Here's the error message I got in Visual Studio after clicking "Debug":

Unhandled exception at 0x000000007764F3E2 (ntdll.dll) in python.exe: 0xC0000374: A heap has been corrupted (parameters: 0x00000000776C8430). occurred

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

dpg.create_context()

dpg.create_viewport(title="Test", width=600, height=600)

dpg.setup_dearpygui()
dpg.show_viewport()

with dpg.window(width=200, height=150):
    with dpg.theme() as header_theme:
        with dpg.theme_component(dpg.mvCollapsingHeader):
            dpg.add_theme_style(dpg.mvStyleVar_FramePadding, 4, 0)

    with dpg.collapsing_header(label="Lorem", default_open=True):
        with dpg.group():
            dpg.bind_item_theme(dpg.last_item(), header_theme)
            with dpg.collapsing_header(label="Ipsum", default_open=True):
                with dpg.group():
                    dpg.bind_item_theme(dpg.last_item(), header_theme)

dpg.start_dearpygui()
dpg.destroy_context()

There needs to be a map<mvAppItemType, stack<mvThemeComponent>> or stack<mvTheme> to support nesting themes like this. It looks like the current code creates linked lists between mvThemeComponent instead, which can break noisily when you nest an item with a theme inside another item with the same theme.

However, theme components with the same mvAppItemType as the item holding the theme don't get put into this linked list, just every component of a different type. So you need the dpg.group()s in that example for it to corrupt.

Another example:

If you click on Dolor a bit, it will acquire contagious green text from the asymptomatic Lorem Ipsum

with dpg.window(width=200, height=150):
    with dpg.theme() as header_theme:
        with dpg.theme_component(dpg.mvCollapsingHeader):
            dpg.add_theme_style(dpg.mvStyleVar_FramePadding, 4, 0)
            dpg.add_theme_color(dpg.mvThemeCol_Text, (0, 255, 0), category=dpg.mvThemeCat_Core)

    with dpg.menu(label="Lorem"):
        dpg.bind_item_theme(dpg.last_item(), header_theme)
        with dpg.menu(label="Ipsum"):
                dpg.bind_item_theme(dpg.last_item(), header_theme)

    with dpg.collapsing_header(label="Dolor", default_open=True):
        pass