#[Solved] Build crashes when accessing BlobArray

1 messages · Page 1 of 1 (latest)

frozen tartan
#

Hey there just having a issue i really can't figure whats wrong. Basicaly my game works fine in editor but not in build mode. It crashes when trying to read a BlobArray from a BlobAsset from a ChunkJob (Confirmed in the crash log).
This BlobAsset is constructed in a baker like so (simplified). There is only one prefab with this baker

// Bakes a polygon collider 2D
struct ColliderData{
  BlobArray<float2> array;
  ...Other data
}

struct ColliderComponent : ISharedComponentData {
  BlobAssetReference<ColliderData> collider;
}

using BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp);
ref var collider = ref blobBuilder.ConstructRoot<ColliderData>();
// setup collider data 

var builderPolys = blobBuilder.Allocate(ref collider.array, lengthOfMyVertices);
// Use builderPolys to build the array ...

var blob = blobBuilder.CreateBlobAssetReference<ColliderData>(Allocator.Persistent);
AddBlobAsset(blob, out _);
AddSharedComponent(new ColliderComponent{ collider = blob });

The baker code works fine, the AddBlobAsset method should help maintain the blob asset alive for it to work on the build side.

On the chunk side, it accesses the shared component containing the blobasset, the code is not out of the ordinary

public unsafe partial struct MyChunkJob : IJobChunk{
      public MyAspect.TypeHandle aspectHandle;
      public SharedComponentTypeHandle<ColliderComponent> colliderHandle;

      public void Execute(in ArchetypeChunk chunk, ... ){
        var aspects = aspectHandle.Resolve(chunk);
        ColliderComponent col = chunk.GetSharedComponent(colliderHandle);

        // The first level works fine, i can access the ColliderData 
        ref ColliderData colliderData = ref col.collider.Value;

        // The second level crashes whenever i access the array length/indices
        var length = colliderData.array.Length;
        // Use the length variable otherwise it is ellided ...
      }
}

Are there anything left i should check that i didn't?

tribal pulsar
#

AddBlobAsset(blob, out _);
shouldn't this line be ref blob

#

how is this compiling?

frozen tartan
#

yes it is a ref just a mistake when i rewrote on discord

tribal pulsar
#

or is it just pseudocode

#

👍

frozen tartan
#

Working on a repro project

frozen tartan
#

Here is the github. The only files to look at in Asset/ are ExampleSystem and PolygonBaker

#

https://github.com/theo97490/ReproBugUnity

When doing this repro, it doesn't crash as it did on in my project (build mode), however it does catch errors when trying to access that blob.

edit: At least i learned that debugging works better without burstcompile (im guessing). Now being able to debug the build i can indeed see that the collider blobref was null

Im sure there is something missing that i don't know

urban prairie
#

just inspect entities

#

in Editor world

frozen tartan
#

I have a subscene called ECS, if i inspect my object (runtime) i can see that the blob has a serialized hash populated. Editor works fine

frozen tartan
#

Closed you mean disabled ?

urban prairie
#

closed meaning closed

#

literally

tribal pulsar
#

Subscenes can be closed or open in editor, unloaded or loaded

#

Just for testing, if you make your component just a regular icd instead of shared does it work?
I don't recall ever putting a blob on a shared component

frozen tartan
#

Still populated but with a different number and it is 2 digit

urban prairie
#

sounds like invalid hash? not sure

frozen tartan
#

Looks like it .. but how ?

urban prairie
#

wait, you put it on shared component?

frozen tartan
#

Yes

urban prairie
#

yeah, that's invalid

#

it won't be remapped

#

you serialized pointer value

#

so as soon as you deallocated what it pointed to - it's invalid pointer

#

or if you ship this to other PC, it will be a pointer to some random memory

frozen tartan
#

Okay that's explains why damn

#

There are baking systems right i don't know how they exactly work

urban prairie
#

Baking is just an entity world that only updates once

#

(or multiple times for live baking)

frozen tartan
#

If i really need a shared component here i make it non shared first and then make it shared after in a system like this

urban prairie
#

I don't see how you need shared component here tbh

#

but you can have both at the same time

#

just add shared component with some random value

#

that matches your blob somehow

#

and at the same time a normal ICD with blob

tribal pulsar
#

Just use the guid of asset or something

frozen tartan
#

Yeah it could work like that if i use a different identifier for my shared component

#

You guys are god sent

#

Thanks a lot again, like i don't even know how i could have gotten this information myself