I got the following error information on the web page if I change the id of canvas to be ‘canvas1’.

The function USDL2OpenGLRenderWindow::CreateAWindow is similar to vtkSDL2OpenGLRenderWindow::CreateAWindow.

We can read VTK and SDL library source code and find these code snippets.

File: video\emscripten\SDL_emscriptenvideo.c

device->CreateSDLWindow = Emscripten_CreateWindow;
static int
Emscripten_CreateWindow(_THIS, SDL_Window * window)
    SDL_WindowData *wdata;
    double scaled_w, scaled_h;
    double css_w, css_h;

    /* Allocate window internal data */
    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
    if (wdata == NULL) {
        return SDL_OutOfMemory();

    wdata->canvas_id = SDL_strdup("#canvas");

We know that the id of the canvas which SDL finds is awayls canvas after read the above code.
If you change it on the HTML page, there will be an error about null object in wasm.
The function void vtkSDL2RenderWindowInteractor::Initialize() will be called automatically by Start() if the interactor is not initialized.
So only after we call Interactor::Start(),the Initialize process and canvas binding will be done. This is situation 2.

void UDisplayManagerBase::Start()

class VTKRENDERINGCORE_EXPORT vtkRenderWindowInteractor : public vtkObject

   * Prepare for handling events and set the Enabled flag to true.
   * This will be called automatically by Start() if the interactor
   * is not initialized, but it can be called manually if you need
   * to perform any operations between initialization and the start
   * of the event loop.
  virtual void Initialize();

Categories: VTKWeb

0 0 votes
Article Rating
Notify of

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments

[…] Let’s define two canvas on the page. One is at the left-top area, the other is at the right-top part. It will change canvas binding with wasm module after we click on the left-bottom button update. We had knew that VTK start to find canvas object in rendering process after starting event loop and the canvas is must be ‘canvas’. Relevant post: Why Does The Canvas Id On HTML Page Have To Be canvas For VTK WebAssembly?. […]

XOR Strings
: Input your strings, the tool can encrypt and decrypt them.

Would love your thoughts, please comment.x