lance-gg / lance

Multiplayer game server based on Node.JS
https://lance-gg.github.io/
Apache License 2.0
1.59k stars 168 forks source link

Bug in ClientEngine - handleInboundMessage/Serializer.deserialize #103

Open dev-zetta opened 5 years ago

dev-zetta commented 5 years ago

There is a bug in method handleInboundMessage in ClientEngine.

/media/maxli/Data/dev/OpenArcanum/node_modules/lance-gg/es5/serialize/Serializer.js:98 Uncaught TypeError: First argument to DataView constructor must be an ArrayBuffer
    at new DataView (<anonymous>)
    at Serializer.deserialize (/media/maxli/Data/dev/OpenArcanum/node_modules/lance-gg/es5/serialize/Serializer.js:98)
    at NetworkTransmitter.deserializePayload (/media/maxli/Data/dev/OpenArcanum/node_modules/lance-gg/es5/network/NetworkTransmitter.js:111)
    at Client.handleInboundMessage (/media/maxli/Data/dev/OpenArcanum/node_modules/lance-gg/es5/ClientEngine.js:448)
    at Client.handleInboundMessage (Client.js:170)
    at Client.step (/media/maxli/Data/dev/OpenArcanum/node_modules/lance-gg/es5/ClientEngine.js:339)
    at Renderer.runClientStep (/media/maxli/Data/dev/OpenArcanum/node_modules/lance-gg/es5/render/Renderer.js:144)
    at Renderer.draw (/media/maxli/Data/dev/OpenArcanum/node_modules/lance-gg/es5/render/Renderer.js:99)
    at Renderer.draw (Renderer.js:27)
    at renderLoop (/media/maxli/Data/dev/OpenArcanum/node_modules/lance-gg/es5/ClientEngine.js:220)

The DataView expects a ArrayBuffer, but plain Buffer is passed in constructor. The workaround is to override handleInboundMessage in ClientEngine and convert the buffer to ArrayBuffer :

  handleInboundMessage(syncData) {
    let buffer = Uint8Array.from(syncData.dataBuffer)
    syncData.dataBuffer = buffer.buffer
    super.handleInboundMessage(syncData)
  }

This works. However is quite inefficient IMHO. Any chance to fix this any soon? Running in Electron 3.X.

namel commented 5 years ago

From the code, it seems that the server sends an ArrayBuffer. See https://github.com/lance-gg/lance/blob/f38918d332eb5ddad691e4b30b20728f25e967d9/src/serialize/Serializable.js#L54

Maybe socket.io changed the data type, or this is an electron issue?