How forward/copy Ly allocators to external dlls?

:vulcan_salute:

I’m guessing this is an easy question as Ly has plenty of dlls linked which each other. In my SamplesProject I can see this lines:

// When module is linked dynamically, we must set our gEnv pointer.
// When module is linked statically, we’ll share the application’s gEnv pointer.
gEnv = system.GetGlobalEnvironment();

Is this suppose to be enough to have working the allocators in an external dll?
Thanks!

Hi @Prompt, when build the engine in profile mode it generates .dlls for every gem, but even so they all statically link AZCore where most of the memory allocator code lives. When you build a release build everything is linked statically and you get a single .exe of your game. Are you writing an external dll that is not a gem .dll? If so you may want to look at the Substance gem, and how it exposes functions to allocate memory for the 3rdparty substance libraries.

Thanks for the info @petrocket. I learned it by hard during the weekend and here is the result :slight_smile:

I followed the module creation of a gem with IGem.h, although I’m having now a hard time of how to reflect the data on Ly Editor as my newly created component has no ComponentDescriptor* != nullptr. I’m investigating how generate it and replace the old one in the system + update the editor inspector.

If you can point me to the info I’ll appreciate that.

Hi @Prompt, are you following the steps in the docs? https://docs.aws.amazon.com/lumberyard/latest/userguide/component-entity-system-pg-intro.html

I’m not sure how you expecting your component to be reflected, but after you register your component (https://docs.aws.amazon.com/lumberyard/latest/userguide/component-entity-system-pg-registering-your-component.html) Lumberyard will call the static ::Reflect() method on your component (https://docs.aws.amazon.com/lumberyard/latest/userguide/component-entity-system-reflect-component.html)

One gotcha is to make sure your component AZ::Edit::Attributes::AppearsInAddComponentMenu is set to “Game” and not “System”. When you create a Gem, the generated system component is set to “System” and sometimes developers try to use this component on their in-game entities and it doesn’t work.

Hope this helps!

Thanks for the links @petrocket, however, my issue was about to unregister the previous component descriptor and register the new one.

So for the record:

if (!AZ::Environment::IsReady())
{
    //
    // Redirect allocators
    //
    InitializeDynamicModule(userData);
    AZ::Module* moduleDataPtr = CreateModuleClass();
    //
    // Say goodbye to the previous component
    //
    AZ::ComponentDescriptor* descriptor = GetCurrentDescriptor<T>();
    descriptor->ReleaseDescriptor();    // Deletes and "un-reflects" the descriptor
    //
    // Register the new descriptor
    //
    T::CreateDescriptor();
}

(currently is done in a cleaner way and standard as Ly gems. But ReleaseDescriptor is what I was searching for :slight_smile:

I’ll do another video to show how works atm. Thanks a lot for the support @petrocket.

I think here you’ll see my current issue: https://youtu.be/AXmGmAgbvhE
I’ll create another post.