mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +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
|
outputCache map[goTextOutputCacheKey]*goTextOutputCacheValue
|
||||||
|
|
||||||
|
addr *GoTextFaceSource
|
||||||
|
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +97,7 @@ func NewGoTextFaceSource(source io.ReadSeeker) (*GoTextFaceSource, error) {
|
|||||||
f: f,
|
f: f,
|
||||||
id: nextUniqueID(),
|
id: nextUniqueID(),
|
||||||
}
|
}
|
||||||
|
s.addr = s
|
||||||
runtime.SetFinalizer(s, finalizeGoTextFaceSource)
|
runtime.SetFinalizer(s, finalizeGoTextFaceSource)
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
@ -117,6 +120,7 @@ func NewGoTextFaceSourcesFromCollection(source io.ReadSeeker) ([]*GoTextFaceSour
|
|||||||
f: f,
|
f: f,
|
||||||
id: nextUniqueID(),
|
id: nextUniqueID(),
|
||||||
}
|
}
|
||||||
|
s.addr = s
|
||||||
runtime.SetFinalizer(s, finalizeGoTextFaceSource)
|
runtime.SetFinalizer(s, finalizeGoTextFaceSource)
|
||||||
sources[i] = s
|
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) {
|
func (g *GoTextFaceSource) shape(text string, face *GoTextFace) (shaping.Output, []glyph) {
|
||||||
|
g.copyCheck()
|
||||||
|
|
||||||
g.m.Lock()
|
g.m.Lock()
|
||||||
defer g.m.Unlock()
|
defer g.m.Unlock()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user