#DynamicComponentTypeHandle & safety system

1 messages · Page 1 of 1 (latest)

signal geyser
#

I have this job and I'm running into an issue I do not fully understand.

I have this exception:

InvalidOperationException: The previously scheduled job HashDataJob reads from the ComponentTypeHandle<Sim.EventStorageSingleton> HashDataJob.JobData.DynamicComponentHandle. You must call JobHandle.Complete() on the job HashDataJob, before you can write to the ComponentTypeHandle<Sim.EventStorageSingleton> safely.

I thought it'd be due to the DynamicComponentTypeHandle, because I hadn't seen this before when using ComponentTypeHandle. So I wrote a version using ComponentTypeHandle instead (for the EventStorageSingleton only).

The error went away, but I got one for LocalTransform as well. I added a hard-coded version for that as well, and i had no more issues.

Then, I removed the hardcoded versions again, and there errors were gone, until I rebooted Unity (odd, I thought this was deterministic, but alright). Since then, I cannot reproduce the issue for the LocalTransform anymore (I do not understand that at all).

Now, only the exception related to Sim.EventStorageSingleton remains, which I started out with, and at least this I now reproduce this consistently. It is triggered from a CompleteDependencyBeforeRW<Sim.EventStorageSingleton>().

Is the dependency system expected to behave differently with DynamicComponentTypeHandle and ComponentTypeHandle ?

#

I also have this exception, which makes as little sense to me as the other one; the dependency has clearly been added to the list of dependencies, so I suspect this is also related to the dynamic component typehandle.

The system Sim.DesyncDetectionDataHashSystem reads Sim.EventStorageSingleton via HashDataJob but that type was not assigned to the Dependency property. To ensure correct behavior of other systems, the job or a dependency must be assigned to the Dependency property before returning from the OnUpdate method.

Perhaps the issues are related to codegen? Or there's a missing feature, or a bug? Or I misunderstand how this should work?

Some ideas to debug would be welcome. ^^'

verbal blade
#

you didn't show how you create type handles

#

my assumption is that you didn't register dependency to system with them

signal geyser
#

just like this

    for (int i = 0, l = _componentTypes.Length; i < l; i++)
    {
        _typeHandles[i] = state.EntityManager.GetDynamicComponentTypeHandle(_componentTypes[i]);
    }

my assumption is that you didn't register dependency to system with them
I don't know what you mean by this, I suppose I missed something; I'll dig through the documentation tomorrow then

verbal blade
signal geyser
#

I am suspecting something like that, but that's what the dynamic handle is for, isn't it?

verbal blade
#

There is either system state relattd overload to get dynamic handle

#

Or you can manually register dependecy

signal geyser
#

Alright, I hoped the system would do that for me when I schedule a job with the dynamic component type handle, but I can do that myself I suppose. I don't remember reading about this in the API 🤔

I'll dig a bit tomorrow, thanks

signal geyser
verbal blade
#

none of EntityManager methods are

signal geyser
#

ah that makes sense of course; however this seems to be the only way to create dynamic component type handles

#

you say manually register dependency but i dont recall seeing such a method

verbal blade
#

did you check SystemState?

#

or systemapi

verbal blade
signal geyser
#

if that's the issue, given all the things done when scheduling jobs, I must say I'm a bit surprised this hasnt been done for us already

verbal blade
#

it's not done because you use EntityManager

#

it's methods specifically meant to be not related to systems

signal geyser
#

I'm a little surprised but I think you were right
if I use state.GetComponentTypeHandle<EventStorageSingleton>(true);, I have no error,
but if I use state.EntityManager.GetComponentTypeHandle<EventStorageSingleton>(true);, I have an error even with a regular type handle

verbal blade
#

just take a look at state overload to see what is done

#

this is pretty much the whole idea behind thread safety

signal geyser
#

I don't know how I missed it, but there exists a GetDynamicComponentTypeHandle inside the state

#

I checked twice at least 🤦

#

im getting old 😂

#

it works, thanks for your patience

I hadn't realized there was a significant difference between the entitymanager and state variants. Mostly because we use Update(ref state) with both, so we're already telling the handles about the system.

signal geyser
#

And so the error message was a bit misleading, since it pointed me to the Dependency property and not to what I was doing wrong.

verbal blade
#

it is quite hard to figure where exactly you failed dependency

signal geyser
#

I'd like to mark the post as resolved but I don't find the option 🤔