-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
stack overflow when calling SetRowHeight in table UpdateCell callback #5007
Comments
Is it possible to please provide a code sample that actually replicates this issue? The snippet included does not compile. |
Hi, Personally, I don't use 'table.SetRowHeight' inside the 'update' function because it seems logical that an issue will occur, given that the row size increases in height, it will trigger a table update again and this will create an infinite loop that will ultimately result in a stack overflow (This is what I believe, but I might be mistaken). So, to keep it simple, you put 'table.SetRowHeight' right after creating your table, something like this: var table *widget.Table
// ...
// ...
table = widget.NewTable(length, create, update)
for i := range items.EnvItems {
table.SetRowHeight(i, rowHeight)
}
return table And it works perfectly. Here's a complete example: package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
var (
// Dummy data
chats = [][]string{
{"title0", "content0", "author0"},
{"title1", "content1", "author1"},
{"title2", "content2", "author2"},
{"title3verylongwithlotofwords", "content3", "author3"},
{"title4", "content4", "author4"},
{"title5", "content5", "author5"},
{"title6verylongwithlotofwords", "content6", "author6"},
{"title7verylongwithlotofwords", "content7", "author7"},
{"title8", "content8", "author8"},
{"title9verylongwithlotofwords", "content9", "author9"},
}
// Set to false to disable text truncation.
// It will use manual width sizing instead.
withTruncation bool = true
)
func main() {
mainApp := app.NewWithID("a.b.c.d")
mainWin := mainApp.NewWindow("test table")
table := openedDialogs()
mainWin.SetContent(container.NewStack(table))
mainWin.CenterOnScreen()
mainWin.Resize(fyne.NewSize(800, 400))
mainWin.ShowAndRun()
}
func openedDialogs() *widget.Table {
// Get length
length := func() (int, int) { return len(chats), 3 }
// Create label
create := func() fyne.CanvasObject {
return widget.NewLabel("O(∩_∩)O哈哈~")
}
// Update table
update := func(id widget.TableCellID, cell fyne.CanvasObject) {
label := cell.(*widget.Label)
label.SetText(chats[id.Row][id.Col])
if withTruncation {
// auto truncation method (change 'withTruncation' to 'false' to disable it)
label.Truncation = fyne.TextTruncateEllipsis
}
}
// Create table
table := widget.NewTableWithHeaders(length, create, update)
// Adjust height/width
for i, v := range chats {
for col, text := range v {
switch col {
case 0:
if len(text) > 25 {
table.SetRowHeight(i, 50)
}
case 1:
// do something
case 2:
// do...
}
if !withTruncation {
// manual cell width sizing method (change 'withTruncation' to 'true' to disable it)
width := fyne.MeasureText(text, theme.TextSize(), fyne.TextStyle{}).Width
table.SetColumnWidth(col, width+theme.Padding()*5)
}
}
}
return table
} |
Thank you for your answer. This is indeed a temporary solution that can be used |
I have modified the example code. Could you please review it again |
Thanks, I can now replicate the issue. PR open |
I had the same problem but could not use the proposed solution. I wordwrap Text in Cells and thus the columnHeight changes, if the contents or the columnWidth changes. Therefore I used SetRowHeight in the UpdateCell call. If fixed the initial problem with a simple variable based saveguard, preventing that I use SetRowHeight again during the Refresh, that it caused: I have fixed this with the introduction of a Mutex to guard all accesses the columnWidths and rowHeights maps in table.go and now it all runs smoothly. I tried to make a fork of fyne and made the changes to table.go there but failed to execute the tests as go test ..... FAILs in the canvas.go which I didn't touch :-(
2024/07/25 21:52:08 Fyne error: Failed to focus object which is not part of the canvas’ content, menu or overlays. Hope this helps anyone. |
Fixed on develop and will get picked into v2.5.1 |
Thank You!! |
Checklist
Describe the bug
I create a table widget . But the row height is uncertain when it created, only until use other variable return fields.
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0x1407a780420 stack=[0x1407a780000, 0x1409a780000]
fatal error: stack overflow
runtime stack:
runtime.throw({0x104b739ce?, 0x16ee4adb8?})
/usr/local/go/src/runtime/panic.go:1023 +0x40 fp=0x16ee4ad50 sp=0x16ee4ad20 pc=0x103016420
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1103 +0x478 fp=0x16ee4aef0 sp=0x16ee4ad50 pc=0x103030fa8
runtime.morestack()
/usr/local/go/src/runtime/asm_arm64.s:341 +0x70 fp=0x16ee4aef0 sp=0x16ee4aef0 pc=0x103049010
goroutine 115 gp=0x1400f26ce00 m=5 mp=0x14000100008 [running]:
fyne.io/fyne/v2/widget.splitLines(0x140002491f0)
/Users/xjy/go/pkg/mod/fyne.io/fyne/v2@v2.5.0/widget/richtext.go:1097 +0x3e8 fp=0x1407a780420 sp=0x1407a780420 pc=0x104999418
fyne.io/fyne/v2/widget.lineBounds(0x140002491f0, 0x0, 0x0, 0x436a0000, {0x436a0000, 0x4193e000}, 0x1407a780be8)
/Users/xjy/go/pkg/mod/fyne.io/fyne/v2@v2.5.0/widget/richtext.go:943 +0x54 fp=0x1407a780a20 sp=0x1407a780420 pc=0x104997714
fyne.io/fyne/v2/widget.(*RichText).updateRowBounds.func1({0x140104a03f0, 0x1, 0x1})
when i remove this code :
table.SetRowHeight(id.Row, 50).
Everything has become normal
How to reproduce
just use i provide code
Screenshots
Example code
when i use this code:
Fyne version
v2.5.0
Go compiler version
1.21
Operating system and version
macOS Sonoma 14.5 Apple M2
Additional Information
No response
The text was updated successfully, but these errors were encountered: