Skip to content

crash with go-findfont package #29

@SuperGod

Description

@SuperGod

go version go1.19.3 linux/amd64
gcc (GCC) 12.2.0
system: archlinux

When I use the go-findfont package, if I call it too many times, the program will crash.(In the actual code, of course, I only call setupFont once, but sometimes it still crashes when mixed with other codes)
If I set GOGC=off, the program can run normally,.
So I think maybe the c code incorrectly references some memory in go

crash log:

setupFont
setupFont finished
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x840 pc=0x7f32172c4c29]

runtime stack:
runtime.throw({0x8b9e6d?, 0x2031?})
        /usr/lib/go/src/runtime/panic.go:1047 +0x5d fp=0x7f31ee5e3cb8 sp=0x7f31ee5e3c88 pc=0x50c0fd
runtime.sigpanic()
        /usr/lib/go/src/runtime/signal_unix.go:819 +0x369 fp=0x7f31ee5e3d08 sp=0x7f31ee5e3cb8 pc=0x520289

goroutine 1 [syscall]:
runtime.cgocall(0x58bb10, 0xc000075ea0)
        /usr/lib/go/src/runtime/cgocall.go:158 +0x5c fp=0xc000075e78 sp=0xc000075e40 pc=0x4dca3c
github.com/AllenDang/cimgui-go._Cfunc_igRunLoop(0x17123b0, 0x58b770, 0x58b7e0, 0x58b850, 0x58b930)
        _cgo_gotypes.go:53150 +0x45 fp=0xc000075ea0 sp=0xc000075e78 pc=0x588065
github.com/AllenDang/cimgui-go.GLFWwindow.Run.func1(0x0?)
        /home/super/code/go/pkg/mod/github.com/!allen!dang/[email protected]/backend.go:76 +0x9b fp=0xc000075f00 sp=0xc000075ea0 pc=0x58849b
github.com/AllenDang/cimgui-go.GLFWwindow.Run(0x8d7778?, 0xc000014018?)
        /home/super/code/go/pkg/mod/github.com/!allen!dang/[email protected]/backend.go:76 +0x37 fp=0xc000075f18 sp=0xc000075f00 pc=0x5883d7
main.main()
        /home/super/code/gocode/imguitest/main.go:36 +0x18b fp=0xc000075f80 sp=0xc000075f18 pc=0x58b6cb
runtime.main()
        /usr/lib/go/src/runtime/proc.go:250 +0x212 fp=0xc000075fe0 sp=0xc000075f80 pc=0x50e952
runtime.goexit()
        /usr/lib/go/src/runtime/asm_amd64.s:1594 +0x1 fp=0xc000075fe8 sp=0xc000075fe0 pc=0x537d61

......

code:

package main

import (
	"fmt"

	"github.com/AllenDang/cimgui-go"
	"github.com/flopp/go-findfont"
)

func afterCreateContext() {
	cimgui.Plot_CreateContext()
}

func beforeDestoryContext() {
	cimgui.Plot_DestroyContext()
}

func loop() {
	cimgui.Begin("Hello")
	cimgui.Text("Hello world")
	cimgui.End()
}

func main() {
	cimgui.SetAfterCreateContextHook(afterCreateContext)
	cimgui.SetBeforeDestroyContextHook(beforeDestoryContext)

	cimgui.SetBgColor(cimgui.NewImVec4(0.45, 0.55, 0.6, 1.0))
	window := cimgui.CreateGlfwWindow("hello", 800, 600, 0)
	fmt.Println("setupFont")
	for i := 0; i != 200; i++ {
		setupFont()
	}

	fmt.Println("setupFont finished")
	window.Run(loop)
}

func setupFont() {
	fontPath, err := findfont.Find("wqy-microhei")
	if err != nil {
		fmt.Println("found font failed")
		return
	}
	_ = fontPath
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions