Skip to content

Commit

Permalink
GD-491: Fix Godot editor crash for Linux systems
Browse files Browse the repository at this point in the history
# Why
The Godot editor crashes if the GdUnit4 plugin enabled at exit.

# What
Extend the hotfix to run also on Linux systems
  • Loading branch information
MikeSchulze committed Jun 6, 2024
1 parent eb1fd8e commit 11fd4d3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
3 changes: 2 additions & 1 deletion addons/gdUnit4/bin/GdUnitCmdTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class CLIRunner:
func quit(code: int) -> void:
_cs_executor = null
GdUnitTools.dispose_all()
await GdUnitMemoryObserver.gc_on_guarded_instances()
#await GdUnitMemoryObserver.gc_on_guarded_instances()
await get_tree().physics_frame
get_tree().quit(code)

Expand Down Expand Up @@ -615,6 +615,7 @@ func _initialize() -> void:

# do not use print statements on _finalize it results in random crashes
func _finalize() -> void:
queue_delete(_cli_runner)
if OS.is_stdout_verbose():
prints("Finallize ..")
prints("-Orphan nodes report-----------------------")
Expand Down
14 changes: 14 additions & 0 deletions addons/gdUnit4/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ var _guard: GdUnitTestDiscoverGuard


func _enter_tree() -> void:
if check_running_in_test_env():
prints("It was recognized that GdUnit4 is running in a test environment, therefore the GdUnit4 plugin will not be activated!")
return
if Engine.get_version_info().hex < 0x40200:
prints("GdUnit4 plugin requires a minimum of Godot 4.2.x Version!")
return
Expand All @@ -36,6 +39,8 @@ func _enter_tree() -> void:


func _exit_tree() -> void:
if check_running_in_test_env():
return
if is_instance_valid(_gd_inspector):
remove_control_from_docks(_gd_inspector)
GodotVersionFixures.free_fix(_gd_inspector)
Expand All @@ -49,6 +54,15 @@ func _exit_tree() -> void:
prints("Unload GdUnit4 Plugin success")


func check_running_in_test_env() -> bool:
var args := OS.get_cmdline_args()
args.append_array(OS.get_cmdline_user_args())
prints("plugin cmd args", args)
if DisplayServer.get_name() == "headless" or args.has("--add") or args.has("-a") or args.has("--quit-after") or args.has("--import"):
return true
return false


func _on_resource_saved(resource :Resource) -> void:
if resource is Script:
_guard.discover(resource)
3 changes: 1 addition & 2 deletions addons/gdUnit4/src/core/GdUnitSignals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ static func dispose() -> void:
for signal_ in signals.get_signal_list():
for connection in signals.get_signal_connection_list(signal_["name"]):
connection["signal"].disconnect(connection["callable"])
signals = null
Engine.remove_meta(META_KEY)
while signals.get_reference_count() > 0:
signals.unreference()
6 changes: 3 additions & 3 deletions addons/gdUnit4/src/core/GdUnitTools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ static func release_timers() -> void:
for node :Node in Engine.get_main_loop().root.get_children():
if is_instance_valid(node) and node.is_in_group("GdUnitTimers"):
if is_instance_valid(node):
Engine.get_main_loop().root.remove_child(node)
Engine.get_main_loop().root.remove_child.call_deferred(node)
node.stop()
node.free()
node.queue_free()


# the finally cleaup unfreed resources and singletons
static func dispose_all() -> void:
release_timers()
GdUnitSignals.dispose()
GdUnitSingleton.dispose()
GdUnitSignals.dispose()


# if instance an mock or spy we need manually freeing the self reference
Expand Down
4 changes: 3 additions & 1 deletion addons/gdUnit4/src/core/GodotVersionFixures.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ static func set_event_global_position(event: InputEventMouseMotion, global_posit

# we crash on macOS when using free() inside the plugin _exit_tree
static func free_fix(instance: Object) -> void:
if OS.get_distribution_name().contains("mac"):
var distribution_name := OS.get_distribution_name()
if distribution_name != "Windows":
prints("Using queue_free() hotfix on system:", distribution_name)
instance.queue_free()
else:
instance.free()
2 changes: 1 addition & 1 deletion gdUnit4.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.2.1">
<Project Sdk="Godot.NET.Sdk/4.2.2">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>11.0</LangVersion>
Expand Down
9 changes: 9 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@ gdscript/warnings/return_value_discarded=false

project/assembly_name="gdUnit4"

[editor_plugins]

enabled=PackedStringArray("res://addons/gdUnit4/plugin.cfg")

[gdunit4]

settings/common/update_notification_enabled=false
ui/inspector/node_collapse=false
ui/toolbar/run_overall=true
ui/inspector/tree_sort_mode=1
settings/test/test_discovery=true
report/godot/script_error=false

[importer_defaults]

Expand Down

0 comments on commit 11fd4d3

Please sign in to comment.