UE4 dumps my plugin's resources when function returns
I have a Code Plugin that provides a BlueprintFunctionLibrary. The BlueprintFunctionLibrary contains UFUNCTIONs that in turn call functions provided by a third party library. The plugin is loading a third party library by referencing the .lib/.dll/include locations in the Build.cs file. The library is SDL -- UE4's built-in SDL only seems to work for linux and html5, not plain windows, so my plugin brings its own copy of SDL.
It works just fine for all synchronous actions like polling buttons. However, any async calls, such as force feedback, will work correctly up until the point that my UFUNCTION is done executing, then suddenly stop, even if the library call was made in a separate thread. Even if the thread was not spawned by my UFUNCTION, calls to async SDL functions will work while a UFUNCTION in the plugin is executing, and not work otherwise. In all cases the function returns a successful code but doesn't actually activate the hardware. At first I thought I might be doing something dumb like having pointers to stack memory but even after moving everything out of the UFUNCTION I get the same result.
I believe UE4 is doing some dynamic loading and unloading of resources each time one of my UFUNCTIONs is called -- maybe it's the DLL, maybe it's my BlueprintFunctionLibrary's static variables which store plugin state, I am not sure. But something is "going away" when my UFUNCTION returns, and I need it to stick around for the asynchronous library calls.
PS adding a wait to the UFUNCTION, which does make it work, is of course not acceptable since it blocks the main thread.
We have not heard back from you for a while, so I will be marking this post as resolved for internal tracking purposes.
As I mentioned previously, it looks like your sample implementation of the SDL_Haptics subsystem appears to be correct when the SDL_Delay call is included, since all of the example implementations that I have seen include the SDL_Delay call. I am still not certain about the SDL_Haptics subsystem being asynchronous by default, though.
answered Apr 25 '18 at 05:42 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here