liabru / matter-js

a 2D rigid body physics engine for the web ▲● ■
MIT License
16.8k stars 1.96k forks source link

Calling Render.create when engine.pairs is populated throws Maximum call stack size exceeded #286

Open staff0rd opened 8 years ago

staff0rd commented 8 years ago

See this pen.

If pairs are evident on the Engine instance, Render.create hits infinite recursion inside Common.Extend due to body.parent === body circular reference for body.id === 1.

Adding a Pairs.clear(engine.pairs) is a workaround for this issue as can also be seen in the pen.

liabru commented 8 years ago

Looks like a bug, thanks. For now I assume you don't actually need to call Engine.update that early, so you can avoid this?

staff0rd commented 8 years ago

In that minimal example sure. In my actual project I use that renderer for debug purposes, and it can be instantiated at any time, including after the engine has been instantiated/updated, so i'm using the Pairs.clear workaround for now.

staff0rd commented 7 years ago

Just some updates in case anyone is googling (I came across this one again just now).

When this occurs;

liabru commented 7 years ago

This seems to be related to #241. I guess I need to re-think the way that Common.extend works, or potentially even stop using it in create functions.

Titozzz commented 7 years ago

I have this issue too. In my case I destroyed the canvas containing the render so i'm trying to create a new one and that happens

Zodiase commented 3 years ago

I also hit this. I only need the rendered view when debugging so I'm trying to dynamically display/hide the rendering.

Running Render.create results in image

Any workarounds at the moment?


I'm currently creating a dedicated element for the renderer regardless if I need to show the rendering, and dynamically append it to DOM and start rendering when I need it and stop the rendering and remove it from DOM when I'm done with it. The reference to the dedicated element sticks around.

liabru commented 3 years ago

@Zodiase did you have any luck with the earlier suggested workaround using Pairs.clear(engine.pairs)?