wpf icon indicating copy to clipboard operation
wpf copied to clipboard

RenderTargetBitmap.Render() crashes with AccessViolationException with specific d3d9.dll

Open nineleaf opened this issue 2 years ago • 14 comments

Description

I encountered a Crash when our product called RenderTargetBitmap.Render() to render control as an image. The software does not log, but the EventView in Windows logs the Crash information. as follows: image image

I could not reproduce this issue on our product software, but I wrote a test software to render 3D files, and successfully reproduced this issue on the test software. Also this issue can only be reproduced on one of my two computers. After comparing my environment on both computers, I found that the problem was with the d3d9.dll file. When I modified the configuration file of the test program, I made the test program refer to the file d3d9.dll with version 10.0.19041.1865. I can reproduce this issue on any computer if it refers to the file d3d9.dll with version 10.0.19041.2788. I can't reproduce the issue on any computer. image

This is the test program and 3D file I use for testing. RenderTest.zip This file is actually a .7z file, but Github does not support .7z file upload. So after downloading this file, please change the extension to .7z, and then unzip it.

The reason I created this issue is that I want to know what exactly causes the crash, because I have not been able to reproduce this issue on our product software, and I am not sure if replacing d3d9.dll will solve the problem in our product. And what is the best way to upgrade DirectX? Our products run on the following Windows environments:

Edition Windows 10 IoT Enterprise LTSC Version 21H2 Installed on ‎2/‎1/‎2022 OS build 19044.1889 Experience Windows Feature Experience Pack 120.2212.4180.0

Reproduction Steps

  1. Run the program I provided above.
  2. Click on the "Select a file to Render" button.
  3. Double click on the RenderTest\3D Files\Egg Hunter Hatchlings.stl file in the folder I provided above. Observe that during the rendering process of the stl file, the RenderTest program is stuck.
  4. While RenderTest is stuck, keep clicking the "Select a file to Render" button frantically to try to continue selecting files for rendering.
  5. After clicking for a while, the software will get stuck.

The time it takes to reproduce the crash problem may be related to the CPU it is running on; the worse the CPU, the more likely it is to recover.

Expected behavior

RenderTargetBitmap does not cause software crash.

Actual behavior

RenderTargetBitmap does cause software crash.

Regression?

No response

Known Workarounds

Replace C:\windows\system32\d3d9.dll

Impact

No response

Configuration

No response

Other information

No response

nineleaf avatar Jun 15 '23 09:06 nineleaf

Please kindly let me know if you need more information.

nineleaf avatar Jun 15 '23 09:06 nineleaf

It sounds like updating to a newer Windows build would give you a newer d3d9.dll. Otherwise, I would expect this to be fixed through Windows Update.

https://support.microsoft.com/en-gb/topic/how-to-install-the-latest-version-of-directx-d1f5ffa5-dae2-246c-91b1-ee1e973ed8c2

miloush avatar Jun 15 '23 10:06 miloush

@nineleaf - I think @miloush is correct. Can you confirm if the latest Windows update fixes your issue. As for finding the exact reason for failure, it may be difficult since the issue looks to be from an unmanaged DirectX component.

pchaurasia14 avatar Jun 19 '23 05:06 pchaurasia14

Perhaps enabling WPF software rendering could also fix the issue.

lindexi avatar Jun 19 '23 06:06 lindexi

Perhaps enabling WPF software rendering could also fix the issue.

Do you mean disable hardware acceleration? I've tried this method and it didn't work.

nineleaf avatar Jun 19 '23 06:06 nineleaf

@nineleaf - I think @miloush is correct. Can you confirm if the latest Windows update fixes your issue. As for finding the exact reason for failure, it may be difficult since the issue looks to be from an unmanaged DirectX component.

I am trying to upgrade windows, but I got an error "something didn't go as planned ......" when I upgraded. I need to fix this first, and if I get new results I'll update.

nineleaf avatar Jun 19 '23 06:06 nineleaf

Perhaps enabling WPF software rendering could also fix the issue.

Do you mean disable hardware acceleration? I've tried this method and it didn't work.

Can I know the exception when you disable the hardware acceleration? Same as before?

lindexi avatar Jun 20 '23 00:06 lindexi

Yes, exactly the same.

nineleaf avatar Jun 21 '23 01:06 nineleaf

@nineleaf This behavior is a bit unexpected, because in soft rendering mode, there will be less dependence on the environment. It seems that this is a more complex issue.

lindexi avatar Jun 21 '23 01:06 lindexi

@nineleaf -

Can you confirm if the latest Windows update fixes your issue.

pchaurasia14 avatar Jun 21 '23 05:06 pchaurasia14

This can be fixed by the updates https://support.microsoft.com/en-us/topic/november-15-2022-kb5020030-os-builds-19042-2311-19043-2311-19044-2311-and-19045-2311-preview-237a9048-f853-4e29-a3a2-62efdbea95e2 or newer. In this version d3d9.dll was updated to 10.0.19041.2133. I tested the update a little earlier than this. The d3d9.dll in version 10.0.19041.2075 still causes a crash. I also tested the latest update kb5027215, and there is no crash with this one.

nineleaf avatar Jun 25 '23 08:06 nineleaf

@nineleaf This behavior is a bit unexpected, because in soft rendering mode, there will be less dependence on the environment. It seems that this is a more complex issue.

I tried disabling hardware acceleration in the registry and setting SoftwareOnly on the software. Neither prevented the crash. Then I noticed in https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/graphics-rendering-tiers?view=netframeworkdesktop-4.8, RenderTargetBitmap.Render does not use hardware acceleration.

nineleaf avatar Jun 25 '23 09:06 nineleaf

This can be fixed by the updates https://support.microsoft.com/en-us/topic/november-15-2022-kb5020030-os-builds-19042-2311-19043-2311-19044-2311-and-19045-2311-preview-237a9048-f853-4e29-a3a2-62efdbea95e2 or newer. In this version d3d9.dll was updated to 10.0.19041.2133. I tested the update a little earlier than this. The d3d9.dll in version 10.0.19041.2075 still causes a crash. I also tested the latest update kb5027215, and there is no crash with this one.

My bad, the issue isn't fixed, it's just harder to reproduce. I'm having this problem again.

nineleaf avatar Jul 18 '24 07:07 nineleaf

@nineleaf I find the https://github.com/narzoul/ForceD3D9On12

Do you think it helps?

lindexi avatar Jul 18 '24 07:07 lindexi