Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Error while changing realities. #320

Open
jo9182 opened this issue Oct 2, 2024 · 9 comments
Open

[BUG] Error while changing realities. #320

jo9182 opened this issue Oct 2, 2024 · 9 comments

Comments

@jo9182
Copy link
Author

jo9182 commented Oct 2, 2024

After I unpaused, it appeared that the game hadn't frozen as my health was depleting from enemies and I could still fire my weapons, it's just that nothing displayed except what you see in the screenshot. The errors vanished upon me switching weapons.

@jo9182
Copy link
Author

jo9182 commented Oct 2, 2024

Screenshot 2024-10-02 1 39 07 PM
Here's this if it's also relevant.

@landgreen
Copy link
Owner

I just want to say that n-gon has some great crashes. The visuals are fun. I'll look into the bug.

@AnnonymousNerd87
Copy link

AnnonymousNerd87 commented Oct 3, 2024 via email

@creator1116
Copy link

you can sometimes get a white screen of death

@corneeme
Copy link

corneeme commented Oct 3, 2024

but it just isn't as visually appealing, and less boring

@Ant-Throw-Pology
Copy link

The only reason the recursive view effect happens is because the error every frame causes ctx.restore to not be called, causing the camera transformations to be applied over and over again.

The error detection code should probably be changed:
Remove

window.addEventListener('error', error => {
    simulation.inGameConsole(`<strong style='color:red;'>ERROR:</strong> ${error.message}  <u>${error.filename}:${error.lineno}</u>`)
});

...because the 'error' event doesn't really work on file:// URLs (it just has a message of 'Script error' and no useful properties) which many people will be playing on (because the github.io site is blocked, they download the repo to play locally)

Replace the loop functions

normalLoop() {
    try {
        simulation.gravity();
        Engine.update(engine, simulation.delta);
        simulation.wipe();
        simulation.textLog();
        if (m.onGround) {
            m.groundControl()
        } else {
            m.airControl()
        }
        m.move();
        m.look();
        simulation.camera();
        level.custom();
        powerUps.do();
        mobs.draw();
        simulation.draw.cons();
        simulation.draw.body();
        if (!m.isBodiesAsleep) mobs.loop();
        mobs.healthBar();
        m.draw();
        m.hold();
        level.customTopLayer();
        simulation.draw.drawMapPath();
        b.fire();
        b.bulletRemove();
        b.bulletDraw();
        if (!m.isBodiesAsleep) b.bulletDo();
        simulation.drawCircle();
        simulation.runEphemera();
    } catch (err) {
        simulation.inGameConsole(`<strong style='color:red;'>ERROR:</strong> ${(error.stack && error.stack.replace(/\n/g, "<br>")) || (error.message + ` <u>${error.filename}:${error.lineno}</u>`)}`);
    } finally {
        ctx.restore();
        simulation.drawCursor();
    }
},
testingLoop() {
    try {
        simulation.gravity();
        Engine.update(engine, simulation.delta);
        simulation.wipe();
        simulation.textLog();
        if (m.onGround) {
            m.groundControl()
        } else {
            m.airControl()
        }
        m.move();
        m.look();
        simulation.camera();
        level.custom();
        m.draw();
        m.hold();
        level.customTopLayer();
        simulation.draw.wireFrame();
        if (input.fire && m.fireCDcycle < m.cycle) {
            m.fireCDcycle = m.cycle + 15; //fire cooldown       
            for (let i = 0, len = mob.length; i < len; i++) {
                if (Vector.magnitudeSquared(Vector.sub(mob[i].position, simulation.mouseInGame)) < mob[i].radius * mob[i].radius) {
                    console.log(mob[i])
                }
            }
        }
        simulation.draw.cons();
        simulation.draw.testing();
        simulation.drawCircle();
        simulation.runEphemera();
        simulation.constructCycle()
    } catch (err) {
        simulation.inGameConsole(`<strong style='color:red;'>ERROR:</strong> ${(error.stack && error.stack.replace(/\n/g, "<br>")) || (error.message + ` <u>${error.filename}:${error.lineno}</u>`)}`);
    } finally {
        ctx.restore();
        simulation.testingOutput();
        simulation.drawCursor();
    }
},

...to have a try...catch...finally with ctx.restore in the finally block, so it always gets called

level.start() (in cycle) should probably also have a try...catch around it to catch any errors from initializing a level

@landgreen
Copy link
Owner

well... this seems like an improvement, but I like the way it crashes... It's cool.

@AnnonymousNerd87
Copy link

AnnonymousNerd87 commented Oct 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants