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

NullReferenceException on subsequent runs #472

Closed
arthurkehrwald opened this issue Sep 5, 2024 · 2 comments
Closed

NullReferenceException on subsequent runs #472

arthurkehrwald opened this issue Sep 5, 2024 · 2 comments

Comments

@arthurkehrwald
Copy link
Contributor

Any time the Unity editor enters play mode after the initial run, an error message appears.

NullReferenceException: Object reference not set to an instance of an object
Unity.Collections.UnsafeQueueBlockPool.OnDomainUnload (System.Object sender, System.EventArgs e) (at ./Library/PackageCache/[email protected]/Unity.Collections/UnsafeQueue.cs:139)
System.AppDomain.DoDomainUnload () (at <8ce0bd04a7a04b4b9395538239d3fdd8>:0)
@arthurkehrwald
Copy link
Contributor Author

This is caused by the property _eventQueue in PhysicsEngine.cs. If the property and all references to it are removed from the code, the error doesn't happen. It seems like the queue is not getting deallocated, despite the call to Dispose in OnDestroy(). The minimal code required to reproduce the error is simply:

using Unity.Collections;
using UnityEngine;

public class NullException : MonoBehaviour
{
    private NativeQueue<bool> _eventQueue = new(Allocator.Persistent);

    private void OnDestroy()
    {
        _eventQueue.Dispose();
    }
}

Attaching this script to a game object and running the scene twice will cause the described NullReferenceException.

@arthurkehrwald
Copy link
Contributor Author

Fixed in #486

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 a pull request may close this issue.

1 participant