Skip to content
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

RichTextLabel's bbcode_text property is not fully updated during _ready #12884

Closed
Tracked by #39144
willnationsdev opened this issue Nov 13, 2017 · 5 comments
Closed
Tracked by #39144

Comments

@willnationsdev
Copy link
Contributor

willnationsdev commented Nov 13, 2017

Operating system or device, Godot version, GPU Model and driver (if graphics related):
Windows 10
Godot 3.0

Issue description:
If, in the _ready() function, you assign a new value to bbcode_text and then call get_total_character_count() or get_line_count(), the variables are not correct. If you then call the same functions in _process or something after _ready, they have the correct values.

Steps to reproduce:
Run a scene with the RichTextLabel root node and the following script:

func _ready():
    bbcode_text = "[u]u[/u]"
    print(get_line_count())
    print(get_total_character_count())

func _process(delta):
    pass
    # print(get_line_count())
    # print(get_total_character_count())
@akien-mga akien-mga added this to the 3.0 milestone Nov 13, 2017
@willnationsdev
Copy link
Contributor Author

Somehow, that's really messed up. XD there's gotta be some deeper level bug associated with that then. I mean, if you update the data in a property, then the property's data should be updated the next time you read from it. Even if it means the name of this Issue needs to be changed, I'd prefer to find what the problem is and make it more known / addressable for the average user to understand. Maybe someday a community fix can be made.

@bojidar-bg
Copy link
Contributor

Does calling scroll_to_line before get_line_count make it magically work?

@akien-mga akien-mga removed this from the 3.0 milestone Dec 16, 2017
@scmccarthy
Copy link
Contributor

I looked into this a bit, and it's a slightly more general problem than only within the _ready function. For example, the following will also produce an incorrect character count:

func _process(delta):
    bbcode_text = "[u]u[/u]"
    print(get_total_character_count())

(Result: 0)

(Side note: I didn't have any trouble with the line count being correct, contrary to the original report. Not sure if this has been incidentally fixed in the meantime or what.)

The issue is that character count (probably among other variables, I didn't look at all of them) is a cached value, and the validity of the cache is only checked when the program internals think it needs checking. This means it gets checked (and recomputed) when you call scroll_to_line as bojidar-bg astutely asked about, as well as when it needs to draw itself, which presumably happens frequently. The validity does NOT get checked when merely asking for the value itself.

In essence, though a lot of the properties and functions on RichTextLabel are exposed, they don't really seem to be designed for that; they're just designed for internal use. The same applies to #12881 and #12882 - the relevant functions work properly for their internal use but present a puzzling and unpredictable interface to end users.

Given that, it might be appropriate to take a step back from the bug and think about what publicly available functions and properties of RichTextLabel are actually desired and useful to expose.

@KoBeWi
Copy link
Member

KoBeWi commented Nov 22, 2020

Still valid in 3.2.4 beta2

@KoBeWi
Copy link
Member

KoBeWi commented Jan 14, 2022

Works fine in 4.0

@KoBeWi KoBeWi closed this as completed Jan 14, 2022
@KoBeWi KoBeWi added this to the 4.0 milestone Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
@KoBeWi @akien-mga @scmccarthy @bojidar-bg @willnationsdev and others