fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
24.72k stars 1.37k forks source link

Random crash in DocTab #3909

Closed matwachich closed 11 months ago

matwachich commented 1 year ago

Checklist

Describe the bug

DocTab randomly crashing when selecting an Item

How to reproduce

I have no idea why sometimes it happens, and sometimes no...

Screenshots

panic: runtime error: index out of range [1] with length 1

goroutine 38 [running]:
fyne.io/fyne/v2/container.(*docTabsRenderer).scrollToSelected(0xc0004e01b0?)
        C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.4-rc1.0.20230516195251-56dd0f3e0f32/container/doctabs.go:362 +0x189
fyne.io/fyne/v2/container.(*docTabsRenderer).Refresh(0xc0004e01b0)
        C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.4-rc1.0.20230516195251-56dd0f3e0f32/container/doctabs.go:267 +0x65 
fyne.io/fyne/v2/widget.(*BaseWidget).Refresh(0x7ff7f51bbf40?)
        C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.4-rc1.0.20230516195251-56dd0f3e0f32/widget/widget.go:139 +0x2e     
fyne.io/fyne/v2/container.(*DocTabs).Select(0xc0001160a0, 0xc001ee48e0?)
        C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.4-rc1.0.20230516195251-56dd0f3e0f32/container/doctabs.go:144 +0x37
main.(*MainWindow).TabAdd(0x7ff7f5743520, {0x7ff7f51bae60, 0xc0020cf880})
        C:/Users/Matwachich/Documents/Programmation/KissEMR/KissEMR/main_window.go:154 +0x147
main.(*tabHomeSearch).openOrCreatePatient(0xc0005044e0?, {0x93, 0xac, 0xb1, 0x43, 0x6b, 0x59, 0x45, 0xed, 0xb1, ...})
        C:/Users/Matwachich/Documents/Programmation/KissEMR/KissEMR/tab_home.go:237 +0x88
main.newTabHomeSearchListItem.func1()
        C:/Users/Matwachich/Documents/Programmation/KissEMR/KissEMR/tab_home.go:289 +0x5a
main.(*tabHomeSearchListItem).Tapped(0xc003348780, 0xc000448901?)
        C:/Users/Matwachich/Documents/Programmation/KissEMR/KissEMR/tab_home.go:334 +0x42
fyne.io/fyne/v2/internal/driver/glfw.(*window).mouseClickedHandleTapDoubleTap.func1()
        C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.4-rc1.0.20230516195251-56dd0f3e0f32/internal/driver/glfw/window.go:634 +0x26
fyne.io/fyne/v2/internal/driver/common.(*Window).RunEventQueue(0x0?)
        C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.4-rc1.0.20230516195251-56dd0f3e0f32/internal/driver/common/window.go:35 +0x3e
created by fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).createWindow.func1
        C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.4-rc1.0.20230516195251-56dd0f3e0f32/internal/driver/glfw/window.go:946 +0x136
exit status 2

Example code

I have a complexe code base, I could not reproduce the bug with simple code.

Fyne version

develop v2.3.4-rc1.0.20230516195251-56dd0f3e0f32

Go compiler version

1.20

Operating system and version

Windows 10

Additional Information

No response

matwachich commented 1 year ago

Re-opening this because I encountered it again in develop (v2.3.6-0.20230618081107-a984816deecd)

