我写了一个测试taichi的ggui的mesh显示功能的程序,可以正常运行,但是将程序在后台放置一分钟左右后,程序就会崩溃,使用的是RX580 8G显卡,vulkan后端。程序如下:
import taichi as ti
import numpy as np
import math
ti.init(arch=ti.vulkan)
indices = ti.field(int, 4*3)
vertices = ti.Vector.field(3, float, 4*3)
colours = ti.Vector.field(3, float, 4*3)
indices.from_numpy(np.array([0,1,2,3,4,5,6,7,8,9,10,11]))
vertices.from_numpy(np.array([
[0,0,0],
[0,1,0],
[0,0,1],
[1,0,0],
[0,0,0],
[0,1,0],
[0,0,1],
[1,0,0],
[0,0,0],
[0,1,0],
[0,0,1],
[1,0,0]
]))
colours.from_numpy(0.5*np.array([
[1,0,0],
[1,0,0],
[1,0,0],
[0,1,0],
[0,1,0],
[0,1,0],
[0,0,1],
[0,0,1],
[0,0,1],
[1,1,0],
[1,1,0],
[1,1,0]
]).astype(np.float32))
window = ti.ui.Window("test mesh plot", (800, 800), vsync=True)
canvas = window.get_canvas()
scene = ti.ui.Scene()
camera = ti.ui.make_camera()
theta=0
phi=0
while window.running:
if window.is_pressed(ti.ui.LEFT, 'a'): theta -=0.03
if window.is_pressed(ti.ui.RIGHT, 'd'): theta +=0.03
if window.is_pressed(ti.ui.UP, 'w'): phi +=0.03
if window.is_pressed(ti.ui.DOWN, 's'): phi -=0.03
phi=min(math.pi/2,max(-math.pi/2,phi))
camera.position(2*math.cos(theta)*math.cos(phi),2*math.sin(theta)*math.cos(phi),2*math.sin(phi)+0.5)
camera.lookat(0,0,0.5)
camera.up(0,0,1)
scene.set_camera(camera)
scene.point_light(pos=(0.5, 1, 2), color=(1, 1, 1))
scene.ambient_light((1,1,1))
scene.mesh(vertices,
indices=indices,
per_vertex_color=colours,
two_sided=True)
canvas.scene(scene)
window.show()
崩溃效果如下: