pixijs: getLocalBounds() causes transform to update, can cause problems in render pass

I have found that calling DisplayObject#getLocalBounds can mess things up if called while the renderer is rendering. This is because this method will cause a transform update after removing the parent.

In many parts of @pixi/core, we use DisplayObject#getBounds(false), which will not update the transform to include the parent’s transform. This is an inherent weakness in PixiJS and should be properly documented.

To solve the problem, you must call update-transform after getting the local bounds.

target.getLocalBounds();
target.updateTransform();

However, code like Container#width (getter) already uses the getLocalBounds() method. This means that trying to access a display-object’s width will result in failure of the renderer.

Maybe we should solve this? @ivanpopelyshev thoughts?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

@bigtimebuddy Sorry for the delay, here is a demo: https://jsfiddle.net/ShukantPal/bjc0te8x/7/.

At line 26, the getLocalBounds() method causes the Sprite to render at 128x128 instead of the scaled up 256x256 (due to 2x scale of stage).