"runtime error: index out of range [0] with length 0"
Stack:
     3  0x00007ff7a1bdc734 in fyne.io/fyne/v2/container.(*docTabsRenderer).scrollToSelected
         at C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.6-0.20230618081107-a984816deecd/container/doctabs.go:362
     4  0x00007ff7a1bdb5d1 in fyne.io/fyne/v2/container.(*docTabsRenderer).Refresh
         at C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.6-0.20230618081107-a984816deecd/container/doctabs.go:267
     5  0x00007ff7a1bb79c9 in fyne.io/fyne/v2/widget.(*BaseWidget).Refresh
         at C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.6-0.20230618081107-a984816deecd/widget/widget.go:139
     6  0x00007ff7a1bdab85 in fyne.io/fyne/v2/container.(*DocTabs).Remove
         at C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.6-0.20230618081107-a984816deecd/container/doctabs.go:132
     7  0x00007ff7a1f01308 in main.(*MainWindow).Setup.func16.1
         at c:/Users/Matwachich/Documents/Programmation/EMR Made Simple/emr-made-simple/src/main_window.go:78
     8  0x00007ff7a1f11d51 in main.(*TabContentModels).onClose
         at c:/Users/Matwachich/Documents/Programmation/EMR Made Simple/emr-made-simple/src/tab_content_models.go:148
     9  0x00007ff7a1f01276 in main.(*MainWindow).Setup.func16
         at c:/Users/Matwachich/Documents/Programmation/EMR Made Simple/emr-made-simple/src/main_window.go:75
    10  0x00007ff7a1f031a9 in main.(*MainWindow).TabCloseAll
         at c:/Users/Matwachich/Documents/Programmation/EMR Made Simple/emr-made-simple/src/main_window.go:223
    11  0x00007ff7a1f01c57 in main.(*MainWindow).Logout
         at c:/Users/Matwachich/Documents/Programmation/EMR Made Simple/emr-made-simple/src/main_window.go:131
    12  0x00007ff7a1fa5beb in main.(*MainWindow).Logout-fm
         at <autogenerated>:1
    13  0x00007ff7a1b971f5 in fyne.io/fyne/v2/widget.(*menuItem).trigger
         at C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.6-0.20230618081107-a984816deecd/widget/menu_item.go:205
    14  0x00007ff7a1b96d2d in fyne.io/fyne/v2/widget.(*menuItem).Tapped
         at C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.6-0.20230618081107-a984816deecd/widget/menu_item.go:151
    15  0x00007ff7a1db2262 in fyne.io/fyne/v2/internal/driver/glfw.(*window).mouseClickedHandleTapDoubleTap.func1
         at C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.6-0.20230618081107-a984816deecd/internal/driver/glfw/window.go:631
    16  0x00007ff7a1d78ed3 in fyne.io/fyne/v2/internal/driver/common.(*Window).RunEventQueue
         at C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.6-0.20230618081107-a984816deecd/internal/driver/common/window.go:35
    17  0x00007ff7a1db5dcb in fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).createWindow.func1.1
         at C:/Users/Matwachich/go/pkg/mod/fyne.io/fyne/v2@v2.3.6-0.20230618081107-a984816deecd/internal/driver/glfw/window.go:943
matwachich commented 1 year ago

https://github.com/fyne-io/fyne/issues/4009 Same issue here. Good that he could reproduce with a simple code.

andydotxyz commented 1 year ago

I think we are still missing code to reproduce this error?

andydotxyz commented 1 year ago

I tried removing all and adding new tab but could not cause the crash. Looking for help understanding how to make this happen.

matwachich commented 1 year ago

I still unable to reproduce with simple code. I just encountered the crash in 2.4.0, while closing a Tab.

The DocTab was containing 3 tabs, I close one (idx 2), so there remains only 2 tabItems (idx 0 and 1)

The crash happened inside docTab.CloseIntercept, while .Refresh()ing inside docTab.Remove(*container.TabItem). image

Inside Refresh, first .Layout is called. As I understand, this function is charged (among other tasks) to update the DocTab buttons according to docTab.Items. image

But something happens in it that prevents it to update buttons. image

Just after Refresh, the function scrollToSelected is called (because the closed tab was selected). So here happens the crash because the buttons container contains only 1 button (it should contain 2, because the docTabs has 2 items). image image image


I really hope this will help understand this silly intermittent crash!

andydotxyz commented 1 year ago

There is an additional interaction (and thread) through your use of OnClosing. Does it happen if you move the Remove call into the CloseIntercept?

matwachich commented 1 year ago

The OnClosing function most of the time does nothing, it is built like this because certain ITab must do cleanup when closed.

The OnClosed method does nearly nothing involving fyne, only database access, sometimes dialog display. It will call the function passed to it when everything is OK for closing the tab.

In the particular case of the last crash encountered, the OnClosed does strictly nothing other than directly calling the function passed to it.

But I will investigate more in this direction...

matwachich commented 1 year ago

Always happening... Even after code simplification.

Here is the code responsible for managing docTabs in my application: https://pastebin.com/56DWJG2R

By the way, the crash not only happens on tab closing, but also when adding the very first tab at application launch.

matwachich commented 1 year ago

Would it be possible to just add a simple check in the begining of docTabsRenderer.scrollToSelected to see if r.docTabs.current is not out of bound of buttons.Objects? This would temporarly correct this (very rare) crash, at the cost of not scrolling to selected tab

matwachich commented 1 year ago

Something like this? https://github.com/fyne-io/fyne/pull/4269

andydotxyz commented 11 months ago

Landing for release branch