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

Editor crash when attaching a certain tool script #79882

Closed
KoBeWi opened this issue Jul 25, 2023 · 8 comments · Fixed by #86633
Closed

Editor crash when attaching a certain tool script #79882

KoBeWi opened this issue Jul 25, 2023 · 8 comments · Fixed by #86633

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Jul 25, 2023

Godot version

4.2 f618701

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

This script:

@tool
extends Node

@export var material_count: int:
	set(count):
		if count == material_count:
			return
		
		materials.resize(count)
		if count > material_count:
			for i in range(material_count, count):
				materials[i] = TerrainMaterial.new()
		
		material_count = count
		notify_property_list_changed()

var materials: Array[TerrainMaterial]

func _get_property_list() -> Array[Dictionary]:
	var ret: Array[Dictionary]
	
	for i in material_count:
		ret.append({name = "material_%d/name" % i, type = TYPE_STRING})
		ret.append({name = "material_%d/durability" % i, type = TYPE_INT, hint = PROPERTY_HINT_RANGE, hint_string = "0,255,1"})
	
	return ret

func _set(property: StringName, value: Variant) -> bool:
	var string: String = property
	
	if string.get_slice_count("/") != 2 or not string.get_slice("/", 0).begins_with("material_"):
		return false
	
	var idx := string.get_slice("/", 0).trim_prefix("material_").to_int()
	if idx < 0 or idx >= materials.size():
		return false
	
	var material := materials[idx]
	match string.get_slice("/", 1):
		"name":
			material.name = value
			return true
		"durability":
			material.durability = value
			return true
		_:
			return false

func _get(property: StringName) -> Variant:
	var string: String = property
	
	if string.get_slice_count("/") != 2 or not string.get_slice("/", 0).begins_with("material_"):
		return false
	
	var idx := string.get_slice("/", 0).trim_prefix("material_").to_int()
	if idx < 0 or idx >= materials.size():
		return false
	
	var material := materials[idx]
	match string.get_slice("/", 1):
		"name":
			return material.name
		"durability":
			return material.durability
		_:
			return null

func get_durability_table() -> PackedInt64Array:
	var ret: PackedInt64Array
	for mat in materials:
		ret.append(mat.durability)
	return ret

class TerrainMaterial:
	var name: String
	var durability: int

Causes:

CrashHandlerException: Program crashed
Engine version: Godot Engine v4.2.dev.custom_build (f6187014ec1d7a47b7201f64f3a8376a5da2f42d)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] List<ScriptLanguage::ScriptError,DefaultAllocator>::operator[] (C:\godot_source\core\templates\list.h:521)
[1] ScriptTextEditor::_validate_script (C:\godot_source\editor\plugins\script_text_editor.cpp:489)
[2] call_with_variant_args_helper<ScriptTextEditor> (C:\godot_source\core\variant\binder_common.h:308)
[3] call_with_variant_args<ScriptTextEditor> (C:\godot_source\core\variant\binder_common.h:418)
[4] CallableCustomMethodPointer<ScriptTextEditor>::call (C:\godot_source\core\object\callable_method_pointer.h:105)
[5] Callable::callp (C:\godot_source\core\variant\callable.cpp:51)
[6] Object::emit_signalp (C:\godot_source\core\object\object.cpp:1071)
[7] Node::emit_signalp (C:\godot_source\scene\main\node.cpp:3571)
[8] Object::emit_signal<> (C:\godot_source\core\object\object.h:891)
[9] CodeTextEditor::_text_changed_idle_timeout (C:\godot_source\editor\code_editor.cpp:1748)
[10] call_with_variant_args_helper<CodeTextEditor> (C:\godot_source\core\variant\binder_common.h:308)
[11] call_with_variant_args<CodeTextEditor> (C:\godot_source\core\variant\binder_common.h:418)
[12] CallableCustomMethodPointer<CodeTextEditor>::call (C:\godot_source\core\object\callable_method_pointer.h:105)
[13] Callable::callp (C:\godot_source\core\variant\callable.cpp:51)
[14] Object::emit_signalp (C:\godot_source\core\object\object.cpp:1071)
[15] Node::emit_signalp (C:\godot_source\scene\main\node.cpp:3571)
[16] Object::emit_signal<> (C:\godot_source\core\object\object.h:891)
[17] Timer::_notification (C:\godot_source\scene\main\timer.cpp:62)
[18] Timer::_notificationv (C:\godot_source\scene\main\timer.h:37)
[19] Object::notification (C:\godot_source\core\object\object.cpp:798)
[20] SceneTree::_process_group (C:\godot_source\scene\main\scene_tree.cpp:943)
[21] SceneTree::_process (C:\godot_source\scene\main\scene_tree.cpp:1024)
[22] SceneTree::process (C:\godot_source\scene\main\scene_tree.cpp:510)
[23] Main::iteration (C:\godot_source\main\main.cpp:3434)
[24] OS_Windows::run (C:\godot_source\platform\windows\os_windows.cpp:1479)
[25] widechar_main (C:\godot_source\platform\windows\godot_windows.cpp:182)
[26] _main (C:\godot_source\platform\windows\godot_windows.cpp:204)
[27] main (C:\godot_source\platform\windows\godot_windows.cpp:218)
[28] WinMain (C:\godot_source\platform\windows\godot_windows.cpp:232)
[29] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[30] <couldn't map PC to fn name>
-- END OF BACKTRACE --

Note that it's some new issue. It doesn't happen in 4.2 dev1

Steps to reproduce

  1. Create new scene
  2. Add a Node
  3. Attach a new built-in script
  4. Paste the code above
  5. The editor should crash immediately

Minimal reproduction project

N/A

@svdragster
Copy link

svdragster commented Jul 29, 2023

I followed your steps on master (031aa99) and f618701, I unfortunately can't reproduce the issue on my machine. I missed that it's a built in script. Now I can reproduce it.

System information

Godot v4.2.dev (f618701) - Arch Linux #1 SMP PREEMPT_DYNAMIC Mon, 24 Jul 2023 20:19:38 +0000 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 (nvidia; 535.86.05) - 13th Gen Intel(R) Core(TM) i9-13900K (32 Threads)

@KoBeWi
Copy link
Member Author

KoBeWi commented Jul 29, 2023

godot.windows.editor.dev.x86_64_SsDwfiDiaE.mp4

@svdragster
Copy link

Thanks, I missed the part that is has to be built in script. Now I can reproduce the crash.

I tried to get it to crash using only parts of the script. It's already crashing with just this line:

var materials: Array[TerrainMaterial]

In fact it seems to happen when the Array type can't be found.

This crashes when pasting:

var foo: Array[DoesNotExist]

This does not crash:

var foo: Array[String]

@KoBeWi
Copy link
Member Author

KoBeWi commented Jul 29, 2023

Crash is one thing, but TerrainMaterial is defined in the same file, so the type should be found.

@svdragster
Copy link

svdragster commented Jul 29, 2023

It seems to crash here trying to get the first error from the errors List. However errors is empty.

I believe commit 83b0170 broke this (PR #75216), because when I comment out lines 481-487 it no longer crashes.

@KoBeWi
Copy link
Member Author

KoBeWi commented Jul 29, 2023

CC @rune-scape

@Topicranger
Copy link

Notably, it crashes when the newly created built-in script is not saved yet.
After quickly saving and reloading the scene, the script works fine and, when editing, script errors get thrown.

@rune-scape
Copy link
Contributor

this is fixed by #81156

@akien-mga akien-mga added this to the 4.2 milestone Feb 13, 2024
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.

5 participants