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

Textbox #70

Merged
merged 2 commits into from
Sep 5, 2024
Merged

Textbox #70

merged 2 commits into from
Sep 5, 2024

Conversation

Jarod42
Copy link
Collaborator

@Jarod42 Jarod42 commented Sep 5, 2024

No description provided.

@Jarod42 Jarod42 merged commit a1ee4e3 into kallisti5:master Sep 5, 2024
2 checks passed
@Jarod42 Jarod42 deleted the textbox branch September 5, 2024 11:12
@midwan
Copy link
Collaborator

midwan commented Sep 6, 2024

Hmm, this actually started breaking Amiberry, so I had to roll it back.
Not sure where exactly the problem occurs, but it segfaults as soon as it starts.

@Jarod42
Copy link
Collaborator Author

Jarod42 commented Sep 6, 2024

:-/
From what I (quickly) see from (future) Guichan commits, Text::SetRow is broken/unimplemented. Text Field had a visual issue.
I don't see a crash fix.

I quickly tested with demo provided and no crashes.
I will review the code to see if I see a problem.
Investigating...

@Jarod42
Copy link
Collaborator Author

Jarod42 commented Sep 7, 2024

@midwan : I have found the issue and fix :-)
It is TextField::GetText which returns dangling reference.
Guichan's fix happens in 2 PRs :-)

@midwan
Copy link
Collaborator

midwan commented Sep 8, 2024

Hm, I'm still getting a segfault on startup in Amiberry, even after merging all the latest commits from guisan here. Unless you didn't apply all the fixes yet, there must be something more... I'll see if I have time to dig through it in more detail.

@Jarod42
Copy link
Collaborator Author

Jarod42 commented Sep 8, 2024

Guichan's fix happens in 2 PRs :-)

So it is un-merged https://github.com/Jarod42/guisan/tree/textfield_fix
(in particular
include/guisan/widgets/textfield.hpp

-        const std::string& getText() const;
+        std::string getText() const;

)
(just after https://github.com/Jarod42/guisan/tree/empty_rectangle)

@midwan
Copy link
Collaborator

midwan commented Sep 8, 2024

@Jarod42 I tried that, along with the related change in textfield.cpp, but it doesn't make a difference. It still segfauls on startup for me.

@midwan
Copy link
Collaborator

midwan commented Sep 8, 2024

Putting a few breakpoints in the code, I found where the crash happens:

It starts off here:

void TextField::setText(const std::string& text)
{
    mText->setRow(0, text);
}

which takes us to text.cpp here:

    void Text::setRow(unsigned int row, const std::string& content)
    {
        if (row >= mRows.size()) throw GCN_EXCEPTION("Row out of bounds!");
    }

And I get a Row out of bounds exception eventually.

@midwan
Copy link
Collaborator

midwan commented Sep 8, 2024

It seems to be, that instead of setRow it should be calling setContext. So, I changed it to that, and got further.
The application started up, but I eventually got another segfault, when opening one of the GUI panels.

The crash happened again in text.cpp, specifically here:

    Rectangle Text::getCaretDimension(Font* font) const
    {
        Rectangle dim;
        dim.x = font->getWidth(mRows[mCaretRow].substr(0, mCaretColumn));
        dim.y = font->getHeight() * mCaretRow;
        dim.width = font->getWidth(" ");
        // We add two for some extra spacing to be sure the whole caret is visible.
        dim.height = font->getHeight() + 2;
        return dim;
    }

and more specifically, in this line: dim.x = font->getWidth(mRows[mCaretRow].substr(0, mCaretColumn));

looks like mRows is not initialized maybe?

The callstack was this:

 	libstdc++.so.6!std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::substr(unsigned long, unsigned long) const	
>	gcn::Text::getCaretDimension(const gcn::Text * const this, gcn::Font * font) Line 334	C++
 	gcn::TextField::draw(gcn::TextField * const this, gcn::Graphics * graphics) Line 144	C++
 	gcn::BasicContainer::drawChildren(gcn::BasicContainer * const this, gcn::Graphics * graphics) Line 336	C++
 	gcn::Container::draw(gcn::Container * const this, gcn::Graphics * graphics) Line 86	C++
 	gcn::BasicContainer::drawChildren(gcn::BasicContainer * const this, gcn::Graphics * graphics) Line 336	C++
 	gcn::Container::draw(gcn::Container * const this, gcn::Graphics * graphics) Line 86	C++
 	gcn::Gui::draw(gcn::Gui * const this) Line 198	C++
 	check_input() Line 828	C++
 	amiberry_gui_run() Line 868	C++
 	run_gui() Line 1252	C++
 	gui_init() Line 449	C++
 	real_main2(int argc, TCHAR ** argv) Line 1467	C++
 	real_main(int argc, TCHAR ** argv) Line 1563	C++
 	main(int argc, char ** argv) Line 4409	C++

Looks like text.cpp needs some more fixes first?

@Jarod42
Copy link
Collaborator Author

Jarod42 commented Sep 8, 2024

Thanks for investigation, I will see how/when guichan fixes that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants