Visual Studio Bug?

Started by
14 comments, last by ApochPiQ 6 years, 10 months ago

Hi,

I am using Visual Studio 2013 Express on Windows 10 to develop my game. Recently, I've ran into a problem concerning Direct3D: When I start my game, it crashes as soon as it starts rendering the first frame with different error messages stating that there was an access violation reading/writing/executing at different locations. However, when I compile the game on Windows 7, it runs on both Windows 7 and 10 without this error. When I try to run the game compiled on Windows 10 on Windows 7, it crashes, too. It does not crash in Debug build, only in Release build. I once "fixed" the problem by outputting the device context using OutputDebugString(). Some changes to the code in unrelated locations seem to "cause" this error.

I already tried re-installing Visual Studio and updating my graphics driver, but that didn't help.

Can I re-install the Direct3D SDK somehow? Or is there maybe another solution?

Edit: SOLVED (see post #15)

Advertisement

It does not crash in Debug build, only in Release build.

Without further information, this sounds like a memory-access related error, likely due to an uninitialized variable which doesn't show up in debug because memory is preinitialized there. Try a tool for detecting such errors like Microsofts application verifier (https://www.microsoft.com/en-us/download/details.aspx?id=20028), while creating debug symbols for your release build (https://msdn.microsoft.com/en-us/library/fsk896zz.aspx). This should optimally lead you to the exact point of failure.

Additional things to do: Turn on the directx debug layer + break on error/corruption, see if this leads you to the source of the crash. Static code analysis tools can also help (http://cppcheck.sourceforge.net/).

If this doesn't help, it might be something else, it just sounds like something along those lines.

It is almost never a Visual Studio bug. Even if it only crashes with one version of the compiler, the issue is usually that you are relying on undefined behaviour which can differ from one compiler to the next.

Suggestions:

  • Check that all your variables are being initialised properly, and never assume they start at some correct value if you didn't do it explicitly
  • Test your debug build with all the runtime diagnostics you can; often the problem exists in debug mode too, but it just doesn't present itself unless you look for it
  • Try creating an 'optimised debug' build; you may be able to find out more about the crash this way, although the call stack may not be 100% accurate.
  • Try using #pragma optimize("", off) around various functions - if the crash goes away, it's likely that the error lies in that part of the code

In this case, all variables were initialized. It crashes when I clear a depth buffer. When I debug the graphics, I get the warning that the depth buffer is read-only, which does not make sense because it was created to be read- and writable. I initialize the graphics in the main thread. After initialization, I create a render thread that then uses those variables. This should not be undefined behavior, though.

Additionally, I don't see how this could possibly lead to an access violation by execution, meaning the PC register is somehow invalid. The device and device context cannot be corrupted at this point since the device is thread-safe and I protect the device context by a mutex each time I use it.

I turned off optimization to test it and sometimes the error did occur without optimization, sometimes not.

This problem first occurred when I changed some unrelated code.

This problem first occurred when I changed some unrelated code.


This, in particular, indicates that the previous replies are on the right track and that you have probably missed something in your own checking.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

But why does it work on Windows 7 with the same compiler (Visual Studio 2013 Express)? It is exactly the same project (I just load it from the same location on the hard drive).

I am certain that the 3 variables involved here are actually initialized. If there was an error in the creation of the device, device context, or depth buffer, the game would have shown an error message and exited.

The code I changed last time was not even executed before the error occured... It was code for some NPC rendering, but there are no NPCs in the game menu displayed at the beginning.

The depth buffer clearing is the second instruction in the rendering and before it there is only initialization since it crashes on the first frame. I don't know what I could have missed.

It works now, though, but I don't know for how long. It worked for years (literally) without any error. I've developed this game since about 2 or 3 years and this part of the code has not changed in all this time, but it just crashed in the last two days. How could this be possible?
Could be a (graphics) driver update.

Enable DirectX debug mode (e.g. set the flags on creation). Any warnings/errors showing up there, when you run your game?

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Could be a (graphics) driver update.

Enable DirectX debug mode (e.g. set the flags on creation). Any warnings/errors showing up there, when you run your game?

As I already said, I already updated the graphics driver and the debug mode only shows a weird error message stating that the depth buffer is read-only, but nothing helpful. :(

Could you post that message? Are there any other warnings popping up?

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I cannot post the exact error message for this error does not occur at the moment, but it said something like that the depth/stencil view was created with the "depth read-only" flag and therefore ClearDepthStencilView does not clear the depth/stencil buffer. This is just not the case (I set the flags to 0), so the error message is not very helpful.

This topic is closed to new replies.

Advertisement