Hi,
we are successfully using the C++ PlayFab client. But we found one problem with the client API.
Our software is embedded into a 3rd party software via runtime plugin mechanisms. Therefore our code has to be able to be completely started & shutdown during the host application's runtime.
This also applies to our PlayFab C++ client API code.
We are using the threaded API mode to avoid stalling the host application, i.e.:
PlayFabSettings::threadedCallbacks = true;
This means the callbacks when calling the PlayFab API will be handled by some PlayFab internal thread (Transport Plugin Thread)
The problem now arises if the host application requests our plugin to shutdown and some PlayFab API requests are still in flight, i.e. being processed by the PlayFab background thread.
We have found no documentation or C++ example code that shows how to wait for the HTTP Transport thread to finish all outstanding API calls before exiting.
Or in other words, if we don't have a way to join our apps' "main" thread with the PlayFab HTTP transport thread, our app will just continue to shutdown and release all memory / class instances.
And after that the PlayFab HTTP thread will still run and eventually try to call some callbacks into our code, which by this time is fully deallocated by this point which will lead to all kinds of crashes obviously.
We found one trick / hack by reading through the PlayFab C++ sources to avoid any callbacks being called after our app was destroyed:
PlayFabPluginManager::SetPlugin((std::shared_ptr<IPlayFabPlugin>)nullptr, PlayFabPluginContract::PlayFab_Transport);
This guarantees that no PlayFab callbacks will be triggered after this line, and lets us safely exit our application code.
This works because the PlayFab HTTP plugin will join the underlying thread (that would also call the callbacks into our code) in its destructor (see https://github.com/PlayFab/XPlatCppSdk/blob/master/code/source/playfab/PlayFabIXHR2HttpPlugin.cpp#L18-L34)
By looking at this code however, you can see that the thread will not join after all outstanding requests where handled, but immediately after the current request from the queue was processed.
This means that some events that were queued to be written by our application would be lost / not written if the happen to be emitted right before our application has to be shut down!
So while avoiding the callback crash problem, this is far from ideal for us.
Please let me know if I missed some API that would let us safely shutdown the PlayFab API while also not losing any API calls that were made.
Thanks