lance-gg / lance

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

Serializer causes a crash if netScheme has a string #133

Closed Pro1d closed 4 years ago

Pro1d commented 4 years ago

I created a DynamicObject that contains a STRING netscheme attribute.

export default class MyObject extends DynamicObject {
  static get netScheme() {
    return Object.assign({
      text: { type: BaseTypes.TYPES.STRING }
    }, super.netScheme);
  }

  constructor(gameEngine, options, props) {
    super(gameEngine, options, props);
    this.text = "???";
  }

  syncTo(other) {
    super.syncTo(other);
    this.text = other.text.clone();
  }
}

When I add this object to the world (gameEngine.addObjectToWorld()) from a my own ServerEngine class, it produces an error at run time in Serializer.writeDataView() due to this STRING attribute: TypeError: Cannot read property 'length' of undefined, at the file/line: https://github.com/lance-gg/lance/blob/master/src/serialize/Serializer.js#L104

The code run correctly, if I change the type of the attribute to a number type.

Note: it seems that there is a similar problem with LIST attribute.

Pro1d commented 4 years ago

The error was mine, I did something wrong in my code (I am quite new to javascript). Sorry for the noise :pray:

BTW, Excellent library! Good job :)

namel commented 4 years ago

thanks!