fabriziospadaro / SpriteSheetRenderer

Spritesheet renderer is a powerful Unity ECS API to render massive numbers of sprites using the new dots stack, taking full advantage of Jobs, DynamicBuffers and ComputeBuffer

Home Page:https://www.linkedin.com/in/fabrizio-spadaro/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NullReferenceException in CreateBuffersContainer after upgrading to Entities 0.17.0-preview.42

TarasMartynyuk opened this issue · comments

Trying to launch the SingleSpriteSheetSpawner demo, and getting callstack below. In short, DynamicBufferManager.CreateBuffersContainer crashes when creating this archetype:

var archetype = EntityManager.CreateArchetype(
          typeof(SpriteIndexBuffer),
          typeof(MatrixBuffer),
          typeof(SpriteColorBuffer),
          typeof(SpriteSheetMaterial),
        typeof(UvBuffer)
        );

It works on previous version - 0.16.0-preview.21
Interestingly, creating the same archetype elsewhere - I did it in Convert() of SingleSpriteSheetSpawner - works.

Callstack:

NullReferenceException: Object reference not set to an instance of an object
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <a5172b547855499dbc8d9d50552f0797>:0)
Unity.Entities.EntityManager.GetCheckedEntityDataAccess () (at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/EntityManager.cs:76)
Unity.Entities.EntityManager.CreateArchetype (Unity.Entities.ComponentType[] types) (at Library/PackageCache/com.unity.entities@0.17.0-preview.41/Unity.Entities/EntityManagerCreateArchetype.cs:29)
DynamicBufferManager.CreateBuffersContainer (SpriteSheetMaterial material) (at Assets/SpriteSheetRenderer/Scripts/DynamicBufferManager.cs:58)
DynamicBufferManager.GenerateBuffers (SpriteSheetMaterial material, System.Int32 entityCount) (at Assets/SpriteSheetRenderer/Scripts/DynamicBufferManager.cs:46)
SpriteSheetManager.RecordSpriteSheet (UnityEngine.Sprite[] sprites, System.String spriteSheetName, System.Int32 spriteCount) (at Assets/SpriteSheetRenderer/Scripts/SpriteSheetManager.cs:134)
SingleSpriteSheetSpawner.Convert (Unity.Entities.Entity entity, Unity.Entities.EntityManager eManager, GameObjectConversionSystem conversionSystem) (at Assets/SpriteSheetRenderer/Examples/SingleSpawnSprite[DEMO]/Script/SingleSpriteSheetSpawner.cs:36)

The problem was with a Singleton-like EntityManager static variable in DynamicBufferManager (and one more class). It was initialized unless null, but at some point Unity changed EntityManager from class to struct, so the default value of variable was never null, and it was left uninitialized.

The problem was with a Singleton-like EntityManager static variable in DynamicBufferManager (and one more class). It was initialized unless null, but at some point Unity changed EntityManager from class to struct, so the default value of variable was never null, and it was left uninitialized.

Yeah, this was 100% correct.
I just fix this along with other problems while upgrading to the latest unity version and entitas v0.17.0-preview.42