Sometimes we need to change canvas for VTK WASM 3D window.
Updating renderer window and renderer is neccessary if we don’t restart all data loading.
The related post is Change Canvas For VTK WASM Project. I got the following error info on the web page if do vtkSDL2OpenGLRenderWindow::Render before m_RenderWindow = newWin; (update the old rendererWindow variable).

Uncaught TypeError: Cannot read properties of null (reading 'bindRenderbuffer')
    at _glBindRenderbuffer (changeCanvasForWASM.js:8174:13)
    at vtkRenderbuffer::Resize(:4002/unsigned int, unsigned int) (http://localhost:4002/changeCanvasForWASM.wasm)

After reading the source code of VTK9.2.0, I find the whole function call logic chain.

void vtkOpenGLRenderWindow::Render()
<---
this->Superclass::Render();
void vtkRenderWindow::Render()
<---
this->Start(); // Ensure context exists
<---
void vtkOpenGLRenderWindow::Start()
<---
this->CreateFramebuffers(this->Size[0], this->Size[1]);
<---
int vtkOpenGLRenderWindow::CreateFramebuffers(int width, int height)
<---
this->RenderFramebuffer->Resize(width, height);
<---
void vtkOpenGLFramebufferObject::Resize(int width, int height)
<---
i->second->Resize(this->LastSize);
<---
this->Renderbuffer->Resize(size[0], size[1]);
<---
void vtkRenderbuffer::Resize(unsigned int width, unsigned int height)
<---
glBindRenderbuffer(GL_RENDERBUFFER, (GLuint)this->Handle);

So just change the order of render and updating to fix the issue.

void Worker::ChangeRenderWindow()
{    
    std::cout << "m_Renderer: " << m_Renderer << std::endl;
    std::cout << "m_RenderWindowInteractor: " << m_RenderWindowInteractor << std::endl;

    m_Renderer = vtkSPtr<vtkRenderer>::New(); // need it!
    m_Renderer->AddActor(m_Actor);
    m_Renderer->SetBackground( 0, 0, 0 );

    vtkSPtr<vtkSDL2OpenGLRenderWindow> newWin = vtkSPtr<vtkSDL2OpenGLRenderWindow>::New(); // need
    newWin->AddRenderer( m_Renderer );
    m_RenderWindowInteractor->SetRenderWindow( newWin );

    
    //m_RenderWindow = newWin; // we can't `m_RenderWindow = newWin` after newWin->render because the error:
/*
Uncaught TypeError: Cannot read properties of null (reading 'bindRenderbuffer')
    at _glBindRenderbuffer (changeCanvasForWASM.js:8174:13)
    at vtkRenderbuffer::Resize(:4002/unsigned int, unsigned int) (http://localhost:4002/changeCanvasForWASM.wasm)
*/ 

    m_RenderWindow = newWin;
    m_RenderWindow->Render();

    m_RenderWindowInteractor->Start();
}
Categories: VTKWeb

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x