Closed
Description
Fyne v2.2.3, Windows 11/21H2, go1.17.11. Crash happens if multiple faces of the same font is used.
Stacktrace:
fatal error: concurrent map writes
goroutine 138 [running]:
runtime.throw({0x21f66c0, 0x48})
C:/Program Files/Go/src/runtime/panic.go:1198 +0x76 fp=0xc0008bd3e8 sp=0xc0008bd3b8 pc=0x2a83f6
runtime.mapassign(0xc0000f85a0, 0xc0008bd5d8, 0xc0008bd490)
C:/Program Files/Go/src/runtime/map.go:585 +0x4d6 fp=0xc0008bd468 sp=0xc0008bd3e8 pc=0x280516
fyne.io/fyne/v2/internal/painter.CachedFontFace({0x0, 0x0, 0x0, 0x0, 0x0}, 0xc0008bd5d8)
C:/Users/go/pkg/mod/fyne.io/fyne/[email protected]/internal/painter/font.go:70 +0x46d fp=0xc0008bd518 sp=0xc0008bd468 pc=0x7884cd
Safeguarding it with RWMutex resolves it.
comp := val.(*fontCacheItem)
comp.facesMutex.RLock()
face := comp.faces[*opts]
comp.facesMutex.RUnlock()
if face == nil {
f1 := truetype.NewFace(comp.font, opts)
f2 := truetype.NewFace(comp.fallback, opts)
face = newFontWithFallback(f1, f2, comp.font, comp.fallback)
comp.facesMutex.Lock()
comp.faces[*opts] = face
comp.facesMutex.Unlock()
}
type fontCacheItem struct {
font, fallback *truetype.Font
faces map[truetype.Options]font.Face
facesMutex sync.RWMutex
}
Race was introduced in this commit: d83ffac
Activity