Closed matwachich closed 11 months 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
https://github.com/fyne-io/fyne/issues/4009 Same issue here. Good that he could reproduce with a simple code.
I think we are still missing code to reproduce this error?
I tried removing all and adding new tab but could not cause the crash. Looking for help understanding how to make this happen.
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).
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.
But something happens in it that prevents it to update buttons.
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).
I really hope this will help understand this silly intermittent crash!
There is an additional interaction (and thread) through your use of OnClosing
.
Does it happen if you move the Remove
call into the CloseIntercept
?
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...
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.
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
Something like this? https://github.com/fyne-io/fyne/pull/4269
Landing for release branch
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
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