<div>Hi,</div><div><br></div><div>I have a project using VTK (and QT). The whole project is organized with modules, one of them being a dynamic </div><div>library (Core.dll, to provide some functions to plugins) and other static. VTK is compiled in static mode.</div>
<div><br></div><div>For linux gcc, it requires to compile with the -fpic flag and everything is fine, VTK seems to be correctly</div><div>called in all the modules.</div>
<div><br></div><div>Under Win32 with Visual Studio it is another story: _CrtIsValidHeapPointer returns FALSE</div><div>and crashes the application when i try to read a VTK file with the following simple code:</div><div><br>
</div><div><div><span style="white-space:pre-wrap">        </span>vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();</div><div><span style="white-space:pre-wrap">        </span>reader->SetFileName(filename.toAscii().data());</div>
<div><span style="white-space:pre-wrap">        </span>reader->Update();</div></div><div><br></div><div>When looking at the call stack you can see that calls:</div><div><br></div><div>><span style="white-space:pre-wrap">        </span>msvcr90d.dll!_CrtIsValidHeapPointer(const void * pUserData) Line 2103<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>msvcr90d.dll!_free_dbg_nolock(void * pUserData, int nBlockUse) Line 1317 + 0x9 bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>msvcr90d.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1258 + 0xd bytes<span style="white-space:pre-wrap">        </span>C++</div><div> <span style="white-space:pre-wrap">        </span>msvcr90d.dll!free(void * pUserData) Line 49 + 0xb bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkDataReader::ReadArray(const char * dataType, int numTuples, int numComp) Line 1915 + 0xc bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkDataReader::ReadPoints(vtkPointSet * ps, int numPts) Line 1932 + 0x15 bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkPolyDataReader::RequestData(vtkInformation * __formal, vtkInformation * __formal, vtkInformationVector * outputVector) Line 165 + 0x13 bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkDataReader::ProcessRequest(vtkInformation * request, vtkInformationVector * * inputVector, vtkInformationVector * outputVector) Line 3062 + 0x1e bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkExecutive::CallAlgorithm(vtkInformation * request, int direction, vtkInformationVector * * inInfo, vtkInformationVector * outInfo) Line 747 + 0x21 bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkDemandDrivenPipeline::ExecuteData(vtkInformation * request, vtkInformationVector * * inInfo, vtkInformationVector * outInfo) Line 507 + 0x1d bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkDemandDrivenPipeline::ProcessRequest(vtkInformation * request, vtkInformationVector * * inInfoVec, vtkInformationVector * outInfoVec) Line 279 + 0x1e bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkStreamingDemandDrivenPipeline::ProcessRequest(vtkInformation * request, vtkInformationVector * * inInfoVec, vtkInformationVector * outInfoVec) Line 202 + 0x14 bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkDemandDrivenPipeline::UpdateData(int outputPort) Line 449 + 0x28 bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkStreamingDemandDrivenPipeline::Update(int port) Line 246 + 0x1c bytes<span style="white-space:pre-wrap">        </span>C++</div><div>
<span style="white-space:pre-wrap">        </span>mriED.exe!vtkExecutive::Update() Line 315 + 0x11 bytes<span style="white-space:pre-wrap">        </span>C++</div><div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkDemandDrivenPipeline::Update() Line 313<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkStreamingDemandDrivenPipeline::Update() Line 227<span style="white-space:pre-wrap">        </span>C++</div><div> <span style="white-space:pre-wrap">        </span>mriED.exe!vtkAlgorithm::Update() Line 1167 + 0x1a bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div> <span style="white-space:pre-wrap">        </span>mriED.exe!VTKMeshReader::ReadVTK(const QString & filename) Line 227 + 0x1d bytes<span style="white-space:pre-wrap">        </span>C++</div>
<div><br></div><div>So it crashes in vtkDataReader::ReadArray , at the following line:</div><div><div><div><br></div><div> vtkAbstractArray *vtkDataReader::ReadArray(const char *dataType, int numTuples, int numComp) </div>
<div>{</div><div> (...)</div><div><div><br></div><div> free(type); << ERROR is there. 'type' is not in the current heap.</div><div> return array;</div><div>}</div></div></div></div><div><br></div>
<div><br></div><div><div>When VTK is compiled in SHARED (dll) everything works well. So the problem seems to be</div><div>mixing dynamic and static libraries with a compilation of VTK as a static library.</div>
</div><div><br></div><div>Does mixing dynamic and static libraries is a really bad idea or is it a bug from VTK?</div><div><div>(i liked the idea to compile VTK in static mode, to avoid to provide all the dlls with</div>
</div><div>the exe)</div><div><br></div><div>I m using a pretty recent version of VTK from the Git repository (from June, 22th)</div><div>
<br></div><div>Thanks a lot for any idea!</div><div>Benoit</div><div><br></div><div><br></div>