why bgl meshes flip when nothing is selected? As described in API the following script will create a mesh from active object using bgl module:
import bpy
import gpu
import bgl
import numpy as np
from random import random
from gpu_extras.batch import batch_for_shader

mesh = bpy.context.active_object.data
mesh.calc_loop_triangles()

vertices = np.empty((len(mesh.vertices), 3), 'f')
indices = np.empty((len(mesh.loop_triangles), 3), 'i')

mesh.vertices.foreach_get(
    &quot;co&quot;, np.reshape(vertices, len(mesh.vertices) * 3))
mesh.loop_triangles.foreach_get(
    &quot;vertices&quot;, np.reshape(indices, len(mesh.loop_triangles) * 3))

vertex_colors = [(random(), random(), random(), 1) for _ in range(len(mesh.vertices))]

shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR')
batch = batch_for_shader(
    shader, 'TRIS',
    {&quot;pos&quot;: vertices, &quot;color&quot;: vertex_colors},
    indices=indices,
)

def draw():
    bgl.glEnable(bgl.GL_DEPTH_TEST)
    batch.draw(shader)
    bgl.glDisable(bgl.GL_DEPTH_TEST)

bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')

But the created mesh flips when nothing is selected:

Please help!
The script does its job.
The problems is caused by old nvidia graphics driver. A new nvidia gameready graphics driver solved the problem.