Engine Subsystem Deinitialize

Hi there,

I have an a subsystem derived from UEngineSubsystem to handle UDP networking. The subsystem starts up UDP sockets, handles communication and closes them down when the subsystem ends. Within in the overridden Deinitialize function, I delete the receiver and close the socket. As I do each of these steps I do put in the log what is happening. It appears that the Deinitialize function might not being called, unless I am doing something wrong. I do not see any of my log entries reported in the Deinitialize function in the log and on occasions the socket is not released properly. This can show up as two situations… 1 - When the socket is not released, I have to restart the computer before I can receive data again (I guess the port is still in use), 2 - The receive thread still appears to be running and causes an exception.

Would you expect UE_LOG calls in the Deinitialize function to appear in the log ?
Any thoughts would be appreciated.

Unreal 4.26.1

Hi .
This is actually a bug. The Deinitialize method *should *be called. The proper location would be UEngine::PreExit() and you will want to call EngineSubsystemCollection.Deinitialize().
Epic are working on a fix for a feature release.

In the meantime, if you don’t have access or don’t wish to change the engine code, you could try calling Deinitialize directly in the destructor of the subsystem, but only if your subsystem has nothing derived from it. Calling a virtual function in the destructor can be dangerous! Or you move your functionality into a non-virtual function, and call that from the subsystem destructor, and from deinitialize. Just remember to remove the destructor call once this issue is fixed in the engine. You can always checkf that the receiver hasn’t been deleted, and that’ll flag up as soon as the cleanup code is called twice (in case you forget about this in the meantime!).

Hope that helps
Malcolm

Is that fixed in 4.27? I just encountered this bug in 4.26, so I’m wondering if I should implement a workaround or just upgrade.