axmolengine / axmol

Axmol Engine – A Multi-platform Engine for Desktop, XBOX (UWP) and Mobile games. (A fork of Cocos2d-x-4.0)
https://axmol.dev
MIT License
922 stars 205 forks source link

FairyGUI problems with text update #1874

Closed paulocoutinhox closed 6 months ago

paulocoutinhox commented 6 months ago
  1. Create a FairGUI GTextField element with any custom font and a simple text, example "test"
  2. Change the text of GTextField in runtime with characters that is not in original text, example "text"

BEFORE CHANGE TEXT

image

AFTER CHANGE TEXT

image

The letter "x" that is not in design mode don't appear when new text have it.

Code:

auto lbMessage = dynamic_cast<fairygui::GTextField *>(getContentPane()->getChild("lbMessage"));
lbMessage->setText("text");

What is wrong?

rh101 commented 6 months ago

What is wrong?

Have you followed it with a debugger to narrow down where the issue is occurring?

paulocoutinhox commented 6 months ago

Sure. Im try debug but i don't understand why it is cutting the chars that is not in the original text. I read all the source code, step by step with debug, but don't make sense to me.

paulocoutinhox commented 6 months ago

The steps is:

void GBasicTextField::setTextFieldText()
{
    if (_templateVars != nullptr)
        _label->setText(parseTemplate(_text.c_str()));
    else
        _label->setText(_text);
}

That call FUILabel.cpp setText:

void FUILabel::setText(std::string_view value)
{
    if (_fontSize < 0)
        applyTextFormat();

    setString(value);
}

That call core/2d/Label.cpp method setString:

void Label::setString(std::string_view text)
{
    if (text.compare(_utf8Text))
    {
        _utf8Text     = text;
        _contentDirty = true;

        std::u32string utf32String;
        if (StringUtils::UTF8ToUTF32(_utf8Text, utf32String))
        {
            _utf32Text = utf32String;
        }
    }
}

And when i changed the text, it set the new string, "text" in my sample, without problems:

image

Don't appear be nothing specific with FairyGUI, since it use Axmol Label.

paulocoutinhox commented 6 months ago

And the TTFConfig of Axmol label is this:

image

The font is ok, it generate the first text of label without problems.

The problems happen when i change the label string/text.

rh101 commented 6 months ago

Don't appear be nothing specific with FairyGUI, since it use Axmol Label.

Have you tested the same font with an ax::Label to see if it has the same issue? If it does not have an issue, then you should compare the behaviour of a standard ax::Label with that of the one used by FairyGUI. Follow it in the debugger to the construction of the texture from the text itself, and you should be able to spot the difference.

paulocoutinhox commented 6 months ago

Hi, sure. Is this I'm doing, but without success. I'm debugging but do not discover the problem.

paulocoutinhox commented 6 months ago

Hi,

I think that there is wrong in my current project, because i create another sample with FairyGUI and axmol Label, and both works fine :(

https://github.com/paulocoutinhox/fairygui-bug

paulocoutinhox commented 6 months ago

In test project it works on both devices.

In my real project it have problems on Android only:

Screenshot_20240503_021149

paulocoutinhox commented 6 months ago

I solve the problems settings correct resolution in design resolution and the text problems is related to threads, because i call JNI somethings and it don't render when come from JNI call (i dont know why, but i call on callback the method runInAxmolThread). Thanks.