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

Uncaught TypeError: Cannot read property 'fps' of undefined #171

Closed
chumo opened this issue Nov 23, 2015 · 4 comments
Closed

Uncaught TypeError: Cannot read property 'fps' of undefined #171

chumo opened this issue Nov 23, 2015 · 4 comments

Comments

@chumo
Copy link

chumo commented Nov 23, 2015

With the last version of the library (https://github.com/liabru/matter-js/blob/master/build/matter.min.js), when I run the engine, I always get the following error in the console:

Uncaught TypeError: Cannot read property 'fps' of undefined

every single frame of the animation. The message is only visible when I render the engine with the flag showDebug: true, so it is not fatal, but still annoying. Anybody knows the reason?

Thanks,
Jesús

@mfdorst
Copy link

mfdorst commented Dec 4, 2015

Well, I don't know exactly how to fix it, but I see that in commit dcdc43d the fps attribute was moved from the Engine class to the Runner class.

As of df5f16c the error is on line 269 of src/render/Render.js:

text += "fps: " + Math.round(metrics.timing.fps) + space;

where metrics is defined as var metrics = engine.metrics
Apparently Render.debug needs to be updated to use Runner.fps instead.

@mfdorst
Copy link

mfdorst commented Dec 5, 2015

What's confusing is that when you run the demo it works just fine. But after a bit of spelunking I found this on line 81 of demo/js/Demo.js:

// pass through runner as timing for debug rendering
demo.engine.metrics.timing = demo.runner;

So the demo code hacks its way around the problem by passing in a reference to the runner.

@mfdorst
Copy link

mfdorst commented Dec 5, 2015

Really it seems that the only problem here is that Render.debug is trying to display information it has no business knowing about. Since the game loop is decoupled from the engine, it should be the programmer's job to display an FPS counter if they want one, since they're in charge of driving the game loop themselves.

I propose that the fps counter simply be removed from Render.debug in the release version.

@liabru
Copy link
Owner

liabru commented Dec 5, 2015

Looks like I didn't properly maintain backwards compatibility when I refactored this.
I've added a check that should prevent this error.

@anthropomorphic you're right about this and it's something I hope to address when I get around to working on decoupling the renderers, but this should at least prevent the errors for the time being

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

3 participants