-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server and Client sharing LuaState in single process PIE #37
Comments
I actually found the cause of this today, but it's a bit of a job to fix it in master. For your case @Ollinator - you will need to ditch the blueprint library. All of the calls use FLuaMachineModule::Get(), which returns the static singleton (this is why singletons aren't so great). This instance is shared between all of the execution state within an editor context - so if you launch editor, then attempt to launch multiple instances (as is the case with a client/server launch), they will be sharing the same lua context in memory. I was able to get my use case working by creating a game instance subsystem and keeping track of my own lua states. Using this method also allows more than 1 instance of a particular LuaState class, since the UClass is being used to key the lua states in LuaMachine. You can create LuaStates like this: Unfortunately, it doesn't solve the issue of the blueprint library using FLuaMachine::Get everywhere... If the moderator decides to refactor this code, I'd highly recommend using Subsystems - it should solve most of these issues. |
Thx bfoo! Yeah, i imagined something like that would be needed. |
Just in case anyone else comes across this thread - the method I described above has the side effect of not working with the lua machine debug tools, since they require the type-keyed map from LuaMachine to populate the states in the debug windows. :( |
I leave this issue opened as it contains lot of useful infos. It is even a boost for merging this long standing patch: #27 |
Hey there!
I've recently played around with LuaMachine and replication and noticed some weirdness going on: When launching 2 instances in PIE using "run in one process" and executing an IsServer() call would report FALSE on the server when executed through an RPC which calls a lua function calling the IsServer() function. The issue (naturally) does not happen when running with multiple processes, so it appears like the two instances somehow share the same luastate.
I've first experienced it in 4.26, but also reproduced it in 4.27 and 5.0, each with latest plugin version available. Also attaching two test projects demonstrating it both in 4.27 and 5.0. Just run them with 2 players and press space on the client, this will execute the chain of functions and print each step on screen and in the log.
LuaTest.zip
LuaTest_UE5.zip
As its a bit complicated to understand perhaps, lets go through the setup step by step! :D
the LuaState defines a function IsServer() which just returns the result of the engines IsServer() to check the state:
A simple Lua script making a table with a single function that just executes the IsServer() function above and compares it with the expected result (which is coming from a native call of the engines IsServer() function):
then, in a test actor, making a copy of the table above and keeping it as a reference for later calls:
in the test actor, a call into the lua function, providing the native result of IsServer():
and finally the chain of RPCs executed in the test actor calling the lua function in each step to report the results of the IsServer() function:
when executing this, this is the print out:
As you can see, both client and server execute within the same lua state, and despite the native call reports to be the server properly, the call from the lua function (executed from the RPC) is reporting on the server to be "Client 0".
I'm quite sure this has to do with the lua state being a singleton, but for some reason client and server share the same singleton instead of creating its own. Not sure if that is easily fixable or at all. Workaround for now is to always run in multiple processes, but this makes testing and debugging really slow and cumbersome...
Maybe I'm also doing something stupid though :D
Thx for your support and that awesome plugin!
The text was updated successfully, but these errors were encountered: