godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.17k stars 20.21k forks source link

Godot crashes when @tool is applied to a script that references a static var dict from another script #95527

Open rafalou38 opened 1 month ago

rafalou38 commented 1 month ago

Tested versions

System information

Windows 11

Issue description

Godot completely crashes, without error when I apply @tool to my script. I can still run the project successfully by not loading the tool in the editor or by running from cmdline.

Steps to reproduce

After a lot of testing, I have pinpointed the issue to this:

In the tool script at _ready and _process

unlocked = Economy.research[type]["unlocked"] 

where Economy is

class_name Economy
extends Node2D

static var money := 0.0

static var research := {
    NodeHandler.NodeType.SHOP: {"unlocked": true, "upgrade": 0, "max_buy": 0},
    NodeHandler.NodeType.MINE: {"unlocked": true, "upgrade": 0, "max_buy": 0},
    NodeHandler.NodeType.PROCESSOR: {"unlocked": true, "upgrade": 0, "max_buy": 0},
    NodeHandler.NodeType.REFINERY: {"unlocked": true, "upgrade": 0, "max_buy": 0},
    NodeHandler.NodeType.TETHER: {"unlocked": false, "upgrade": 0, "max_buy": 0},
    NodeHandler.NodeType.DUPLICATOR: {"unlocked": false, "upgrade": 0, "max_buy": 0},
}

Minimal reproduction project (MRP)

I reduced my project to the bare minimum to reproduce this error on the min-bug branch: https://github.com/rafalou38/IdleGame/tree/min-bug

The tool script is at res://views/shop/shop_item.gd And the crash can be resolved by comenting the line

@tool
# or
unlocked = Economy.research[type]["unlocked"] 
matheusmdx commented 1 month ago

I tested with godot 4.3 stable and instead a crash the editor starts a spam of two errors:

res://views/shop/shop_item.gd:20 - Out of bounds get index '0' (on base: 'Dictionary')
res://views/shop/shop_item.gd:20 - Out of bounds get index '1' (on base: 'Dictionary')

image


I bisected and the crash was changed to the error spam after https://github.com/godotengine/godot/pull/91472. Before this pr the engine crash with this backtrace:

