[PE] Add extra checks to ensure OnDestroy doesn't throw #166

Merged
ManlyMarco merged 3 commits from ondes into main 2025-09-11 17:04:45 +00:00
ManlyMarco commented 2025-09-11 17:01:15 +00:00 (Migrated from github.com)
No description provided.
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2025-09-11 17:02:00 +00:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull Request Overview

This PR adds defensive null checks to OnDestroy methods across multiple classes to prevent exceptions when objects are destroyed. The changes ensure that null reference exceptions don't occur during cleanup operations.

Key changes:

  • Added null checks before invoking delegate events and accessing collections
  • Wrapped event unsubscriptions in null guards for parent objects
  • Added additional null checks for UI components and transform hierarchies

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Core.PoseEditor/PoseController.cs Added null-conditional operators for onDestroy event and _poseControllers collection
Core.PoseEditor/CharaPoseController.cs Added null check before removing from _charaPoseControllers collection
Core.PoseEditor/AMModules/IKEditor.cs Wrapped event unsubscriptions in null check for _parent
Core.PoseEditor/AMModules/DynamicBonesEditor.cs Added null check for _parent before unsubscribing from events
Core.PoseEditor/AMModules/CollidersEditor.cs Added comprehensive null checks for collider cleanup and parent validation
Core.PoseEditor/AMModules/ClothesTransformEditor.cs Protected event unsubscriptions with null check for _parent
Core.PoseEditor/AMModules/BoobsEditor.cs Added null check for _parent before event unsubscription
Core.PoseEditor/AMModules/BonesEditor.cs Wrapped event unsubscriptions in null check for _parent
Core.PoseEditor/AMModules/BlendShapesEditor.cs Added null checks for _parent and _imguiBackground components

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

## Pull Request Overview This PR adds defensive null checks to OnDestroy methods across multiple classes to prevent exceptions when objects are destroyed. The changes ensure that null reference exceptions don't occur during cleanup operations. Key changes: - Added null checks before invoking delegate events and accessing collections - Wrapped event unsubscriptions in null guards for parent objects - Added additional null checks for UI components and transform hierarchies ### Reviewed Changes Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment. <details> <summary>Show a summary per file</summary> | File | Description | | ---- | ----------- | | Core.PoseEditor/PoseController.cs | Added null-conditional operators for onDestroy event and _poseControllers collection | | Core.PoseEditor/CharaPoseController.cs | Added null check before removing from _charaPoseControllers collection | | Core.PoseEditor/AMModules/IKEditor.cs | Wrapped event unsubscriptions in null check for _parent | | Core.PoseEditor/AMModules/DynamicBonesEditor.cs | Added null check for _parent before unsubscribing from events | | Core.PoseEditor/AMModules/CollidersEditor.cs | Added comprehensive null checks for collider cleanup and parent validation | | Core.PoseEditor/AMModules/ClothesTransformEditor.cs | Protected event unsubscriptions with null check for _parent | | Core.PoseEditor/AMModules/BoobsEditor.cs | Added null check for _parent before event unsubscription | | Core.PoseEditor/AMModules/BonesEditor.cs | Wrapped event unsubscriptions in null check for _parent | | Core.PoseEditor/AMModules/BlendShapesEditor.cs | Added null checks for _parent and _imguiBackground components | </details> --- <sub>**Tip:** Customize your code reviews with copilot-instructions.md. <a href="/IllusionMods/HSPlugins/new/main/.github?filename=copilot-instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Create the file</a> or <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">learn how to get started</a>.</sub>
@ -578,27 +578,36 @@ namespace HSPE.AMModules
public override void OnDestroy()
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-09-11 17:01:59 +00:00

This line should be protected with a null check for _parent like the other event unsubscriptions in the method. Currently it will throw a null reference exception if _parent is null when _isLoneCollider is true.

            if (_parent != null)
                _parent.onUpdate -= Update;
This line should be protected with a null check for `_parent` like the other event unsubscriptions in the method. Currently it will throw a null reference exception if `_parent` is null when `_isLoneCollider` is true. ```suggestion if (_parent != null) _parent.onUpdate -= Update; ```
Sign in to join this conversation.
No description provided.