matter-js icon indicating copy to clipboard operation
matter-js copied to clipboard

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

Open staff0rd opened this issue 9 years ago • 7 comments

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.

staff0rd avatar Sep 09 '16 02:09 staff0rd

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?

liabru avatar Sep 09 '16 09:09 liabru

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 avatar Sep 09 '16 09:09 staff0rd

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

When this occurs;

  • Chrome (v55) will just crash without showing any error, with the "Aw, snap" screen.
  • Microsoft Edge (v38) will throw the error "Out of stack space" linking to this line.

staff0rd avatar Nov 07 '16 01:11 staff0rd

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.

liabru avatar Jan 15 '17 15:01 liabru

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

Titozzz avatar May 11 '17 21:05 Titozzz

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.

Zodiase avatar Mar 16 '21 07:03 Zodiase

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

liabru avatar Mar 20 '21 12:03 liabru