g3n / engine

Go 3D Game Engine (http://g3n.rocks)
https://discord.gg/NfaeVr8zDg
BSD 2-Clause "Simplified" License
2.74k stars 292 forks source link

fatal error: checkptr: pointer arithmetic computed bad pointer value on `GLS.VertexAttribPointer` #301

Closed zyxkad closed 8 months ago

zyxkad commented 8 months ago

When run g3n with -race flag, program will failed:

Stacktrace ``` fatal error: checkptr: pointer arithmetic computed bad pointer value goroutine 1 [running, locked to thread]: runtime.throw({0x1046f90e6?, 0x1045aad24?}) /opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/panic.go:1077 +0x40 fp=0xc0000e94f0 sp=0xc0000e94c0 pc=0x10450b490 runtime.checkptrArithmetic(0xe9538?, {0x0?, 0xc0000e9568?, 0x1045a9500?}) /opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/checkptr.go:52 +0xb8 fp=0xc0000e9520 sp=0xc0000e94f0 pc=0x1044de028 github.com/g3n/engine/gls.(*VBO).Transfer.(*GLS).VertexAttribPointer.func1(0x3?, 0xc0?, 0x98ab0?, 0xc0?, 0x46f05ed?, 0xc) /Users/ckpn/Mine/projects/golang/src/github.com/LiterMC/curve/test/g3n/gls/gls-desktop.go:815 +0x60 fp=0xc0000e9570 sp=0xc0000e9520 pc=0x1045a96b0 github.com/g3n/engine/gls.(*GLS).VertexAttribPointer(...) /Users/ckpn/Mine/projects/golang/src/github.com/LiterMC/curve/test/g3n/gls/gls-desktop.go:815 github.com/g3n/engine/gls.(*VBO).Transfer(0xc00028e230, 0xc000000120) /Users/ckpn/Mine/projects/golang/src/github.com/LiterMC/curve/test/g3n/gls/vbo.go:311 +0x45c fp=0xc0000e96a0 sp=0xc0000e9570 pc=0x1045a951c github.com/g3n/engine/geometry.(*Geometry).RenderSetup(0xc0001fe410, 0xc000000120) /Users/ckpn/Mine/projects/golang/src/github.com/LiterMC/curve/test/g3n/geometry/geometry.go:528 +0x218 fp=0xc0000e9740 sp=0xc0000e96a0 pc=0x10460f7a8 github.com/g3n/engine/graphic.(*GraphicMaterial).Render(0xc00028cc60, 0xc000000120, 0xc0000e99f8?) /Users/ckpn/Mine/projects/golang/src/github.com/LiterMC/curve/test/g3n/graphic/graphic.go:305 +0xac fp=0xc0000e9840 sp=0xc0000e9740 pc=0x104623dbc github.com/g3n/engine/renderer.(*Renderer).renderGraphicMaterial(0xc0000f6580, 0xc00028cc60) /Users/ckpn/Mine/projects/golang/src/github.com/LiterMC/curve/test/g3n/renderer/renderer.go:354 +0x5cc fp=0xc0000e9a60 sp=0xc0000e9840 pc=0x10467410c github.com/g3n/engine/renderer.(*Renderer).Render(0xc0000f6580, {0x1047c66e0, 0xc0000b2140}, {0x1047c4da0, 0xc00022a000}) /Users/ckpn/Mine/projects/golang/src/github.com/LiterMC/curve/test/g3n/renderer/renderer.go:191 +0x7d8 fp=0xc0000e9d10 sp=0xc0000e9a60 pc=0x1046723e8 main.(*Runner).Tick(0xc0000c62c0, 0x658252f0?, 0x72a) /Users/ckpn/Mine/projects/golang/src/github.com/LiterMC/curve/runner.go:203 +0x2b0 fp=0xc0000e9e00 sp=0xc0000e9d10 pc=0x104680200 main.(*Runner).Tick-fm(0xc158b29c2bc5f690?, 0x2bcb7d1e?) :1 +0x48 fp=0xc0000e9e40 sp=0xc0000e9e00 pc=0x104681fa8 github.com/g3n/engine/app.(*Application).Run(0xc0000b0240, 0xc0000e9f18) /Users/ckpn/Mine/projects/golang/src/github.com/LiterMC/curve/test/g3n/app/app-desktop.go:82 +0x22c fp=0xc0000e9ed0 sp=0xc0000e9e40 pc=0x10467716c main.main() /Users/ckpn/Mine/projects/golang/src/github.com/LiterMC/curve/main.go:35 +0xf4 fp=0xc0000e9f30 sp=0xc0000e9ed0 pc=0x10467ce34 runtime.main() /opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:267 +0x2bc fp=0xc0000e9fd0 sp=0xc0000e9f30 pc=0x10450ddcc runtime.goexit() /opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/asm_arm64.s:1197 +0x4 fp=0xc0000e9fd0 sp=0xc0000e9fd0 pc=0x10453cbe4 ```

It's because g3n will covert uint32 offset into unsafe.Pointer in order to pass it to C function *void. https://github.com/g3n/engine/blob/4e30d5c3f79e6690781696921fb09f3c329ae520/gls/gls-desktop.go#L813-L816

danaugrs commented 8 months ago

Thanks!!