• Advertisement
Sign in to follow this  

DX11 Non-fatal, undocumented return code

Recommended Posts

Hi guys, I was wondering if any of you ever had an encounter with 0xCCCCCCCC as a return code/result when calling a D3D11CreateDeviceAndSwapChain or D3D11CreateDevice.

My code worked just fine as of yesterday, and did for months, but I now get 0xCCCCCCCC instead of the usual S_OK (or rarely S_FALSE) for some reason. Literally nothing in my code changed. I woke up to that return code. Whatever it is, it's in no way preventing my application from working as it should but I do have to bypass the error checking I've put in place because of how unusual the error code is.

Can anyone shed some light on this undocumented return code?

Edited by Shangbye

Share this post


Link to post
Share on other sites
Advertisement

Now that you mention it, it does look like it. The value is just plain off when I take a look at the range of the documented values.

I'll try replacing D3D11.dll and see if it changes anything. Thanks dude.

Edited by Shangbye

Share this post


Link to post
Share on other sites

You're spot on about the origin of the value. I found out about it by monitoring the value before and after the call and then I discovered that the call didn't write to the HRESULT at all so it kept 0xCCCCCCCC as its value and my error detection failed. The corruption hypothesis turned out to be correct because I had no such problem when debugging the code on my other computer. Everything makes sense to me now because it seems my Win10 installation is partly corrupted. CL.EXE and C2.DLL started giving me weird errors 2 days ago and CL.EXE eventually wouldn't run at all. I replaced them with the files from the VS installation and it fixed the issue. I guess the same thing happened to d3d11.dll. Repairing my Win10 installation should take care of it. I should have come to that conclusion sooner tbh.

Edited by Shangbye

Share this post


Link to post
Share on other sites
12 minutes ago, Shangbye said:

it seems my Win10 installation is partly corrupted. CL.EXE and C2.DLL started giving me weird errors 2 days ago and CL.EXE eventually wouldn't run at all. I replaced them with the files from the VS installation and it fixed the issue

Your HDD/SSD is failing and/or you've got a virus attacking your PC :o

Time to pull your drives out and put in a clean one.

Share this post


Link to post
Share on other sites

Outside of failing hdd/virus, your other computer assumption is absurd.

 

Undefined behavior is undefined, you could have run fine for monh then crash, cure the cancer, resolve climate change or start world war 3. Undefined behavior means everything possible.

 

In regards to uninitialized variable, usually they either get set to 0xcccc or 0 if you run a debug runtime or contains whatever was at the address if not. And you cannot rely on it to be consistent between machines or os version !

Share this post


Link to post
Share on other sites

No, all this magic numbers are Microsof, VS sure don't set memory to zero !, you can find a good list of theme here (https://stackoverflow.com/questions/127386/in-visual-studio-c-what-are-the-memory-allocation-representations). They are meant to help you debug, and be glad it gives consistent behavior to something that is not, because it allow you to catch bugs that could be silent for months. Your worst enemy would be everything initialized to 0.

Share this post


Link to post
Share on other sites
22 hours ago, galop1n said:

VS sure don't set memory to zero

Doesn't the MVSC++ compiler with debug flag enabled need to generate the explicit initialization code statements? (for me VS and MVSC++ are so coupled, pretty much the same; some skin over the compiler).

Edited by matt77hias

Share this post


Link to post
Share on other sites
On 9/1/2017 at 1:22 AM, matt77hias said:

Doesn't the MVSC++ compiler with debug flag enabled need to generate the explicit initialization code statements? (for me VS and MVSC++ are so coupled, pretty much the same; some skin over the compiler).

Exact behavior in practice depends on what debug flags are passed to the compiler, which version of the standard libraries you're linking against (debug or release), whether or not you started the program with the debugger attached, and other stuff I'm likely forgetting.  Many of these will be to use magic numbers, not zero, explicitly to help you track down what would be considered bugs in cases where the C++ standard does not require initialization, and may not initialize in Release builds.

In release builds, the compiler may make extremely aggressive optimizations about uninitialized memory, such as evaluating two mutually exclusive if statement as both being true, even though common sense would say uninitialized memory has only one value and that such a thing is impossible:  https://markshroyer.com/2012/06/c-both-true-and-false/

There are some circumstances where C++ guarantees data gets zero-initialized (global data, memory returned by calloc (clear-alloc), etc.), use those if you want your memory to be zero.  Debug patterns like CCCCCCCC help make sure you're not accidentally using something that just happens to sometimes return zero-initialized memory and expecting it to always be zero-initialized (when it may not be in Release builds, on other compilers, when the allocator starts to reuse freed memory, etc.)

