Skip to content

Example code is broken out of the box #111

@noxabellus

Description

@noxabellus
git clone https://github.com/lance-gg/tinygames.git
cd tinygames/asteroids
npm i
npm run start
> lance-asteroids@5.0.0 start
> node dist-server/main.js

Listening on 3000
file:///home/nox/projects/tinygames/asteroids/node_modules/lance-gg/dist/server/lance-gg.js:28931
            this.id = this.gameEngine.world.getNewId();
                                      ^

TypeError: Cannot read properties of null (reading 'world')
    at new GameObject (file:///home/nox/projects/tinygames/asteroids/node_modules/lance-gg/dist/server/lance-gg.js:28931:39)
    at new PhysicalObject2D (file:///home/nox/projects/tinygames/asteroids/node_modules/lance-gg/dist/server/lance-gg.js:29153:9)
    at new Asteroid (file:///home/nox/projects/tinygames/asteroids/dist-server/common/Asteroid.js:2:16)
    at Serializer.deserialize (file:///home/nox/projects/tinygames/asteroids/node_modules/lance-gg/dist/server/lance-gg.js:29578:19)
    at Asteroid.prunedStringsClone (file:///home/nox/projects/tinygames/asteroids/node_modules/lance-gg/dist/server/lance-gg.js:14344:33)
    at AsteroidsServerEngine.serializeUpdate (file:///home/nox/projects/tinygames/asteroids/node_modules/lance-gg/dist/server/lance-gg.js:30028:27)
    at AsteroidsServerEngine.syncStateToClients (file:///home/nox/projects/tinygames/asteroids/node_modules/lance-gg/dist/server/lance-gg.js:30004:34)
    at Array.map (<anonymous>)
    at AsteroidsServerEngine.step (file:///home/nox/projects/tinygames/asteroids/node_modules/lance-gg/dist/server/lance-gg.js:29973:33)
    at Scheduler.callTick (file:///home/nox/projects/tinygames/asteroids/node_modules/lance-gg/dist/server/lance-gg.js:29531:22)

similar results can be seen for all the example projects here; In Serializer.deserialize there is

let obj = new objectClass(null, {}, {});

and then the GameObject constructor looks like this

    constructor(gameEngine, options, props) {
        super();
        this.gameEngine = gameEngine;
        if (options && options.id)
            this.id = options.id;
        else
            this.id = this.gameEngine.world.getNewId();
        this.playerId = (props && props.playerId) ? props.playerId : 0;
        this.components = {};
    }

So with options empty, it tries to use the null gameEngine that was passed to get a new id. Beyond this I can't really understand what's happening as I'm not really familiar with all the code paths yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions