I was using renderer.Present() after Copy some texture in a for loop, and sometimes the program just froze and no responding.
I try to print some message to figure out where's the problem, and the output was able to print the line before Present(), but not able to reach the line after Present(), so I think it might be the problem.
How can I fixed it or it is a bug?
a part of my code:
type element struct {
tex *sdl.Texture
x, y int32
}
var (
board element
stones []element
special element
)
func game(renderer *sdl.Renderer) {
for i := 0; ; i++ {
renderer.SetDrawColor(210, 210, 210, 255)
renderer.Clear()
board.draw(renderer)
for _, v := range stones {
v.draw(renderer)
}
special.draw(renderer)
fmt.Println("before present")
renderer.Present()
fmt.Println("after")
time.Sleep(33333 * time.Microsecond) // 30 fps
fmt.Println(i)
}
}
func (ele *element) draw(renderer *sdl.Renderer) {
renderer.Copy(ele.tex,
&sdl.Rect{X: 0, Y: 0, W: 20, H: 20},
&sdl.Rect{X: ele.x, Y: ele.y, W: 20, H: 20})
}
I was using renderer.Present() after Copy some texture in a for loop, and sometimes the program just froze and no responding. I try to print some message to figure out where's the problem, and the output was able to print the line before Present(), but not able to reach the line after Present(), so I think it might be the problem. How can I fixed it or it is a bug?
a part of my code: