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
Ensure we never access out of range table dividers, fixes #2018 #2026
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on the fix - but I don't understand why the 0 width theme is required to test it
Theme with separator thickness equals to zero is a special case that causes the current code accesses out of range dividers, indeed that is the root cause of #2018, so I thought it would be useful if there is a test for that situation, doesn't it? |
If that is the root cause, it should of course be fixed. |
Just FYI we just got the following in another PR tests - is this the same bug? The widget tests don't have 0 width separators.
|
Well the real problem is the initial state (like the case when a window is created and it reports zero size and then the real size), in that case almost all related variables to the renderer are 0 and the value of the theme.SeparatorThickness is decisive: for y := theme.Padding() + t.scroll.Offset.Y - float32(count) - separatorThickness; y < t.scroll.Offset.Y+t.t.size.Height && i < rows-1 && divs < len(t.dividers); y += t.cellSize.Height + separatorThickness {
if y < theme.Padding()+t.scroll.Offset.Y {
continue
}
....
} If you run that test in the current develop branch it will fail 100% of the times with index out of range.
It is the same bug (index out of range), but different situation for sure. This PR would solve that bug too as now it is impossible to go out of range (unless there is a race condition and that is the root cause of the others?). For example #1887 is a different situation but with the same bug, however that situation is harder to replicate and so doing a test for that case is so difficult. The test with SeparatorThicknessZero theme is consistent (and a special case), but certainly is not the best way to test this in a general form, should I remove it? |
Thanks for the summary. It would be a shame not to test so you're probably right to leave it. Oh, and the private type should be at the end of the file, below the exported test methods. |
Yes, that would be great, but currently it is not possible because there isn't a public theme object available to be embedded, is it?
You are right, I forgot it, sorry, will update :) |
This example works - could be adapted to reduce your line count I am sure: type bigTextTheme struct {
fyne.Theme
}
func (b *bigTextTheme) Size(n fyne.ThemeSizeName) float32 {
if n == theme.SizeNameText {
return 22
}
return b.Theme.Size(n)
} That can be set like follows: a.Settings().SetTheme(&bigTextTheme{test.Theme()}) |
Oh that's great, I didn't know that it is possible to embed an interface 😅 into a struct. |
@andydotxyz updated :) |
Thanks. I guess this should be added to the |
You're welcome.
Yes, it should. In fact, any bug fixes that don't involve new methods or breaking changes should be added IMHO :) |
Description:
Fixes #2018 and possibly #1887.
Checklist: