diff --git a/text/v2/multi.go b/text/v2/multi.go index a44169fdb..8797255f4 100644 --- a/text/v2/multi.go +++ b/text/v2/multi.go @@ -32,9 +32,10 @@ type MultiFace struct { // NewMultiFace creates a new MultiFace from the given faces. func NewMultiFace(faces ...Face) *MultiFace { - return &MultiFace{ - faces: faces, - } + m := &MultiFace{} + m.faces = make([]Face, len(faces)) + copy(m.faces, faces) + return m } // Metrics implements Face. diff --git a/text/v2/text_test.go b/text/v2/text_test.go index 21b258012..a76051d27 100644 --- a/text/v2/text_test.go +++ b/text/v2/text_test.go @@ -240,3 +240,14 @@ func TestUnhashableFace(t *testing.T) { } } } + +func TestMultiFace(t *testing.T) { + faces := []text.Face{text.NewStdFace(bitmapfont.Face)} + f := text.NewMultiFace(faces...) + img := ebiten.NewImage(30, 30) + text.Draw(img, "Hello", f, nil) + + // Confirm that the given slice doesn't cause crash. + faces[0] = nil + text.Draw(img, "World", f, nil) +}