mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
text/v2: add copyCheck to GoTextFaceSource
This commit is contained in:
parent
d2d86fbddd
commit
7a08737326
@ -58,6 +58,8 @@ type GoTextFaceSource struct {
|
||||
|
||||
outputCache map[goTextOutputCacheKey]*goTextOutputCacheValue
|
||||
|
||||
addr *GoTextFaceSource
|
||||
|
||||
m sync.Mutex
|
||||
}
|
||||
|
||||
@ -95,6 +97,7 @@ func NewGoTextFaceSource(source io.ReadSeeker) (*GoTextFaceSource, error) {
|
||||
f: f,
|
||||
id: nextUniqueID(),
|
||||
}
|
||||
s.addr = s
|
||||
runtime.SetFinalizer(s, finalizeGoTextFaceSource)
|
||||
return s, nil
|
||||
}
|
||||
@ -117,6 +120,7 @@ func NewGoTextFaceSourcesFromCollection(source io.ReadSeeker) ([]*GoTextFaceSour
|
||||
f: f,
|
||||
id: nextUniqueID(),
|
||||
}
|
||||
s.addr = s
|
||||
runtime.SetFinalizer(s, finalizeGoTextFaceSource)
|
||||
sources[i] = s
|
||||
}
|
||||
@ -130,7 +134,15 @@ func finalizeGoTextFaceSource(source *GoTextFaceSource) {
|
||||
})
|
||||
}
|
||||
|
||||
func (g *GoTextFaceSource) copyCheck() {
|
||||
if g.addr != g {
|
||||
panic("text: illegal use of non-zero GoTextFaceSource copied by value")
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GoTextFaceSource) shape(text string, face *GoTextFace) (shaping.Output, []glyph) {
|
||||
g.copyCheck()
|
||||
|
||||
g.m.Lock()
|
||||
defer g.m.Unlock()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user