Static Shared Pointers Nullify After Hot Reloads

Hi,

I believe I’ve found a bizarre bug and I’m struggling to think of an answer.

In short, I’m using a plugin that has a runtime and editor module. A key runtime file has a TSharedPtr<IEditorAccess> with a get and set method. An editor class’ constructor calls the set method.

The TSharedPtr<IEditorAccess> is defined in the CPP file as TSharedPtr<IEditorAccess> URuntimeClass::EditorAccess = nullptr;. Every time a hot reload occurs, this line is run, nullifying the pointer without the editor class’s constructor running again to set it.

I also believe the resource being pointed to isn’t destroyed as no logs or breakpoints run in the class’ destructor.

Some solutions I’ve thought of:

  1. Disable the xxx = nullptr during hot reloads. However, not sure if hot reloads are detectable
  2. Create the IEditorAccess during the Get method, if the variable is null. However, if the previous resource isn’t GC’d then this would be a memory leak?
  3. Try a different smart pointer. Maybe one from the standard library that will definitely clean up the resource
  4. Disallow hot reloading for the plugin. Not sure if this is even possible

Is there any way around this or possible solutions I could try?

Kind regards,
James