-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Fix local bounds problems. Swap bounds with localBounds to do the trick. #6365
Conversation
Hmm, this doesn't solve the JSFiddle I presented. On inspection, the |
The sprite still renders wrongly because |
Codecov Report
@@ Coverage Diff @@
## dev #6365 +/- ##
=======================================
Coverage 78.54% 78.54%
=======================================
Files 57 57
Lines 2825 2825
=======================================
Hits 2219 2219
Misses 606 606 Continue to review full report at Codecov.
|
@ivanpopelyshev @bigtimebuddy This fixes the problem! |
I think I will do one more optimization tomorrow: on a container's children, we should swap the transform with a temporary transform instance. Then we won't have to call update-transform again after |
It is important if you could capture this modified bounds behavior in a unit test, preferably one that breaks on dev. That’s the best way to ensure that we don’t have a regression. A good unit test uses only public APIs preferably and considers all the scenarios in which it could be used, including edge cases. |
As I said in the issue:
|
@ivanpopelyshev Your idea could be added in another PR - when it becomes your priority. |
Overrides will not be affected at all. This should be a backward compatible change after I swap the child transforms too. |
@ivanpopelyshev I’m looking for your tests today that should fail with this change. |
OK, I wanted to merge dev into it but made something wrong. Can you please re-do it and push with force? |
c70cece
to
6fc56e1
Compare
OK, never mind, I've rebased it myself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, now I understand how good is that PR:
- It is fixing stupid issue.
- It does not gives us a new fundamental way to store things, it just fixes current problem.
- I like it that
_localBounds
makes sure that subsequent call (c.height
afterc.width
) does not trigger re-updates.
What to change:
- We need tests. I'll help to convert jsfiddle to test and maybe make a test that
width/height
check does not trigger update two times. _localBounds
is one more object. Maybe make it null by default.
Good job!
We have to update all objects (Sprites, e.t.c.) @bigtimebuddy we have a problem that |
@ivanpopelyshev Please recheck the standing of the changes. |
Doesn't work at all in real cases =) DEV: Your: |
@eXponenta I already know. Review the types of changes first and then I’ll fix the bugs today. |
How should we review it when it doesn't works properly? |
@eXponenta Sometimes people don’t like me changing something even if it works |
Don't worry, we'll take care of it in weekend together. |
32e1aac
to
6fc56e1
Compare
@ivanpopelyshev Any updates? |
Cant commit, one test is failing because I added extra condition: two consecutive |
@ivanpopelshev Will look at it in evening |
Yeah, if you manage to adjust |
Looks good, but tests. |
My fault - I made extra test that I thought can be passed with this PR, but it turns out something is wrong with boundsID's. I'm waiting for @SukantPal when he will be free to investigate whether i made a mistake or he did |
…into fix-local-bounds
…hics.clear() shall declare bounds dirty!
@ivanpopelyshev I pushed changes to make the tests to pass. I following breaking changes will occur:
|
Could you help me understand the breaking change more? If you could show some code of what would change, that’d be helpful. |
@bigtimebuddy I'll explain the "breaking" change a bit rigorously as follows: Let's say we have a display-object Now, the local bounds are, by definition, defined as bounds without any transforms applied. That leaves us with: if Previously, Hence, since This assumption is now incorrect with this PR. If Why?By not updating the local bounds when they aren't marked dirty, we prevent unnecessary bounds calculations and transform updates. Future workSimilarly, we could prevent Another use-case of this PRWhen the scene graph is being rendered, it is expected that This PR swaps |
@bigtimebuddy We have a problem with parent containers whose local bounds depend on the transform of children in the parent’a reference frame. I will push a fix for that, if possible. |
@SukantPal, I think the work that you've done here is terrific. I commend you for optimizing these code paths related to caching bounds, because it's subtle, difficult work. One of the challenges of PRs like this, is that I (and probably others on the PixiJS team), don't fully understand the extent to which this may produce unwelcome side-effects for developers. It's one thing add unit-tests, it's another to do a full integration where users heavily rely on bounds. Our goal as an open source library is, most importantly, is to make sure we do no harm. I think it's important that you can work with developers (@themoonrat, @GoodBoyDigital, and others) to test this build into real-world, complex apps and games. As much as you're able to prove and show that this will not negatively impact users, it will be easier to approve. |
@bigtimebuddy I have removed the sync barrier (stopping local-bounds recalculations) so there are no side-effects. I think @ivanpopelyshev would be okay to merge this now. (So this PR now only prevents getLocalBounds from storing its result in this._bounds, preventing corruption this.getBounds(true), via the _localBounds swap). To prevent unnecessary bounds updates, we will need to implement a system where transform updates are propagated up the scene graph. This will be experimented on another branch. |
There's only one thing left - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations @SukantPal with solving the problem that has a trail of dead PR's for years. Now we've covered it with test and it wont be possible to regress.
Btw, I added one more test in my last commit, the one we discussed two days ago.
Hey @SukantPal , thanks for this! Going to test this branch on one of our more layout heavy games! Will let you know how it goes :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works like a boss!
Fix for #6355
By swapping the
_bounds
object with_localBounds
, we are preventingcalculateBounds
from editing the world-bounds.Also, I am syncing the changes in the
_boundsID
with the world-boundsupdateID
. This will prevent the world-bounds from getting recalculated in the nextgetBounds(true)
if it was already update-to-date.npm run lint
)npm run test
)