mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
text/v2: bug fix: the given slice to MultiFace should be copied
Updates #2845
This commit is contained in:
parent
dfa058a961
commit
fa3ec12731
@ -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.
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user