Skip to content
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

Deleting a component retrieved with TryGet results in engine IndexOutOfRange error #6648

Open
trundlr opened this issue Oct 20, 2024 · 1 comment

Comments

@trundlr
Copy link

trundlr commented Oct 20, 2024

Describe the bug

In Micro Mayhem, I am refactoring some of the code, and received an error while destroying a component fetched within a TryGet:

if ( Components.TryGet( out WardrobeCamera tempCamera ) )
	tempCamera.Destroy();

The error:

Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at Sandbox.Utility.HashSetEx`1.EnumerateLocked(Boolean nullChecks)+MoveNext() in C:\build\_work\sbox\sbox\engine\Sandbox.System\Collections\HashSetEx.cs:line 124
   at Sandbox.Scene.Update() in C:\build\_work\sbox\sbox\engine\Sandbox.Game\Scene\Scene\Scene.Tick.cs:line 153
   at Sandbox.Scene.SharedTick() in C:\build\_work\sbox\sbox\engine\Sandbox.Game\Scene\Scene\Scene.Tick.cs:line 229
   at Sandbox.Scene.GameTick() in C:\build\_work\sbox\sbox\engine\Sandbox.Game\Scene\Scene\Scene.Tick.cs:line 278
   at Sandbox.Game.Frame() in C:\build\_work\sbox\sbox\engine\Sandbox.Game\Game\Game.Scene.cs:line 33
   at Sandbox.GameInstanceDll.Tick() in C:\build\_work\sbox\sbox\engine\Sandbox.GameInstance\GameInstanceDll.cs:line 278
   at Sandbox.EngineLoop.FrameStart() in C:\build\_work\sbox\sbox\engine\Sandbox.Engine\EngineLoop.cs:line 212
   at Sandbox.EngineLoop.RunFrame(CMaterialSystem2AppSystemDict appDict, Boolean& wantsQuit) in C:\build\_work\sbox\sbox\engine\Sandbox.Engine\EngineLoop.cs:line 64

To Reproduce

  1. Use TryGet and Destroy the component
  2. Observe error

Expected behavior

No error

Media/Files

No response

Additional context

No response

@matekdev
Copy link

matekdev commented Oct 20, 2024

We were getting the same error with the following code. I imagine it has something to do with removing the component from whatever internal hash set when it is destroyed.

if ( _modelPhysics.IsValid() )
	_modelPhysics.Destroy();

Image

If you need a repro contact me on discord (it is a part of a larger project and is private on GitHub).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To triage
Development

No branches or pull requests

2 participants