hoffstadt / hoffstadt/DearPyGui
move_item_up/down crashes if there's a table in the widget tree
- Dominant language
- C++
- Stars
- 15.6k
- Forks
- 783
- PR merge metrics
- No merged PRs in 30d
Description
## Version of Dear PyGui
Version: 1.10.1
Operating System: Windows 10
## My Issue/Question
If `move_item_up` or `move_item_down` is used on a widget that resides somewhere below a table in the widgets tree (as seen by the depth-first tree lookup), DPG crashes on the `move_item_YYY` call.
The reason is that `MoveChildUp/Down` functions in `mvItemRegistry.cpp` perform a depth-first lookup on the widgets tree, comparing each item's UUID to the specified UUID - that is, instead of using `GetItem` they search for the target object on their own. This is because they need to manipulate the parent object (the list of children in it). The following line of code does not expect `child` to be null:
```cpp
if (child->uuid == uuid)
```
On the other hand, `mvTable` adds null pointers to slot 2 each time a column is added. I couldn't find why it does that and how slot 2 is used afterwards (it's reserved for draw commands, but why a column needs null at the corresponding location in slot 2?).
```cpp
void mvTable::onChildAdd(std::shared_ptr item)
{
if (item->type == mvAppItemType::mvTableColumn)
{
...
childslots[2].push_back(nullptr);
```
When `MoveChildUp/Down` perform their lookup, they stumble upon those `nullptr`'s in slot 2 of the table. Boom.
## To Reproduce
Steps to reproduce the behavior:
1. Run the example below. It crashes right at startup.
## Expected behavior
No crash.
## Screenshots/Video
None.
## Standalone, minimal, complete and verifiable example
```python
import dearpygui.dearpygui as dpg
dpg.create_context()
dpg.setup_dearpygui()
dpg.create_viewport(title="Test", width=600, height=600)
with dpg.window():
with dpg.table():
dpg.add_table_column()
btn = dpg.add_text("Lorem")
dpg.move_item_up(btn)
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
```
Contributor guide
Assessment
This issue has not been assessed yet.