Unexpected crash when creating image reader with Visual Studio Release mode

I’m trying to use ITK to build a small application for my colleagues. However, the following code causes my app to crash:

using ReaderType = itk::ImageFileReader<ImageType>;
ReaderType::Pointer reader = ReaderType::New(); // this line causes the problem!

I don’t know what happened, so I tried to recompile SimpleITK Superbuild with RelWithDeInfo and found this error:

0x00007FF904AF8C34 (msvcp140.dll)处(位于 Calculator.exe 中)引发的异常: 0xC0000005: 读取位置 0x0000000000000000 时发生访问冲突。

// (translated into English)
Exception thrown at 0x00007FF904AF8C34 (msvcp140.dll) in Calculator.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

Here is the program stack:

Here are the dll libraries:

“Calculator.exe”(Win32): 已加载“E:\projects\sitk\SITKExample\CalculatorBin\RelWithDebInfo\Calculator.exe”。已加载符号。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\ntdll.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\kernel32.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\KernelBase.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\shell32.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\msvcp_win.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\ucrtbase.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\user32.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\win32u.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\gdi32.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\gdi32full.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\advapi32.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\msvcrt.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\sechost.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\bcrypt.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\rpcrt4.dll”。
“Calculator.exe”(Win32): 已加载“E:\projects\sitk\SITKExample\CalculatorBin\RelWithDebInfo\onnxruntime.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\wsock32.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\ws2_32.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\msvcp140.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\vcruntime140.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\vcruntime140_1.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\msvcp140_1.dll”。
“Calculator.exe”(Win32): 已加载“C:\Windows\System32\imm32.dll”。
线程 38208 已退出,返回值为 0 (0x0)。
0x00007FF904AF8C34 (msvcp140.dll)处(位于 Calculator.exe 中)引发的异常: 0xC0000005: 读取位置 0x0000000000000000 时发生访问冲突。

My program works fine when compiled with Debug mode. This error only happens in Release/RelWithDeInfo mode.

The most bizarre thing is that I originally COULD compile my app in release mode and run it until one day my computer crashed and I restarted my computer. From that day on, the release mode no longer works :frowning: Re-compiling ITK/SimpleITK won’t work. I have searched the Internet and found a similar post c++ - ITK access violation error in release mode but not in debug mode while reading DICOM files - Stack Overflow but this does not solve my problem.

This issue is driving me crazy. What could be the problem?

Please share your source code and CMakeLists.txt file your are using for your example program.

I suspect that you have mixed up different ITK and/or SimpleITK runtime environments.

You say “Re-compiling ITK/SimpleITK won’t work.” You are no longer able to build from source?

Hi! Thanks for your reply!!! What I mean is that re-compiling ITK/SimpleITK won’t fix my issue.

But I have solved this issue by re-installing Latest supported Visual C++ Redistributable downloads | Microsoft Learn, so I assume this problem is related to Windows update?

Thank you anyway!

2 Likes