我在 Go 中有這個簡單的 OpenGL 程序。當(dāng)我編譯并運行它時,主游戲循環(huán)在因分段違規(guī)而崩潰之前經(jīng)歷了大約 9 次迭代。rendering for the 0 timerendering for the 1 timerendering for the 2 timerendering for the 3 timerendering for the 4 timerendering for the 5 timerendering for the 6 timeSIGSEGV: segmentation violationPC=0x7fdab95a0e29signal arrived during cgo executionruntime.cgocall(0x414f90, 0x7fdab9887e88) /usr/lib/go/src/pkg/runtime/cgocall.c:149 +0x11b fp=0x7fdab9887e70github.com/go-gl/gl._Cfunc_glClear(0xc200004100) github.com/go-gl/gl/_obj/_cgo_defun.c:340 +0x31 fp=0x7fdab9887e88github.com/go-gl/gl.Clear(0x4100) /mnt/data/Dropbox/Coding/Go/src/github.com/go-gl/gl/gl.go:161 +0x25 fp=0x7fdab9887e98main.draw() /home/josh/Coding/Go/src/github.com/JoshWillik/Wander/wander.go:120 +0x25 fp=0x7fdab9887eb8main.main() /home/josh/Coding/Go/src/github.com/JoshWillik/Wander/wander.go:52 +0x300 fp=0x7fdab9887f48runtime.main() /usr/lib/go/src/pkg/runtime/proc.c:220 +0x11f fp=0x7fdab9887fa0runtime.goexit() /usr/lib/go/src/pkg/runtime/proc.c:1394 fp=0x7fdab9887fa8goroutine 3 [syscall]:runtime.goexit() /usr/lib/go/src/pkg/runtime/proc.c:1394rax 0x0rbx 0x7fdab9887e88rcx 0x7fdab9887e88rdx 0x7fdab9887e20rdi 0x4100rsi 0xc210001900rbp 0xc21002a000rsp 0x7fdab2a4ddd8r8 0xc210001120r9 0x7fdab9887e20r10 0x0r11 0x286r12 0x0r13 0x7fdab9a74000r14 0x0r15 0x7fdab2a4e700rip 0x7fdab95a0e29rflags 0x10202cs 0x33fs 0x0gs 0x0如果我刪除shouldRender函數(shù)中基于時間的邏輯,它會在崩潰前迭代大約 28-29 次。如果我刪除函數(shù)gl.Clear()中的draw調(diào)用,它會在崩潰之前持續(xù)到 90 年代。如果我刪除對fmt.Println()in的調(diào)用shouldRender,游戲?qū)搭A(yù)期運行而不會崩潰。(我已經(jīng)測試了大約 2 到 3 分鐘,所以將近 10,000 幀)這讓我懷疑fmt.Println()對分段違規(guī)的調(diào)用以某種方式負(fù)責(zé)。我是否誤讀了這些標(biāo)志?如果不是,那么核心功能怎么會Println()如此不穩(wěn)定?
Golang fmt.Println() 導(dǎo)致游戲崩潰
慕運維8079593
2021-07-16 18:01:47