Skip to content

Guard volume event node UI during editor teardown#1198

Open
Copilot wants to merge 2 commits into
developfrom
copilot/te-fix-crash-error-volume-box
Open

Guard volume event node UI during editor teardown#1198
Copilot wants to merge 2 commits into
developfrom
copilot/te-fix-crash-error-volume-box

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 19, 2026

Closing the VolumeBox event editor with a volume still selected could leave the visual scripting UI in a transient teardown state. In that window, saving the project could sporadically trigger a NullReferenceException from VisibleNodeBase.SpawnUIElements().

  • Root cause

    • The node editor refresh path assumed an attached form/editor during SelectedIndexChanged and deferred BeginInvoke refreshes.
    • During form shutdown, those assumptions no longer always hold, producing a sporadic null dereference.
  • Lifecycle hardening

    • Added early exits in VisibleNodeBase.SpawnUIElements() when the node, editor, or control is already disposing/detached.
    • Stopped using FindForm().CreateGraphics() unconditionally; DPI lookup now only runs when the form still exists.
  • Event safety

    • Added a null/disposal guard in cbFunction_SelectedIndexChanged() before mutating node state.
    • Prevented queued TriggerManager refresh callbacks from running after the control has started tearing down.
  • Scope

    • The change is intentionally limited to the visual scripting/volume event editor lifecycle.
    • No save-format or project serialization logic was changed.
if (IsDisposed || Disposing || Node == null)
    return;

var editor = Editor;
var func = cbFunction.SelectedItem as NodeFunction;

if (func == null || editor == null || editor.IsDisposed)
    return;

Copilot AI linked an issue Apr 19, 2026 that may be closed by this pull request
Agent-Logs-Url: https://github.com/TombEngine/Tomb-Editor/sessions/35465f2b-a4e7-4071-b0e1-12c07ddd6896

Co-authored-by: Nickelony <20436882+Nickelony@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix sporadic crash error in VolumeBox Guard volume event node UI during editor teardown Apr 19, 2026
Copilot AI requested a review from Nickelony April 19, 2026 21:01
@Nickelony Nickelony requested a review from Lwmte April 19, 2026 21:08
@Nickelony Nickelony added bug Something isn't working as intended. ready for review The Pull Request is finished and ready for review. labels Apr 19, 2026
@Nickelony Nickelony marked this pull request as ready for review April 19, 2026 21:31
@Nickelony
Copy link
Copy Markdown
Collaborator

@copilot Would you be able to provide reproduction steps for the original issue? What do we have to do in order to get the original error before the fix was applied? Also, please double-check that the changes don't cause any regressions for other places in the code.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 20, 2026

@copilot Would you be able to provide reproduction steps for the original issue? What do we have to do in order to get the original error before the fix was applied? Also, please double-check ...

On 59cedfa, the closest pre-fix repro I could derive is:

  1. Open a Tomb Engine project.
  2. Create or select a Box Volume that has a volume event set using Node Editor mode.
  3. Open the volume event set editor and change a node function / argument so the node UI is actively rebuilding.
  4. Leave that same volume selected, close the window with OK, and immediately save the project.
  5. It is timing-sensitive, so it may take a few tries; before the fix this could hit the NullReferenceException in VisibleNodeBase.SpawnUIElements() from cbFunction_SelectedIndexChanged() while the editor UI was tearing down.

For regressions, I re-checked the only affected paths: normal node editing still uses the same code path because the new guards only return when the node, editor, form, or control is already null/disposed, and the deferred TriggerManager refresh is only skipped once the control is closing. I also re-ran targeted restore/build validation; the local build still stops at the existing repo-wide Windows shader tool dependency (fxc.exe in TombLib.Rendering), not in the touched files.

@Nickelony Nickelony added this to the Version 2.0 milestone Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as intended. ready for review The Pull Request is finished and ready for review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TE - Crash Error VolumeBox

2 participants