Skip to content

Conversation

JetLua
Copy link

@JetLua JetLua commented Jul 7, 2020

fix: #6744

fixed: https://jsfiddle.net/JetLu/w501jpxk/

label.text += '100'
app.render()

Only in step 2 will Text.updateText be triggered, but it's too late.

Text.updateText -> Text.updateTexture -> Sprite._onTextureUpdate -> Transform.onChange

Text update transform property lags behind render.

This PR may be only a temporary solution.

image

@bigtimebuddy
Copy link
Member

@@ -165,6 +165,11 @@ export class Text extends Sprite
{
const style = this._style;

if (!style)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the updateText in the set text method, but why the check for no style here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
this.text triggers the set before this.style

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can switch their places

@JetLua
Copy link
Author

JetLua commented Jul 8, 2020

Could you check out the failing test?
https://github.com/pixijs/pixi.js/pull/6751/checks?check_run_id=847661289#step:7:1333

I changed the content of the unit-test because the width is 1 when text = \n

https://jsfiddle.net/JetLu/xnhftc31/

@bigtimebuddy
Copy link
Member

Would it be possible to add a new unit test for this case? If we do find a better solution, would be good to prevent a regression.

@JetLua
Copy link
Author

JetLua commented Jul 8, 2020

Would it be possible to add a new unit test for this case? If we do find a better solution, would be good to prevent a regression.

hmm, there's no need to add new unit tests. I'm just correcting that value.

// use: https://pixijs.download/dev/pixi-legacy.js

const label = new PIXI.Text("\n");

label.updateText() // Without this line,output: 3

console.log(label.canvas.width) // output: 1

@bigtimebuddy
Copy link
Member

Oh I get it! Awesome.

@bigtimebuddy bigtimebuddy added this to the v5.3.1 milestone Jul 8, 2020
@@ -713,6 +713,7 @@ export class Text extends Sprite
}
this._text = text;
this.dirty = true;
this.updateText(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit wary of this change, as I think it'll bring performance issues for fast changing text.

Text in PixiJS has always been 'lazy'. So if you updated text a million times within 1 frame..... it doesn't matter, the texture for text only got updated when it comes through to render.
Now we're saying, every time you change the text, it's going to update that texture immediately.

That's a different performance profile which may negatively effect content out there - I'm thinking of high scores or numbers counting up super fast.

Copy link
Author

@JetLua JetLua Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is worth considering. Another option is to call updateTransform manually in updateTexture.

But that's just repeating the calculation. So it's a temporary solution.

I'll try to optimize it later.

@JetLua JetLua requested review from themoonrat and bigtimebuddy July 8, 2020 08:13
@JetLua
Copy link
Author

JetLua commented Jul 8, 2020

@ivanpopelyshev
Copy link
Collaborator

need _recursivePostUpdateTransform or something like that

@JetLua
Copy link
Author

JetLua commented Jul 11, 2020

need _recursivePostUpdateTransform or something like that

3Q, updated

@@ -394,6 +394,9 @@ export class Text extends Sprite

baseTexture.setRealSize(canvas.width, canvas.height, this._resolution);

// Recursively updates transform of all objects from the root to this one
(this as any)._recursivePostUpdateTransform();
Copy link
Member

@bigtimebuddy bigtimebuddy Jul 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better fix, however, can you please remove as any. Keeping it like this masks these API when we have to refactor things later.

The approach to deal with private APIs that are used internally, is to remove the access modifier (in this case private) from the original method. We can use documentation flagging to make sure it's not "public" for users.

https://github.com/pixijs/pixi.js/blob/3f90364d02b11b4fef1645df2bedac3e9b2b121e/packages/display/src/DisplayObject.ts#L283

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes,. this really should not be private

@bigtimebuddy bigtimebuddy added the ✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t label Jul 12, 2020
@bigtimebuddy bigtimebuddy merged commit eb5e5bc into pixijs:dev Jul 12, 2020
@JetLua JetLua deleted the fix/6744 branch July 14, 2020 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fixed width text renders in wrong size for one frame whenever the text is changed
4 participants