Repository navigation
[Client] check skipped IsClientInitialized on networked objects - #1084
Open
jimdroberts wants to merge 1 commit into
Open
jimdroberts wants to merge 1 commit into
jimdroberts wants to merge 1 commit into
Conversation
The IsNetworked guard in CreateIsClientCheck branched to the passed label when the object was networked, so the IsClientInitialized check never ran for networked objects. Branch to the failed label when not networked, matching CreateIsServerCheck.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since 4.6.16, a
[Client]method on a NetworkBehaviour runs whenever its object is networked, whether or not theclient is initialized for that object. This happens on a dedicated server, on a server-only instance, and before
client initialization or after deinitialization.
[Client]guards server-side code paths from running clientlogic, so any such method now executes on servers. The warning is never logged, because the check never fails.
[Server]is not affected.Cause
4.6.16 changed
CreateIsNetworkedCheckto take a branch opcode and target, as the fix for #939 ("Server/Clientattribute not blocking execution when IsNetworked was set to false"). The two callers were given opposite
branches:
CreateIsServerCheck(CodeGenerating/Helpers/NetworkBehaviourHelper.cs:396):CreateIsNetworkedCheck(methodDef, OpCodes.Brfalse, conditionFailedInst), meaning "not networked means fail,otherwise check
IsServerInitialized". This is correct.CreateIsClientCheck(NetworkBehaviourHelper.cs:340):CreateIsNetworkedCheck(methodDef, OpCodes.Brtrue, conditionPassedInst), meaning "networked means passwithout checking
IsClientInitialized". Otherwise it falls through toIsClientInitialized, which is false fora non-networked object.
So the #939 case (not networked) is blocked, but only by accident, and the main case (networked object, client
not initialized) is now allowed. In 4.6.12 the same helper emitted
brfalse endIf, which skipped theinitialization check for non-networked objects. #939 inverted that correctly for
[Server]only.checkIsNetworkedis true only for the instance path (!useStatic) fromQOLAttributeProcessor.cs:141/149.The RPC callers pass
falseand are unaffected.Fix
Emit the same guard as
CreateIsServerCheck:brfalsetoconditionFailedInst. The emitted check becomesif (!GetIsNetworked() || !IsClientInitialized) { log; return default; }.Evidence
Verified by reading the emitted instruction sequences, plus a small interpreter that executes them
(
useStatic = false,checkIsNetworked = true):net=GetIsNetworked(),init=IsClientInitialized/IsServerInitialized. With this change[Client]matches
[Server]on main. The column that matters isnet=1 init=0: a networked object on a server, or notyet initialized on the client. Main runs the method there. (
net=0 init=1is probably unreachable, and is shownfor completeness.)
Compiled with Unity 6000.4's Roslyn with no new errors or warnings.
Behavior change
[Client]methods on networked objects no longer run when the client is not initialized for that object. Theyreturn default and log at the attribute's
Logginglevel, as documented ("Prevents this method from running ifclient is not active") and as 4.6.15 and earlier behaved. Projects that unknowingly relied on these methods
running server-side since 4.6.16 will now see that warning.