• Advertisement
Sign in to follow this  

BSoD in Managed DX, is this a known problem?

This topic is 4209 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So, I was just optimizing my rendering, to add culling, when I made a little bug. While this is so my own fault, a bluescreen is a little harsh way of telling me imho..
Point UL = MouseToTile(new Point(0, 0));
Point DR = MouseToTile(new Point(799, 599));
for(int i = DR.Y; i <= UL.Y; i++)
{
device.DrawPrimitives(PrimitiveType.TriangleList, (Map.w * i + UL.X)*6, (DR.X-UL.X + 1)*2);
}

The bug was that sometimes UL.X or DR.Y could become negative, and when that was the case, I got a bluescreen (or, well, immediate reboot anyway).. I have fixed it in my code now, but I still find it a bit annoying that it happend as I had tons of windows and files open. I'm using MDX1 for this. Has anyone else seen this problem? Does anyone else think there should be an InvalidArgumentException thrown?

Share this post


Link to post
Share on other sites
Advertisement
Generally, hard resets in D3D are a telltale sign that something is wrong with the geometry that you are feeding the driver. Nobody knows that there is a problem until the driver is interacting with the data - and by that point, it's too late.

These problems can be as simple as incorrect primitive counts or vertex counts, or more complex like memory corruption. I would double check all of the triangles you are supplying to DP, and verify you are using the correct parameters.

Share this post


Link to post
Share on other sites
As I said (umm, intended to anyway, I'll admitt I wasn't very clear though), the problem is when I send a negative value as start vertex or primitivecount. It's obviously very wrong, and easy to fix, but still shouldn't cause a BSoD in my opinion. Sure, a device reset, or an exception, but not a BSoD. :p

Share this post


Link to post
Share on other sites
Quote:
Original post by DvDmanDT
As I said (umm, intended to anyway, I'll admitt I wasn't very clear though), the problem is when I send a negative value as start vertex or primitivecount. It's obviously very wrong, and easy to fix, but still shouldn't cause a BSoD in my opinion. Sure, a device reset, or an exception, but not a BSoD. :p


It depends on the video card and driver whether or not it will BSoD.

But as a coder, you probably shouldn't expect a low-level driver to handle incorrect input, and should at least make an attempt to ensure correctness in what you send.

After all, if it hurts when you do that...don't do that.

Share this post


Link to post
Share on other sites
Quote:
hard resets in D3D are a telltale sign that something is wrong with the geometry that you are feeding the driver.


Direct3D is an interface that spans the user/kernel mode barrier. It should catch and validate all data, and return an error if it's bad. No execptions. Else, a unprivileged user mode program can totally halt the entire machine, which is a security problem (can you say "Denial of Service" ?)

Thus, you're provoking a bug in Direct3D and/or your drivers. You should package up the crashing program in a mode where it crashes as quickly as possible (say, use a Deployment Project to create an installer), and mail it to both directx@microsoft.com, and devrel@ati.com (or devrel@nvidia.com, depending on your graphics card chipset).

Share this post


Link to post
Share on other sites
Are you using the Debug runtimes when this happens? While this shouldn't happen with the release runtimes either, I'm quite confident the debug runtimes should catch this one.

If this happens with the debug runtimes as well, this might be worth pointing out to the DX team as a missing validation.

Hope this helps.

[Edited by - sirob on August 12, 2006 11:13:16 PM]

Share this post


Link to post
Share on other sites
I wouldn't really care if it happend from unmanaged DX to be honest.. There crashes and unstableness is somewhat expected.. But this is managed stuff, isn't it supposed to run in a secure enviroment and what not..? :p

Share this post


Link to post
Share on other sites
It happens on negative values because the numerical parameters to DrawPrimitive() are unsigned integers. Thus, (uint)-1 is casted to 4294967295. Depending on the input and which parameter it is, this value could be within the max primitive count or max vertex index of the card. The driver proceeds (although input is irregular, it could be valid), tries to read the data stream to that point, and then boom.

Quote:
Direct3D is an interface that spans the user/kernel mode barrier. It should catch and validate all data, and return an error if it's bad. No execptions. Else, a unprivileged user mode program can totally halt the entire machine, which is a security problem (can you say "Denial of Service" ?)

Very good point. I am surprised some virus hasn't been written that simply resets / blue screens the machine using this technique.

Share this post


Link to post
Share on other sites
After some investigation, I have found that the managed version uses regular integers for its draw functions. The unmanaged version uses unsigned integers.

I have no idea why these are different. Ideally, unmanaged would use signed ints as well, so it could at least test for negative values. However, I don't see why the managed runtimes don't check this now, since they have the ability to do so.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement