I am trying to use vtkImageCanvasSource2D with WebAssembly and I am getting a runtime error “missing function: pthread_attr_setscope”. I think this is called when vtkImageCanvasSource2D updates. When I compile the project with Emscripten I always get the warning “warning: undefined symbol: pthread_attr_setscope”, but it wasn’t causing any issues until I started using the class vtkImageCanvasSource2D. I found this link: https://github.com/InsightSoftwareConsortium/itk-js/issues/247 and I added vtkThreadedImageAlgorithm::SetGlobalDefaultEnableSMP(true); at the beginning of my program and the runtime error disappears, but my image doesn’t get rendered. I can load a .vti file with vtkXMLImageDataReader and everything renders fine. I need to create my own vtkImageData at runtime with the vtkImageCanvasSource2D functionality. I can run the same program with VTK C++ on my Windows machine and the image renders fine. Seems to be a problem with that class, WebAssembly, and pthreads. Any help is appreciated.
I think WebAssembly does not support pthread hence the issue. But there might be some option now (compilation flag or else) to handle that (but don’t know). Searching online might allow you to find a possible path forward.
Thanks Sebastien. I was thinking of recompiling VTK for wasm without pthread support, but I am unable to find a cmake definition to disable pthreads it in VTK. Does anybody know how to disable pthreads when compiling VTK? Here is the configuration I used to compile VTK for wasm:
I found the problem. I am reading a binary file that contains the data I am creating the vtkImageData with. When running on Windows and I need to create a short from two bytes this works fine:
((char)(a)) | (((short)((char)(b)))<<8))
It does not work the same when compiled with Emscripten. I changed to:
(((short)a) << 8) | (0x00ff & b)
and it works on both platforms.
I still have to add:
at the beginning of my program to get rid of the “missing function: pthread_attr_setscope” runtime error.