Backtrace ``` ================================================================ CrashHandlerException: Program crashed Engine version: Godot Engine v4.3.dev.custom_build (396ce1a8c8a69a8a1448fcc9321bf055ae9fb5f1) Dumping the backtrace. Please include this when reporting the bug to the project developer. [0] HashMap > >::_lookup_pos (C:\Users\Matheus\Downloads\Godot Source\core\templates\hash_map.h:100) [1] HashMap > >::_lookup_pos (C:\Users\Matheus\Downloads\Godot Source\core\templates\hash_map.h:100) [2] HashMap > >::find (C:\Users\Matheus\Downloads\Godot Source\core\templates\hash_map.h:501) [3] Dictionary::getptr (C:\Users\Matheus\Downloads\Godot Source\core\variant\dictionary.cpp:115) [4] VariantIndexedSetGet_Dictionary::get (C:\Users\Matheus\Downloads\Godot Source\core\variant\variant_setget.cpp:860) [5] GDScriptFunction::call (C:\Users\Matheus\Downloads\Godot Source\modules\gdscript\gdscript_vm.cpp:1076) [6] GDScriptInstance::callp (C:\Users\Matheus\Downloads\Godot Source\modules\gdscript\gdscript.cpp:1978) [7] Object::callp (C:\Users\Matheus\Downloads\Godot Source\core\object\object.cpp:820) [8] Variant::callp (C:\Users\Matheus\Downloads\Godot Source\core\variant\variant_call.cpp:1212) [9] GDScriptFunction::call (C:\Users\Matheus\Downloads\Godot Source\modules\gdscript\gdscript_vm.cpp:1764) [10] GDScriptInstance::callp (C:\Users\Matheus\Downloads\Godot Source\modules\gdscript\gdscript.cpp:1978) [11] Node::_gdvirtual__ready_call<0> (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.h:354) [12] Node::_notification (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:214) [13] Node::_notificationv (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.h:49) [14] CanvasItem::_notificationv (C:\Users\Matheus\Downloads\Godot Source\scene\main\canvas_item.h:45) [15] Control::_notificationv (C:\Users\Matheus\Downloads\Godot Source\scene\gui\control.h:48) [16] Container::_notificationv (C:\Users\Matheus\Downloads\Godot Source\scene\gui\container.h:37) [17] BoxContainer::_notificationv (C:\Users\Matheus\Downloads\Godot Source\scene\gui\box_container.h:37) [18] HBoxContainer::_notificationv (C:\Users\Matheus\Downloads\Godot Source\scene\gui\box_container.h:81) [19] Object::notification (C:\Users\Matheus\Downloads\Godot Source\core\object\object.cpp:907) [20] Node::_propagate_ready (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:269) [21] Node::_propagate_ready (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:260) [22] Node::_propagate_ready (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:260) [23] Node::_propagate_ready (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:260) [24] Node::_propagate_ready (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:260) [25] Node::_propagate_ready (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:260) [26] Node::_propagate_ready (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:260) [27] Node::_propagate_ready (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:260) [28] Node::_propagate_ready (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:260) [29] Node::_set_tree (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:3181) [30] Node::_add_child_nocheck (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:1552) [31] Node::add_child (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:1580) [32] EditorNode::set_edited_scene (C:\Users\Matheus\Downloads\Godot Source\editor\editor_node.cpp:3714) [33] EditorNode::load_scene (C:\Users\Matheus\Downloads\Godot Source\editor\editor_node.cpp:4040) [34] EditorNode::_load_open_scenes_from_config (C:\Users\Matheus\Downloads\Godot Source\editor\editor_node.cpp:5059) [35] EditorNode::_load_editor_layout (C:\Users\Matheus\Downloads\Godot Source\editor\editor_node.cpp:4983) [36] EditorNode::_sources_changed (C:\Users\Matheus\Downloads\Godot Source\editor\editor_node.cpp:1078) [37] call_with_variant_args_helper (C:\Users\Matheus\Downloads\Godot Source\core\variant\binder_common.h:309)[38] call_with_variant_args (C:\Users\Matheus\Downloads\Godot Source\core\variant\binder_common.h:419) [39] CallableCustomMethodPointer::call (C:\Users\Matheus\Downloads\Godot Source\core\object\callable_method_pointer.h:104) [40] Callable::callp (C:\Users\Matheus\Downloads\Godot Source\core\variant\callable.cpp:58) [41] Object::emit_signalp (C:\Users\Matheus\Downloads\Godot Source\core\object\object.cpp:1221) [42] Node::emit_signalp (C:\Users\Matheus\Downloads\Godot Source\scene\main\node.cpp:3903) [43] Object::emit_signal (C:\Users\Matheus\Downloads\Godot Source\core\object\object.h:936) [44] EditorFileSystem::_notification (C:\Users\Matheus\Downloads\Godot Source\editor\editor_file_system.cpp:1299) [45] EditorFileSystem::_notificationv (C:\Users\Matheus\Downloads\Godot Source\editor\editor_file_system.h:138) [46] Object::notification (C:\Users\Matheus\Downloads\Godot Source\core\object\object.cpp:907) [47] SceneTree::_process_group (C:\Users\Matheus\Downloads\Godot Source\scene\main\scene_tree.cpp:966) [48] SceneTree::_process (C:\Users\Matheus\Downloads\Godot Source\scene\main\scene_tree.cpp:1043) [49] SceneTree::process (C:\Users\Matheus\Downloads\Godot Source\scene\main\scene_tree.cpp:529) [50] Main::iteration (C:\Users\Matheus\Downloads\Godot Source\main\main.cpp:4041) [51] OS_Windows::run (C:\Users\Matheus\Downloads\Godot Source\platform\windows\os_windows.cpp:1686) [52] widechar_main (C:\Users\Matheus\Downloads\Godot Source\platform\windows\godot_windows.cpp:181) [53] _main (C:\Users\Matheus\Downloads\Godot Source\platform\windows\godot_windows.cpp:206) [54] main (C:\Users\Matheus\Downloads\Godot Source\platform\windows\godot_windows.cpp:220) [55] WinMain (C:\Users\Matheus\Downloads\Godot Source\platform\windows\godot_windows.cpp:234) [56] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288) [57] -- END OF BACKTRACE -- ================================================================ ```