Calling Render method on vtkRenderWindow produces an error. (Vtk 9.0 - Python wrapper)

I’m trying to change the color of one of the actors. After change the color in the actor, I call the Render method and produces this error.

2020-06-01 12:45:40.413 (   5.598s) [                ]     vtkOpenGLState.cxx:1380  WARN| Hardware does not support the number of textures defined.2020-06-01 12:45:40.467 (   5.652s) [                ]     vtkOpenGLState.cxx:1380  WARN| Hardware does not support the number of textures defined.2020-06-01 12:45:40.484 (   5.669s) [                ]   vtkShaderProgram.cxx:437    ERR| vtkShaderProgram (000002380CB1D770): 1: #version 150
2: #ifndef GL_ES
3: #define highp
4: #define mediump
5: #define lowp
6: #endif // GL_ES
7: #define attribute in
8: #define varying out
9:
10:
11: /*=========================================================================
12:
13:   Program:   Visualization Toolkit
14:   Module:    vtkPolyDataVS.glsl
15:
16:   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
17:   All rights reserved.
18:   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
19: 
20:      This software is distributed WITHOUT ANY WARRANTY; without even
21:      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
22:      PURPOSE.  See the above copyright notice for more information.
23:
24: =========================================================================*/
25: 
26: in vec4 vertexMC;
27:
28:
29:
30: // frag position in VC
31: out vec4 vertexVCVSOutput;
32:
33: // optional normal declaration
34: //VTK::Normal::Dec
35:
36: // extra lighting parameters
37: //VTK::Light::Dec
38: 
39: // Texture coordinates
40: //VTK::TCoord::Dec
41:
42: // material property values
43: //VTK::Color::Dec
44:
45: // clipping plane vars
46: //VTK::Clip::Dec
47:
48: // camera and actor matrix values
49: uniform mat4 MCDCMatrix;
50: uniform mat4 MCVCMatrix;
51:
52: // Apple Bug
53: //VTK::PrimID::Dec
54:
55: // Value raster
56: //VTK::ValuePass::Dec
57:
58: // picking support
59: //VTK::Picking::Dec
60:
61: void main()
62: {
63:   //VTK::Color::Impl
64:
65:   //VTK::Normal::Impl
66: 
67:   //VTK::TCoord::Impl
68: 
69:   //VTK::Clip::Impl
70:
71:   //VTK::PrimID::Impl
72:
73:   vertexVCVSOutput = MCVCMatrix * vertexMC;
74:   gl_Position = MCDCMatrix * vertexMC;
75:
76:
77:   //VTK::ValuePass::Impl
78:
79:   //VTK::Light::Impl
80:
81:   //VTK::Picking::Impl
82: }

2020-06-01 12:45:41.157 (   6.341s) [                ]   vtkShaderProgram.cxx:438    ERR| vtkShaderProgram (000002380CB1D770): Could not create shader object.

My code is:

import vtk


colors = vtk.vtkNamedColors()


def crear_superficie(*puntos):

    points = vtk.vtkPoints()
    polygon = vtk.vtkPolygon()
    polygon.GetPointIds().SetNumberOfIds(len(puntos))
    for i, p in enumerate(puntos):
        points.InsertNextPoint(*p)
        polygon.GetPointIds().SetId(i, i)
    polygons = vtk.vtkCellArray()
    polygons.InsertNextCell(polygon)

    # Create a PolyData
    polygonPolyData = vtk.vtkPolyData()
    polygonPolyData.SetPoints(points)
    polygonPolyData.SetPolys(polygons)

    # Create a mapper and actor
    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputData(polygonPolyData)

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().EdgeVisibilityOn()
    actor.GetProperty().SetLineWidth(2)
    actor.GetProperty().SetColor(colors.GetColor3d("Banana"))

    return actor


def main():

    a = crear_superficie((0, 0, 0), (0, 6, 0), (15, 10, 0), (30, 6, 0), (30, 0, 0))
    b = crear_superficie((0, 6, 0), (15, 10, 0), (15, 10, 60), (0, 6, 60))
   # Add the polygon to a list of polygons


    # Visualize
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.SetWindowName("Polygon")
    renderWindow.AddRenderer(renderer)
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    renderer.AddActor(a)
    renderer.AddActor(b)
    renderer.SetBackground(colors.GetColor3d("Silver"))
    renderWindow.Render()
    renderWindowInteractor.Start()
    b.GetProperty().SetColor(colors.GetColor3d("Silver"))
    renderWindow.Render()



if __name__ == '__main__':
   main()

Don’t change anything after the interactor starts.

Do this in your last block of code:


    renderer.AddActor(a)
    renderer.AddActor(b)
    renderer.SetBackground(colors.GetColor3d("Silver"))
    b.GetProperty().SetColor(colors.GetColor3d("Silver"))
    renderWindow.Render()
    renderWindowInteractor.Start()

A fuller explanation:
The mapper terminates the pipeline which is then associated with the renderer and finally the renderer window. At this point you can still change actor properties, backgounds etc.
When the interactor starts it creates an event loop so you can interact with the rendered objects in the render window, rotate them, zoom them etc. So the operating system, and graphics engine are doing all the work. If you change a property after stopping the interactor then there is no link back to the objects. Hence the crash after exiting.

It’s working now. Thanks for the detailed explanation.

So, in summary, it’s no possible to make modifications while the user interacts with the render.

It’s still possible to make changes during interaction via event-driven programming. Once the event loop starts, the application becomes event-driven. If you add event observers before calling Start(), those observers will be called when the events occur. See this sample code.

Thanks! I’ll check it out.