# Unexpected crash when creating image reader with Visual Studio Release mode

**URL:** <https://discourse.itk.org/t/unexpected-crash-when-creating-image-reader-with-visual-studio-release-mode/7324>\
**Category:** Beginner Questions\
**Created:** [November 21, 2024, 12:34pm UTC](https://discourse.itk.org/t/unexpected-crash-when-creating-image-reader-with-visual-studio-release-mode/7324 "2024-11-21T12:34:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tctco](https://discourse.itk.org/user_avatar/discourse.itk.org/tctco/32/4416_2.png) [@tctco](https://discourse.itk.org/u/tctco)\
**Post date:** [November 21, 2024, 12:34pm UTC](https://discourse.itk.org/t/unexpected-crash-when-creating-image-reader-with-visual-studio-release-mode/7324/1 "2024-11-21T12:34:12Z")

</div>

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

```cpp
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:

```cpp
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:

 ![image](https://discourse.itk.org/uploads/default/original/2X/a/a575b1a8b784600fe3c443c6421b351af6edd75d.png)

Here are the dll libraries:

```auto
“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 ☹ 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](https://stackoverflow.com/questions/14948611/itk-access-violation-error-in-release-mode-but-not-in-debug-mode-while-reading-d) but this does not solve my problem.

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

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [November 21, 2024, 1:01pm UTC](https://discourse.itk.org/t/unexpected-crash-when-creating-image-reader-with-visual-studio-release-mode/7324/2 "2024-11-21T13:01:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tctco](https://discourse.itk.org/user_avatar/discourse.itk.org/tctco/32/4416_2.png) [@tctco](https://discourse.itk.org/u/tctco)\
**Post date:** [November 21, 2024, 3:04pm UTC](https://discourse.itk.org/t/unexpected-crash-when-creating-image-reader-with-visual-studio-release-mode/7324/3 "2024-11-21T15:04:25Z")

</div>

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](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170), so I assume this problem is related to Windows update?

Thank you anyway!
