-
-
Notifications
You must be signed in to change notification settings - Fork 510
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
Close organelle menu when leaving cell editor #5775
base: master
Are you sure you want to change the base?
Close organelle menu when leaving cell editor #5775
Conversation
The lead programmer for Thrive is currently on vacation until 2025-01-07. Until then other programmers will try to make pull request reviews, but please be patient if your PR is not getting reviewed. PRs may be merged after multiple programmers have approved the changes (especially making sure to ensure style guide conformance and gameplay testing are good). If there are no active experienced programmers who can perform merges, PRs may need to wait until the lead programmer is back to be merged. |
When exiting the editor with the organelle menu open, I get the following exception: Exception stack traceE 0:00:54:0255 GodotObject.base.cs:78 @ nint Godot.GodotObject.GetPtr(Godot.GodotObject): System.ObjectDisposedException: Cannot access a disposed object. Object name: 'CellEditorComponent'. System.ObjectDisposedException /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:78 @ nint Godot.GodotObject.GetPtr(Godot.GodotObject) GodotObject.base.cs:78 @ nint Godot.GodotObject.GetPtr(Godot.GodotObject) Node.cs:776 @ void Godot.Node.AddChild(Godot.Node, bool, Godot.Node+InternalMode) NodeHelpers.cs:121 @ void NodeHelpers.ReParent(Godot.Node, Godot.Node) ModalManager.cs:169 @ void ModalManager.UpdateModals() ModalManager.cs:68 @ void ModalManager._Process(double) Node.cs:2395 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) NodeWithInput_ScriptMethods.generated.cs:48 @ bool NodeWithInput.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) ModalManager_ScriptMethods.generated.cs:128 @ bool ModalManager.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)It seems like at the moment of |
Thanks for the feedback @dligr. I have updated the code so that all modals are deleted as soon as their parent is deleted. This will stop the exception from occurring again. |
The organelle context menu now correctly closes on editor exit, but an exception is now thrown when exiting with an organelle upgrade popup open. Stack traceE 0:01:45:0885 GodotObject.base.cs:78 @ nint Godot.GodotObject.GetPtr(Godot.GodotObject): System.ObjectDisposedException: Cannot access a disposed object. Object name: 'CustomConfirmationDialog'. System.ObjectDisposedException /root/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GodotObject.base.cs:78 @ nint Godot.GodotObject.GetPtr(Godot.GodotObject) GodotObject.base.cs:78 @ nint Godot.GodotObject.GetPtr(Godot.GodotObject) Node.cs:752 @ Godot.StringName Godot.Node.GetName() Node.cs:374 @ Godot.StringName Godot.Node.get_Name() ModalManager.cs:168 @ void ModalManager.UpdateModals() ModalManager.cs:68 @ void ModalManager._Process(double) Node.cs:2395 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) NodeWithInput_ScriptMethods.generated.cs:48 @ bool NodeWithInput.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) ModalManager_ScriptMethods.generated.cs:138 @ bool ModalManager.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&) CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*) |
Thanks for spotting @dligr. This occurred because the popup was in the demoted popup queue before it was destroyed. I have now fixed this by removing all destroyed popups from this queue. |
After looking through the code, it seems like modals are added to |
@dligr I choose to call the close method since some popups have custom behaviour that is run when they are closed (e.g. the pause menu will unpause the game). From my testing, it seems that no menu will actually be effected though since the pause menu can't loose its parent. |
I think that it really is better to retain the popups' custom OnClose() functionality. |
private void OnParentLost(TopLevelContainer popup) | ||
{ | ||
// Remove the original parent since the reference will now be invalid | ||
originalParents.Remove(popup); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should guard against duplicate signals as MakeModal I think can be called multiple times (so the signal registration also happens multiple times).
originalParents[popup] = parent; | ||
|
||
// Listen for when the parent is removed from the tree so the modal can be removed as well. | ||
parent.Connect(Node.SignalName.TreeExiting, Callable.From(() => OnParentLost(popup)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be worth it to track what parents are connected in this way? So that they can be unconnected on normal close (and not require leaving the tree). Or at least made so that no duplicate connections are made by this method.
Brief Description of What This PR Does
Automatically close a modal when the parent is deleted. If the modal is not immediately deleted, then there will be an exception if the modal is closed and the modal manager tries to reparent it back to the now deleted parent.
Related Issues
Closes #4470
Progress Checklist
Note: before starting this checklist the PR should be marked as non-draft.
break existing features:
https://wiki.revolutionarygamesstudio.com/wiki/Testing_Checklist
(this is important as to not waste the time of Thrive team
members reviewing this PR)
styleguide.
Before merging all CI jobs should finish on this PR without errors, if
there are automatically detected style issues they should be fixed by
the PR author. Merging must follow our
styleguide.