EDIT:  There are also more involved tools like https://clang.llvm.org/docs/MemorySanitizer.html which cause your program to actually crash when reading uninitialized memory, specifically so you can easily find it and fix it, instead of having strange bugs in your program which can be hard to get to the bottom of.

(Additionally, there are ways to have Visual Studio use clang, gcc, and other non-Microsoft compilers - so it doesn't hurt to be specific about what you're talking about :))

Edited by MaulingMonkey
Add note of memorysanitizer

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By Hawkblood
      I've been away for a VERY long time, so if this topic has already been discussed, I couldn't find it.
      I started using VS2017 recently and I keep getting warnings like this:
      1>c:\program files (x86)\microsoft directx sdk (june 2010)\include\d3d10.h(609): warning C4005: 'D3D10_ERROR_FILE_NOT_FOUND': macro redefinition (compiling source file test.cpp) 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\shared\winerror.h(54103): note: see previous definition of 'D3D10_ERROR_FILE_NOT_FOUND' (compiling source file test.cpp) It pops up for various things, but the reasons are all the same. Something is already defined.....
      I have DXSDK June2010 and referencing the .lib and .h set correctly (otherwise I wouldn't get this, I'd get errors)
      Is there a way to correct this issue or do I just have to live with it?
       
      Also (a little off-topic) the compiler doesn't like to compile my code if I make very small changes.... What's up with that? Can I change it? Google is no help.
    • By d3daywan
      【DirectX9 Get shader bytecode】
      I hook DrawIndexedPrimitive
          HookCode(PPointer(g_DeviceBaseAddr + $148)^,@NewDrawIndexedPrimitive, @OldDrawIndexedPrimitive);    
          function NewDrawIndexedPrimitive(const Device:IDirect3DDevice9;_Type: TD3DPrimitiveType; BaseVertexIndex: Integer; MinVertexIndex, NumVertices, startIndex, primCount: LongWord): HResult; stdcall;
          var
              ppShader: IDirect3DVertexShader9;
              _Code:Pointer;
              _CodeLen:Cardinal;
          begin
              Device.GetVertexShader(ppShader);//<------1.Get ShaderObject(ppShader)
              ppShader.GetFunction(nil,_CodeLen);
              GetMem(_Code,_CodeLen);
              ppShader.GetFunction(_Code,_CodeLen);//<----2.Get bytecode from ShaderObject(ppShader)
              Result:=OldDrawIndexedPrimitive(Self,_Type,BaseVertexIndex,MinVertexIndex, NumVertices, startIndex, primCount);
          end;
      【How to DirectX11 Get VSShader bytecode?】
      I hook DrawIndexed
          pDrawIndexed:=PPointer(PUINT_PTR(UINT_PTR(g_ImmContext)+0)^ + 12 * SizeOf(Pointer))^;
          HookCode(pDrawIndexed,@NewDrawIndexed,@OldDrawIndexed);
          procedure NewDrawIndexed(g_Real_ImmContext:ID3D11DeviceContext;IndexCount:     UINT;StartIndexLocation: UINT;BaseVertexLocation: Integer); stdcall;
          var
              game_pVertexShader: ID3D11VertexShader;
                  ppClassInstances: ID3D11ClassInstance;
                  NumClassInstances: UINT
          begin
              g_Real_ImmContext.VSGetShader(game_pVertexShader,ppClassInstances,NumClassInstances);    //<------1.Get ShaderObject(game_pVertexShader)
              .....//<----【2.Here's how to get bytecode from ShaderObject(game_pVertexShader)?】
              OldDrawIndexed(ImmContext, IndexCount, StartIndexLocation, BaseVertexLocation);
          end;

      Another way:
      HOOK CreateVertexShader()
      but
      HOOK need to be created before the game CreateVertexShader, HOOK will not get bytecode if the game is running later,I need to get bytecode at any time like DirectX9
    • By matt77hias
      Is it ok to bind nullptr shader resource views and sample them in some shader? I.e. is the resulting behavior deterministic and consistent across GPU drivers? Or should one rather bind an SRV to a texture having just a single black texel?
    • By lonewolff
      Hi guys,
      I am having problems with trying to perform a basic 'shift left' on a char.
      char temp[1]; temp[0] = buffer[0] << 1; // buffer[0] is 0xff After this I have temp[0] writing to a file. Instead of being the expected 0x7F it is written as 0xF8.
      Any guidance on what I am doing wrong would be awesome.
      Thanks in advance
  • Advertisement