heap corruption when tried to new a vtkSmartPointer

When I tried to new a vtkSmartPointer with type of vtkTextMapper, error occured. But It’s very weird that this kind of error just happened in Release mode but not in Debug mode. Everything in Debug mode went fine.
Here is the error code and the information:
Shows ntdll.dll goes wrong, and Heap Corruption!

Could anybody give me any advice!? Big thanks!!!

Can you please provide the text of and/or translate the error messages?

Are you sure you have built the VTK in Release mode?

Hi there!
Here is the translation of the error massages:

0x00007FFA2FE6F349(ntdll.dll) (In Asg3d.exe) Unprocessed exception: 0xC0000374: Heap corruption. (Parameter: 0x00007FFA2FED97F0).

Yes. I am sure. I used the Release x64 mode of VTK, built in CMake. I know it’s quite weird that because vtkSmartPointer will free up memory automatically, but here is how the error occured. :smiling_face_with_tear:

And the version of VTK is 8.2.0.

And the unprocessed exception is caused randomly, but it can be skipped while debugging in release mode. But I am afraid that the exception will drawn unknown consequences.

OK, i think it is better to provide more code around that line. are you sure the error root is exactly the line you have provided? becasue it is kind of weird that VTK pointer implementation leads to heap corruption.

Hi there, here is the code around the line.

The bug was reported at line88, while sometimes bug could be reported at line97. It’s so weird, I have no idea… For ClearChangedFlags() just like this:

inline void		ClearChangedFlags() { m_uChangedFlags = 0; }


What is the value of szFontFile when it crashes? Does GetModulePath need to be passed 512 or 511 (is it putting a null on the end of the string as with strncpy?)

have you tried running with address sanitizer? Highly recommend if you can get it running. Or build in debug mode to see if you get more info?

Thanks for advice!
I am sorry that address sanitizer seems to be a feature of VS2019, but with to fit the version of the complier with our team, I have to use VS2017 instead.
In Debug mode, nothings happened, and the program went smooth, and not any overflow value occured. Could you tell me how to get the required information?
But I noticed that in Release Mode, is that when I tried to run push_back from std::vector, and heap corruption could show sometimes. With this clue, is it because some optimization of Release Mode cause these kind of problems?

But this kind of problem of vtkSmartPointer stuff, could run continue for times and skip it. And the class members were all initialized correctly.

With Debug mode, I found some debugging information in the output window below:
It seems memory leaking occurs, but will it influence the heap when I define a new vtkSmartPointer?

leaking is not as big of a deal as corruption. It just means you’re not freeing memory when you should. Are you using vtkSmartPointer<…>::New() everywhere?

You should look at the _CrtSetDbgFlag function. try turning everything on and see what you find. If it’s too slow, you can try turning it on and off as you enter and exit suspicious functions.

Yes… I use lots of vtkSmartPointer to define renderers, renderwindow, actors, mappers and so on. I tried to ChatGPT that question, and it said that vtkNew and vtkSmartPointer is just different way to initialize something… and I used to skeptical of descriptions like this. But I quited continue digging in the problem of flooded vtkSmartPointer definition.

Here is my def:
I think it’s kind of ugly way to do this…but I have no clue how to make it more clear and simplified.

I found some information about vtkNew and vtkSmartPointer in a pipermail.
[vtkusers] Understanding vtkSmartPointers

Hi. Mr.Geoff, after checking my code with Application Verifier… I tried finishing other things first then look back here.
With the help of Microsoft Application Verifier, it says that the heap error might occur earlier, and breakpoint triggered after the next time pointer initialization. So vtksmartpointer became the victim. But I still cannot find the solution with the code c0000374 heap corruption, seems that with calling the parent class constructor, the protected members are not correctly initialized( type is float and unsigned int), the local variables window shows them . If I have any progress I will update here. Big thanks again!

after re-checking again and replace the backup code I found that might be some packages(for me is dcmtk) were wrong! They are the reason of memory leaking, after changing the version of the corresponding package, run pass! Great thanks for all solutions, It helps a lot!