Skip to content

Commit

Permalink
Fixed errors when going through Object menu pages quickly.
Browse files Browse the repository at this point in the history
One type of error that was occuring was the scene tree calling
`can_process()` on pieces that had just left the scene tree, but they
were still in the "idle_physics_process" group as the _physics_process
notification was being fired. This was solved by not removing the piece
from the scene tree early, and letting the queue_free() operation
remove it from the scene tree instead.

The game would also sometimes freeze at random intervals, with no errors
being thrown. After some debugging, I found that this freezing was
originating from the `load` call in `ResourceManager`, which was being
run inside a thread - thus I think the issue is the same as
godotengine/godot#55566. I implemented the same workaround mentioned
in that issue, and the game no longer freezes.

This commit closes #216.
  • Loading branch information
drwhut committed Mar 9, 2023
1 parent bf8cac7 commit dcb084d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion game/Scripts/Game/UI/Previews/ObjectPreview.gd
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,13 @@ func _remove_piece() -> void:
# case one escapes the _piece reference.
for child in _viewport.get_children():
if child is RigidBody:
_viewport.remove_child(child)
# Removing the piece from the scene tree early sometimes causes
# errors when the _physics_process notification fires, and it is
# still expecting the piece to be in the scene tree.
# TODO: Maybe stop removing children from the scene tree before
# calling queue_free() on them?
#_viewport.remove_child(child)

ResourceManager.queue_free_object(child)

_piece = null
Expand Down
5 changes: 5 additions & 0 deletions game/Scripts/ResourceManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ var _stex_refs = {}
# path: The path of the resource to load.
func load_res(path: String) -> Resource:
_res_mutex.lock()

# Workaround for this issue:
# https://github.com/godotengine/godot/issues/55566
OS.delay_msec(1)

var res: Resource = load(path)

# On macOS, I came across a bug in GLES3 where a StreamTexture would be
Expand Down

0 comments on commit dcb084d

Please sign in to comment.