Skip to content

Fixing a crash when exiting or re-entering play mode#6296

Open
Codengineer wants to merge 21 commits into
developfrom
bobd/fix_crash_exit_playmode
Open

Fixing a crash when exiting or re-entering play mode#6296
Codengineer wants to merge 21 commits into
developfrom
bobd/fix_crash_exit_playmode

Conversation

@Codengineer

@Codengineer Codengineer commented May 14, 2026

Copy link
Copy Markdown
Contributor

Fixes UUM-135678, UUM-143767, UUM-135675, UUM-140974
Fixes a series of crash that could occur following memory overflow.

Proposed change(s)

Add tensor buffer bounds checks to prevent allocator corruption on exit (UUM-143767)
Sensor writes during inference could overflow the tensor buffer when
observation size exceeded the model's expected input, silently corrupting
the allocator's internal metadata and causing non-deterministic crashes
on MemoryManager::TryDeallocateWithLabel when exiting Play mode.

Adds a capacity guard to ObservationGenerator's sensor write loop and
bounds capping to all ObservationWriter TensorProxy write paths. Includes
13 regression tests covering overflow scenarios for every write method.

Retested intensively enter-exit play mode cycle on all user provided project and could not get it to crash again while it was crashing almost all the times before. Also tested exiting the editor in play mode in all the affected project as this was another way to trigger some of the crashes

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

https://jira.unity3d.com/browse/UUM-135678
https://jira.unity3d.com/browse/UUM-143767
https://jira.unity3d.com/browse/UUM-135675
https://jira.unity3d.com/browse/UUM-140974

Types of change(s)

  • Bug fix
  • New feature
  • Code refactor
  • Breaking change
  • Documentation update
  • Other (please describe)

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

@montplaisir montplaisir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread com.unity.ml-agents/Runtime/Academy.cs Outdated
Codengineer and others added 3 commits June 16, 2026 11:21
…it (UUM-143767)

Sensor writes during inference could overflow the tensor buffer when
observation size exceeded the model's expected input, silently corrupting
the allocator's internal metadata and causing non-deterministic crashes
on MemoryManager::TryDeallocateWithLabel when exiting Play mode.

Adds a capacity guard to ObservationGenerator's sensor write loop and
bounds capping to all ObservationWriter TensorProxy write paths. Includes
13 regression tests covering overflow scenarios for every write method.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment thread com.unity.ml-agents/Runtime/Inference/GeneratorImpl.cs Outdated
@montplaisir montplaisir self-requested a review June 16, 2026 20:55

@montplaisir montplaisir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good with 2 small fixes to do.

@montplaisir

Copy link
Copy Markdown
Contributor

/crc

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

Comprehensive fix for memory corruption crashes with strong test coverage; a few edge cases in the bounds checking logic could be further hardened.

🤖 Helpful? 👍/👎

Comment thread com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs Outdated
Comment thread com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs Outdated
Comment thread com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants