Giter Site home page Giter Site logo

Comments (7)

No3371 avatar No3371 commented on May 29, 2024

I've noticed, in latest documentation EntityReservationSystem is not mentioned at all, but I believe that's not related to this issue. It looks like something happened deep inside the command sending mechanics.

from gdk-for-unity.

No3371 avatar No3371 commented on May 29, 2024

The provided logs is from local managed worker, running the worker in Unity will results in immediate crash. Unity's editor log file catches nothing after "CreateEntity sent!"

from gdk-for-unity.

jamiebrynes7 avatar jamiebrynes7 commented on May 29, 2024

Hey @No3371 I'm sorry you're running into this, can you post the implementation of EntityTemplates.CreateFishTemplate along with the schema for any components you've defined and added to this entity?

from gdk-for-unity.

No3371 avatar No3371 commented on May 29, 2024

Sure.

        public static EntityTemplate CreateFishTemplate (string workerID, byte[] serializedArguments)
        {
            var template = new EntityTemplate();
            template.AddComponent(new Position.Snapshot(), WorkerTypeString);
            template.AddComponent(new W.C.Rotation2D.Snapshot(), WorkerTypeString);  // namespace simplified
            template.AddComponent(new W.F.Fish.Snapshot(), WorkerTypeString); // namespace simplified

            template.SetReadAccess(WorkerTypeString, "PlayerClient");

            return template;
        }

The schemas:

component Fish {
    id = 781;
    uint32 fish_type = 1;
}

component Rotation2D {
    id = 540;
    float degree = 1;
}

from gdk-for-unity.

No3371 avatar No3371 commented on May 29, 2024

I was not sure what components are required for managed AI entities (the example project only got simulated players), so I only added Position. Did I miss anything?

from gdk-for-unity.

jamiebrynes7 avatar jamiebrynes7 commented on May 29, 2024

Hey @No3371, I managed to reproduce the problem and can see the issue:

        var eTemplate = EntityTemplates.CreateFishTemplate(AWorkerConnector.WorkerType, null);
        var request = new WorldCommands.CreateEntity.Request(eTemplate);
        for (int i = 0; i < spawned.Length; i++)
        {
            request.EntityId = reserved[i];
            spatialCommandSystem.SendCommand(request);
        }
        UnityEngine.Debug.Log("CreateEntity sent!");

Inside the WorldCommands.CreateEntity.Request(EntityTemplate template) constructor, we serialize the EntityTemplate into the binary format. This is native memory which is freed by the Worker SDK after Improbable.Worker.CInterop.Internal.CWorker.Connection_SendCreateEntityRequest is finished with it. This means if we reuse the Request object, the second time around you have memory corruption.

To fix, move the WorldCommands.CreateEntity.Request(EntityTemplate template) constructor into the for-loop:

        var eTemplate = EntityTemplates.CreateFishTemplate(AWorkerConnector.WorkerType, null);
        for (int i = 0; i < spawned.Length; i++)
        {
        	var request = new WorldCommands.CreateEntity.Request(eTemplate);
            request.EntityId = reserved[i];
            spatialCommandSystem.SendCommand(request);
        }
        UnityEngine.Debug.Log("CreateEntity sent!");

That being said, this should probably be handled more gracefully than hard-crashing the Editor! I'll raise a ticket to address that.

I've noticed, in latest documentation EntityReservationSystem is not mentioned at all

There's a small docs page on it here https://documentation.improbable.io/gdk-for-unity/docs/entity-reservation-system 😄

from gdk-for-unity.

No3371 avatar No3371 commented on May 29, 2024

Thanks, will try the solution!

There's a small docs page on it here https://documentation.improbable.io/gdk-for-unity/docs/entity-reservation-system 😄

I see.
The ECS Workflow -> commands section does not mentions EntityReservationSystem, that's why I said that, sorry for the reckless comment!

from gdk-for-unity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.