Author Topic: Issue write/read ushort with int32  (Read 1803 times)

MartinW

  • Guest
Issue write/read ushort with int32
« on: September 17, 2013, 05:41:44 PM »
I have a strange situation where if I mix uint with int, the number are scrambled when I tried to read them back. What could cause this?

uint id = 0;
int x = 0;
int y = 64;
int z = 4;

writer.Write(id);
writer.Write(x);
writer.Write(y);
writer.Write(z);

uint id= reader.ReadUInt16();
int x = reader.ReadInt32();
int y = reader.ReadInt32();
int z = reader.ReadInt32();

id : 0
x : 0
y : 4194304
z : 262144

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Issue write/read ushort with int32
« Reply #1 on: September 18, 2013, 01:18:56 PM »
Because ReadUInt16 reads 2 bytes. UInt is 4 bytes.