Skip to content

Commit

Permalink
fix: fixing syncvar reading when using bools
Browse files Browse the repository at this point in the history
When using bools they will only take 1 bit, so canRead will return true as there are still 8 bits left in the byte.
We need to check if we are able to read 1 whole byte to see if there are more components to read otherwise it will assume there is another component when there isn't
  • Loading branch information
James-Frowen committed Jul 5, 2021
1 parent ba50c26 commit 31aca8e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Assets/Mirage/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,11 @@ internal void OnDeserializeAll(NetworkReader reader, bool initialState)
reader.ObjectLocator = Client != null ? Client.World : null;
// deserialize all components that were received
NetworkBehaviour[] components = NetworkBehaviours;
while (reader.CanRead())
// check if we can read atleast 1 byte
while (reader.CanReadBytes(1))
{
// todo replace index with bool for if next component in order has changed or not
// the index below was an alternative to a mask, but now we have bitpacking we can just use a bool for each NB index
// read & check index [0..255]
byte index = reader.ReadByte();
if (index < components.Length)
Expand Down

0 comments on commit 31aca8e

Please sign in to comment.