Skip to content

Instantly share code, notes, and snippets.

@wolfgang42
Created April 20, 2018 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfgang42/07e8a2677c7f6e36393bdca862bebac2 to your computer and use it in GitHub Desktop.
Save wolfgang42/07e8a2677c7f6e36393bdca862bebac2 to your computer and use it in GitHub Desktop.
Test case for golang nuklear crash

This is a stripped-down test case for a crash I encountered in the go bindings for nuklear.

To reproduce:

  1. Compile: go build nk-go-crash.go
  2. Run: ./nk-go-crash
  3. Focus the text box in the window.
  4. Type 123456789. It should crash sometime around 7 or 8.

Tested with Ubuntu 16.04.4, go version go1.9.4 linux/amd64.

package main
import (
"runtime"
"time"
"github.com/go-gl/gl/v3.2-core/gl"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/golang-ui/nuklear/nk"
)
const (
winWidth = 400
winHeight = 500
maxVertexBuffer = 512 * 1024
maxElementBuffer = 128 * 1024
)
func init() {
runtime.LockOSThread()
}
var ibuf = []byte{0}
var shouldFocus = true
func main() {
if err := glfw.Init(); err != nil {
panic(err)
}
glfw.WindowHint(glfw.ContextVersionMajor, 3)
glfw.WindowHint(glfw.ContextVersionMinor, 2)
glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
win, err := glfw.CreateWindow(winWidth, winHeight, "Nuklear Demo", nil, nil)
if err != nil {panic(err)}
win.MakeContextCurrent()
if err := gl.Init(); err != nil {
panic("opengl: init failed")
}
ctx := nk.NkPlatformInit(win, nk.PlatformInstallCallbacks)
atlas := nk.NewFontAtlas()
nk.NkFontStashBegin(&atlas)
sansFont := nk.NkFontAtlasAddDefault(atlas, 16, nil)
nk.NkFontStashEnd()
nk.NkStyleSetFont(ctx, sansFont.Handle())
fpsTicker := time.NewTicker(time.Second / 30)
for {
<-fpsTicker.C
glfw.PollEvents()
gfxMain(win, ctx)
}
}
func gfxMain(win *glfw.Window, ctx *nk.Context) {
nk.NkPlatformNewFrame()
// Layout
width, height := win.GetSize()
bounds := nk.NkRect(0, 0, 400, 500)
update := nk.NkBegin(ctx, "Demo", bounds, 0)
if update > 0 {
nk.NkLayoutRowDynamic(ctx, 36, 1)
nk.NkEditStringZeroTerminated(ctx, nk.EditField, ibuf, 256, nil)
}
nk.NkEnd(ctx)
// Render
gl.Viewport(0, 0, int32(width), int32(height))
gl.Clear(gl.COLOR_BUFFER_BIT)
nk.NkPlatformRender(nk.AntiAliasingOn, maxVertexBuffer, maxElementBuffer)
win.SwapBuffers()
}
fatal error: cgoUse should not be called
goroutine 1 [running, locked to thread]:
runtime.throw(0x5d02c0, 0x1b)
/usr/local/go/src/runtime/panic.go:605 +0x95 fp=0xc420053d70 sp=0xc420053d50 pc=0x4589c5
runtime.cgoUse(0x574b00, 0x1dd8e30)
/usr/local/go/src/runtime/cgo.go:45 +0x36 fp=0xc420053d90 sp=0xc420053d70 pc=0x431f26
github.com/golang-ui/nuklear/nk._Cfunc_nk_edit_string_zero_terminated(0x1dd8e30, 0x260, 0x8b80cf, 0x100, 0x0, 0x1)
github.com/golang-ui/nuklear/nk/_obj/_cgo_gotypes.go:3555 +0x7c fp=0xc420053dd0 sp=0xc420053d90 pc=0x4f419c
github.com/golang-ui/nuklear/nk.NkEditStringZeroTerminated.func1(0x1dd8e30, 0x260, 0x8b80cf, 0xc400000100, 0x0, 0x1dd8e30)
/go/src/github.com/golang-ui/nuklear/nk/nk.go:1695 +0x88 fp=0xc420053e10 sp=0xc420053dd0 pc=0x4fac48
github.com/golang-ui/nuklear/nk.NkEditStringZeroTerminated(0x1dd8e30, 0x100000260, 0x8b80cf, 0x1, 0x1, 0x100, 0x0, 0x0)
/go/src/github.com/golang-ui/nuklear/nk/nk.go:1695 +0x6f fp=0xc420053e58 sp=0xc420053e10 pc=0x4f999f
main.gfxMain(0xc420086000, 0x1dd8e30)
/go/main.go:69 +0x1b8 fp=0xc420053eb8 sp=0xc420053e58 pc=0x5088e8
main.main()
/go/main.go:55 +0x290 fp=0xc420053f80 sp=0xc420053eb8 pc=0x5086c0
runtime.main()
/usr/local/go/src/runtime/proc.go:195 +0x226 fp=0xc420053fe0 sp=0xc420053f80 pc=0x45a0b6
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc420053fe8 sp=0xc420053fe0 pc=0x482ce1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment