tags:

views:

88

answers:

3

I was doing some .NET programming in WPF which involved reading .png and .txt files, placing images on a canvas, moving them around and then removing them and all of a sudden I get a bluescreen. I didn't think my little tinkering could cause a driver issue until I restarted and did the exact same thing with my program and I got another driver error. It seems that an intel graphics driver had failed and my resolution went way down. No bluescreen the second time, though. I was playing pretty fast and loose adding and removing elements from the children of the canvas. My question is, how could such simple programming cause such a serious error and how do I fix it?

+6  A: 

As a first order approximation all bluescreens are caused by buggy drivers, and most driver bugs are race conditions. (see footnote 1) That is - it's not necessarily the specific operations, but the exact timing of them interacting with other things that are out of your control.

So if you can nail it down to a sequence of operations, then you can just avoid that sequence. but usually the only fix is to get better drivers - and not necessarily the latest drivers, sometimes its best to go back to an older set of drivers.

footnotes:

1 Of course, not all bluescreens are drivers, but they are all from kernel mode, it should never be possible for user mode code to make calls that crash in kernel mode, so when you hit a bluescreen, you have found a bug in some component that runs in kernel mode. A bluescreen is by definition not your bug (2) (or not only your bug).

2 unless you write drivers.

John Knoeller
Man programmers get a lot of hurdles! Am I right?
ChaosPandion
@Chaos: I remember once getting a bunch of new machines for a trade show, they had new graphics cards with new drivers that worked great, but while you drew to the screen the audio would playback choppy. _our product was an audio editor_.
John Knoeller
+2  A: 

It sounds like you have a buggy graphics driver. WPF by itself cannot trigger a blue screen -- but WPF does call DirectX, which in turn calls the graphics driver -- and if the graphics driver contains bugs, those can cause a blue screen.

You cannot fix this at the WPF level, because WPF is innocent in this particular problem. You need to update your graphics driver. A possible workaround if there are no updates or the latest version doesn't fix it is to disable hardware acceleration for WPF, as this may avoid hitting the buggy bit of the driver.

itowlson
Are you saying that even though the problem happened at the EXACT SAME INSTANT when I was using the EXACT SAME SOFTWARE, the problem is caused by the driver and that on another computer with another driver, my program would work just fine?
Stefan
It's likely. The fact that it happens at the "exact same instant" every time on your machine doesn't exclude the driver: driver bugs are reproducible too after all! Best way to know is to try it: if it crashes at the exact same instant on another computer with a different graphics card (not just a different version of the same driver, because that just mean the bug hasn't been fixed between the two versions), then that points to a bug in the Windows graphics subsystem; otherwise it points to a bug in the driver on your particular machine.
itowlson
+1  A: 

Try disabling WPF hardware rendering (DirectX) and see if your problem goes away:

Graphics Rendering Registry Settings

Excerpt:

Disable Hardware Acceleration Option

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\DisableHWAcceleration

DWORD

The disable hardware acceleration option enables you to turn off hardware acceleration for debugging and test purposes. When you see rendering artifacts in an application, try turning off hardware acceleration. If the artifact disappears, the problem might be with your video driver.

The disable hardware acceleration option is a DWORD value that is either 0 or 1. A value of 1 disables hardware acceleration. A value of 0 enables hardware acceleration, provided the system meets hardware acceleration requirements; for more information, see Graphics Rendering Tiers.

DSO
How do I do that? Is it a system setting, a setting for visual studio, or something I alter in the code itself?
Stefan
As described in the response, its a registry setting. This is for testing purposes only, to help determine if it is indeed your video driver that is causing the problem. Unfortunately this isn't something that you should do in production.
DSO