natinusala / borealis

Hardware accelerated, controller and TV oriented UI library for PC and Nintendo Switch (libnx)
Apache License 2.0
260 stars 83 forks source link

Segfault when attempting to render List with no items #37

Closed meganukebmp closed 3 years ago

meganukebmp commented 4 years ago

This crashes. Very likely related to #29 but for BoxLayout.

brls::AppletFrame* rootFrame = new brls::AppletFrame(false, false);
brls::List* myList = new brls::List();
rootFrame->setContentView(myList);
brls::Application::pushView(rootFrame);
meganukebmp commented 4 years ago

This will also crash if the list is populated on exit, as the child objects are destroyed first, leaving the list empty

WerWolv commented 4 years ago

Almost the exact same code (with children in the list) was used in the example and works fine there. Are you sure it's not some other issue? Where does your crash log with addr2line point to?

meganukebmp commented 4 years ago

It crashes Atmosphere entirely. The provided backtrace address does not give anything meaningful with addr2line.

#include <borealis.hpp>

int main() {
    // debug logging for borealis
    brls::Logger::setLogLevel(brls::LogLevel::DEBUG);

    // attempt to initialize borealis
    if (!brls::Application::init("Crash")) {
        brls::Logger::error("Unable to init Borealis application");
        return EXIT_FAILURE;
    }

    brls::AppletFrame* rootFrame = new brls::AppletFrame(false, false);
    brls::List* myList = new brls::List();
    rootFrame->setContentView(myList);

    brls::Application::pushView(rootFrame);

    // Run the app
    while (brls::Application::mainLoop());

    // Exit
    return EXIT_SUCCESS;
}

This program should crash

natinusala commented 4 years ago

Can you try on PC, does it crash too? You'll be able to use proper debugging tools there

meganukebmp commented 4 years ago
[New Thread 8920.0x84c]
[New Thread 8920.0x2a40]
[New Thread 8920.0x1634]
[New Thread 8920.0x167c]
[New Thread 8920.0x724]
[New Thread 8920.0x2358]
[INFO] GL Vendor: ATI Technologies Inc.
[INFO] GL Renderer: Radeon (TM) RX 480 Graphics
[INFO] GL Version: 4.3.13587 Core Profile Context 20.4.2 26.20.15029.27016
[INFO] Window size changed to 1280x720
[INFO] New scale factor is 1.000000
[ERROR] Shared symbols font not found
[INFO] Using Material font
[INFO] Maximum FPS set to 60 - using a frame time of 16.67 ms
[DEBUG] Showing N4brls11AppletFrameE with animation 0
[DEBUG] Showing N4brls4HintE with animation 0

Thread 1 received signal SIGSEGV, Segmentation fault.
brls::View::getY (this=this@entry=0x0) at ../library/lib/view.cpp:430
430         return this->y;
natinusala commented 4 years ago

Full trace maybe?

meganukebmp commented 4 years ago

Sorry

#0  brls::View::getY (this=this@entry=0x0) at ../library/lib/view.cpp:430
#1  0x000000000046c3a0 in brls::ScrollView::updateScrolling (this=0xbb4f960,
    animated=animated@entry=false) at ../library/lib/scroll_view.cpp:145
#2  0x000000000046c507 in brls::ScrollView::draw (this=0xbb4f960,
    vg=0x11d3260, x=0, y=88, width=1280, height=559,
    style=0x4832e0 <brls::Application::currentStyle>, ctx=0x11afd00)
    at ../library/lib/scroll_view.cpp:44
#3  0x00000000004533a8 in brls::View::frame (this=0xbb4f960, ctx=0x11afd00)
    at ../library/lib/view.cpp:104
#4  0x00000000004552fd in brls::AppletFrame::draw (this=0xbb4f570,
    vg=0x11d3260, x=0, y=0, width=1280, height=720,
    style=0x4832e0 <brls::Application::currentStyle>, ctx=0x11afd00)
    at ../library/lib/applet_frame.cpp:170
#5  0x00000000004533a8 in brls::View::frame (this=0xbb4f570, ctx=0x11afd00)
    at ../library/lib/view.cpp:104
#6  0x0000000000450a76 in brls::Application::frame ()
    at ../library/lib/application.cpp:587
#7  0x0000000000450ce6 in brls::Application::mainLoop ()
    at ../library/lib/application.cpp:426
#8  0x000000000047ed85 in main () at ../example/main.cpp:20
natinusala commented 4 years ago

Wait so this is null here? Or am I reading it wrong?

WerWolv commented 4 years ago

The issue is here: https://github.com/natinusala/borealis/blob/master/library/lib/scroll_view.cpp#L145

If the scroll view scrolls without any view being focused, this segfaults. @meganukebmp is it possible that none of the items in your list are focusable?

natinusala commented 4 years ago

Oh yeah, right now it doesn't make sense to use use a ScrollView if none of the items are focusable, which is why I didn't bother handling that scenario. This is one of the 548 edge cases that crash the library at the moment

meganukebmp commented 4 years ago

I dont see why it wouldnt be focuseable given the provided code. My idea was to start a list without any items in it and slowly populate it with items during runtime, seems like a valid use case to me. Anyways for the time being I'll simply push the listbox along with the first item.

natinusala commented 4 years ago

Well I said "if none of the items are focusable", in an empty list there are 0 items that can be focused :stuck_out_tongue:

Not trying to dismiss the case here btw, this is a bug

xfangfang commented 3 years ago

This fixed my problem.

change the ScrollView::getDefaultFocus from:

View* ScrollView::getDefaultFocus()
{
    return this->contentView;
}

to

View* ScrollView::getDefaultFocus()
{
    if (this->contentView)
        return this->contentView->getDefaultFocus();
    return nullptr;
}
natinusala commented 3 years ago

Closed as this issue is solved or made irrelevant by the changes on the yoga branch.