Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree's set_selected() does not check if TreeItem belongs to the Tree #84862

Closed
KoBeWi opened this issue Nov 13, 2023 · 1 comment · Fixed by #84870
Closed

Tree's set_selected() does not check if TreeItem belongs to the Tree #84862

KoBeWi opened this issue Nov 13, 2023 · 1 comment · Fixed by #84870

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Nov 13, 2023

Godot version

4.2 beta6

System information

Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 (NVIDIA; 30.0.15.1403) - Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 Threads)

Issue description

Tree allows selecting TreeItem from another Tree, resulting in a crash:

CrashHandlerException: Program crashed
Engine version: Godot Engine v4.2.beta.custom_build (59457685c18e2d729eea50c751c11f049a7186f0)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] CowData<TreeItem::Cell>::_get_size (C:\godot_source\core\templates\cowdata.h:81)
[1] CowData<TreeItem::Cell>::size (C:\godot_source\core\templates\cowdata.h:134)
[2] VectorWriteProxy<TreeItem::Cell>::operator[] (C:\godot_source\core\templates\vector.h:52)
[3] Tree::select_single_item (C:\godot_source\scene\gui\tree.cpp:2574)
[4] Tree::set_selected (C:\godot_source\scene\gui\tree.cpp:4548)
[5] call_with_variant_args_helper<Tree,TreeItem *,int,0,1> (C:\godot_source\core\variant\binder_common.h:308)
[6] call_with_variant_args_dv<Tree,TreeItem *,int> (C:\godot_source\core\variant\binder_common.h:451)
[7] MethodBindT<Tree,TreeItem *,int>::call (C:\godot_source\core\object\method_bind.h:337)
[8] Object::callp (C:\godot_source\core\object\object.cpp:775)
[9] Variant::callp (C:\godot_source\core\variant\variant_call.cpp:1168)
[10] GDScriptFunction::call (C:\godot_source\modules\gdscript\gdscript_vm.cpp:1705)
[11] GDScriptInstance::callp (C:\godot_source\modules\gdscript\gdscript.cpp:1975)
[12] Node::_gdvirtual__ready_call<0> (C:\godot_source\scene\main\node.h:322)
[13] Node::_notification (C:\godot_source\scene\main\node.cpp:188)
[14] Node::_notificationv (C:\godot_source\scene\main\node.h:49)
[15] Object::notification (C:\godot_source\core\object\object.cpp:840)
[16] Node::_propagate_ready (C:\godot_source\scene\main\node.cpp:232)
[17] Node::_propagate_ready (C:\godot_source\scene\main\node.cpp:223)
[18] Node::_propagate_ready (C:\godot_source\scene\main\node.cpp:223)
[19] Node::_set_tree (C:\godot_source\scene\main\node.cpp:2941)
[20] SceneTree::initialize (C:\godot_source\scene\main\scene_tree.cpp:450)
[21] OS_Windows::run (C:\godot_source\platform\windows\os_windows.cpp:1472)
[22] widechar_main (C:\godot_source\platform\windows\godot_windows.cpp:182)
[23] _main (C:\godot_source\platform\windows\godot_windows.cpp:204)
[24] main (C:\godot_source\platform\windows\godot_windows.cpp:218)
[25] WinMain (C:\godot_source\platform\windows\godot_windows.cpp:232)
[26] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[27] <couldn't map PC to fn name>
-- END OF BACKTRACE --

Steps to reproduce

  1. Make a scene with 2 Tree nodes
  2. Run this code
func _ready() -> void:
	var item = $Tree.create_item()
	$Tree2.set_selected(item, 0)

Minimal reproduction project

N/A

@jsjtxietian
Copy link
Contributor

The cause of crash is that get_root returns null, if the tree has some tree items, it won't crash but just sliently fail to set selected, nothing worse will happen. But it should check the tree item belongs to tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants