panic when render given Chinese rune
zhangpy opened this issue · comments
panic: runtime error: slice bounds out of range
goroutine 1 [running, locked to thread]:
github.com/google/gxui/drivers/gl.(*glyphPage).add(0xc2081d01e0, 0xc200008703, 0xc2080802c0, 0xc34680)
src/github.com/google/gxui/drivers/gl/glyph_page.go:138 +0x567
github.com/google/gxui/drivers/gl.(*glyphTable).get(0xc2081ce3a0, 0xc200008703, 0xc2080802c0, 0x3f4ccccd3f4ccccd)
src/github.com/google/gxui/drivers/gl/glyph_table.go:28 +0xf8
github.com/google/gxui/drivers/gl.(*font).DrawRunes(0xc20802e280, 0xc2081cc000, 0xc20800a638, 0x2, 0x2, 0xc2080205c0, 0x2, 0x2, 0x3f4ccccd3f4ccccd, 0x3f8000003f4ccccd, ...)
src/github.com/google/gxui/drivers/gl/font.go:110 +0x2bb
github.com/google/gxui/drivers/gl.func·006(0xc2081cc000, 0xc2081ce360)
src/github.com/google/gxui/drivers/gl/canvas.go:177 +0x103
github.com/google/gxui/drivers/gl.(*canvas).draw(0xc208012690, 0xc2081cc000, 0xc2081ce360)
src/github.com/google/gxui/drivers/gl/canvas.go:67 +0xf7
github.com/google/gxui/drivers/gl.func·005(0xc2081cc000, 0xc2081ce360)
src/github.com/google/gxui/drivers/gl/canvas.go:163 +0x28c
github.com/google/gxui/drivers/gl.(*canvas).draw(0xc208012620, 0xc2081cc000, 0xc2081ce360)
src/github.com/google/gxui/drivers/gl/canvas.go:67 +0xf7
github.com/google/gxui/drivers/gl.(*viewport).render(0xc2081be000)
src/github.com/google/gxui/drivers/gl/viewport.go:276 +0x1bd
github.com/google/gxui/drivers/gl.func·048()
src/github.com/google/gxui/drivers/gl/viewport.go:317 +0xe9
github.com/google/gxui/drivers/gl.(*driver).driverLoop(0xc208020040)
src/github.com/google/gxui/drivers/gl/driver.go:82 +0x75
github.com/google/gxui/drivers/gl.StartDriver(0xc32f60)
src/github.com/google/gxui/drivers/gl/driver.go:51 +0x2b9
main.main()
test/main.go:36 +0x2a
package main
import (
"io/ioutil"
"log"
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/themes/dark"
)
func appMain(driver gxui.Driver) {
theme := dark.CreateTheme(driver)
window := theme.CreateWindow(1024, 800, "Hi")
window.SetBackgroundBrush(gxui.CreateBrush(gxui.Gray50))
fontData, err := ioutil.ReadFile("../fonts/simkai.ttf") //font comes from windows
if err != nil {
log.Fatalf("error reading font: %v", err)
}
font, err := driver.CreateFont(fontData, 512)
if err != nil {
panic(err)
}
label := theme.CreateLabel()
label.SetFont(font)
label.SetText("辰蜃")
window.AddChild(label)
window.OnClose(driver.Terminate)
}
func main() {
gl.StartDriver(appMain)
}
If I change the font size to 500505, it looks like this:512, it will panic.
when font size is 505
If I change text to only one rune, it will not panic.
label.SetText("辰")
label.SetText("蜃")
Please let me know if there is anything I could do to help the issue. thanks.
It works. thanks, ben.