public unsafe void TestCacheClearWithDispose() { var a0 = BlobAssetReference <int> .Create(0); var a1 = BlobAssetReference <int> .Create(1); var a2 = BlobAssetReference <float> .Create(2.0f); var k0 = FromInt(a0.Value); var k1 = FromInt(a1.Value); var k2 = FromFloat(a2.Value); Assert.IsTrue(m_Store.TryAdd(k0, a0)); Assert.IsTrue(m_Store.TryGet <int>(k0, out var ra0)); Assert.IsTrue(m_Store.TryAdd(k1, a1)); Assert.IsTrue(m_Store.TryGet <int>(k1, out var ra1)); m_Store.ResetCache(true); Assert.Throws <InvalidOperationException>(() => a0.GetUnsafePtr()); Assert.Throws <InvalidOperationException>(() => a1.GetUnsafePtr()); Assert.IsFalse(m_Store.TryGet(k0, out ra0)); Assert.IsFalse(m_Store.TryGet(k0, out ra1)); Assert.IsTrue(m_Store.TryAdd(k2, a2)); Assert.IsTrue(m_Store.TryGet <float>(k2, out var ra2)); }
public void Start() { defaultWorld = World.DefaultGameObjectInjectionWorld; entityManager = defaultWorld.EntityManager; blobAssetStore = new BlobAssetStore(); blobAssetStore.ResetCache(true); CreateEntity3(); }
public void ConvertColliderPrefabs(UnityEngine.GameObject floorCollider, UnityEngine.GameObject solidCollider) { using (var blobAssetStore = new BlobAssetStore()) { var conversionSettings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore); var floorColliderPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(floorCollider, conversionSettings); var solidColliderPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(solidCollider, conversionSettings); _floorColliderPrefab = EntityManager.GetComponentData <PhysicsCollider>(floorColliderPrefab).Value; _solidColliderPrefab = EntityManager.GetComponentData <PhysicsCollider>(solidColliderPrefab).Value; // the BlobAssetStore will contain collider information, which it would try to dispose. This data is handled by UnitPhysics, so we dont want that. resetting the cache seems to do the trick. i hope this has no unintended consequences blobAssetStore.ResetCache(false); } }