CreateDDSTextureFromFile crashes on setprivatedata

Feb 21, 2013 at 11:02 PM
Hello, am very new to D3D11, hope I put all things clear to solve my problem.

Am using this sample code as a reference to follow up tutorials from Beginning DirectX11 Game Programming.
Am compiling to a x64 target on Win7, with VStudio2012.
I already redirected my project paths to use Win8 sdk, already ran some of the applications implemented on the book, however I discover some of the features, like DDS texture loading, are deprecated for the previous DX lib, but now supported on XTEx & XTK.
I compiled the XTK lib for x64, it links. When using CreateDDSTextureFromFile, now it crashes on the DDSTExtureLoader::CreateDDSTextureFromFile function (1365 line) am clueless what to do next. The DDS is one provided from the code site of the book I just mentioned.

Appreciate you help. Thanks in advance
Coordinator
Feb 21, 2013 at 11:11 PM
Edited Feb 21, 2013 at 11:12 PM
The SetPrivateData calls are for 'naming' the object for the Direct3D debug layer, so they aren't technically required.

Can you try running the DirectXTK sample on your desktop in Debug to see if it works for you?
Coordinator
Feb 21, 2013 at 11:15 PM
Edited Feb 21, 2013 at 11:15 PM
What's the content of the variables strFileA and fileName at the time of the crash?
Feb 21, 2013 at 11:41 PM
Edited Feb 21, 2013 at 11:47 PM
walbourn, sure where is the sample? I only found DirectXTK_Desktop_2012 which builds the lib and has a MakeSpriteFont tool
strFileA and fileName have a correct relative path values
Coordinator
Feb 22, 2013 at 12:33 AM
Feb 22, 2013 at 12:46 AM
Thank you! I didn't really know those samples were there, but will keep in mind for the next. I compiled with same target and works as a charm, gonna review the code, hopefully there I can find my problem
Feb 22, 2013 at 12:58 AM
Edited Feb 22, 2013 at 1:01 AM
I can quickly notice a difference, for my program to link, need to add the DirectXTK.lib, on the demo there is not such, no aditional lib dirs, links fine.
I see no pragma on cpp, but then am missing one step. I tried copying the macros defined there, but still the link error
 error LNK2019: unresolved external symbol "long __cdecl DirectX::CreateDDSTextureFromFile
What am doing wrong?

Edit: taking the demo libs set up I ended up with this inputs
d3d11.lib
D3dcompiler.lib
dxguid.lib
winmm.lib

D3Dcompiler because am compiling for debug, no problem.
Coordinator
Feb 22, 2013 at 5:42 AM
Edited Feb 22, 2013 at 5:43 AM
That's because the most robust way to do this is to use a 'Reference' within the solution file which implicity links against the output of the DirectXTK project. See the CodePlex doc page under "Adding to a VS Project".

You still have to manually add the DirectXTK\Inc folder to your Additional Include Directories settings for your project, but the Reference takes care of coordinating the build and specifying the correct paths for linking the lib for all configurations and platforms.
Feb 22, 2013 at 1:07 PM
Good.
Having said that, I really doubt this would be the cause of the problem, am gonna trying setting up the lib as a Reference anyways.
Feb 22, 2013 at 1:22 PM
Very nice, finally added as a reference no more crash, why would this behave so different than referencing manually?
Now my problems seems to be about the dds file the DDSTExtureLoader::CreateTextureFromDDS ends with the ERROR_NOT_SUPPORTED

        format = GetDXGIFormat( header->ddspf );

        if (format == DXGI_FORMAT_UNKNOWN)
        {
           return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );
        }
Strange I have opened the DDS file on VStudio2012 it reports a colorFormat 32bpp RGBA, is this format the DDS_ALPHA which is not detected run time?
Coordinator
Feb 22, 2013 at 5:40 PM
Edited Feb 22, 2013 at 5:52 PM
RE: Reference vs. .lib

I don't actually know why it failed before, it is quite possible it was not using the correctly matching configuration version so it wasn't building with the same settings. Static libraries are a bit more sensitive to mixing build settings than DLLs.


RE: DDS Failing to Load
More than likely the file in question is actually a legacy format, 24bpp, which is not supported by DDSTextureLoader. You can convert it to something that is supported easily enough using DirectXTex (which is actually what Visual Studio 2012 uses to read legacy DDS files). See the DDSTextureLoader doc page for details.
Feb 22, 2013 at 7:10 PM
Correct, I will investigate further on the legacy format, the texture was taken from the code samples of the book, I thought they at least have a standard format, but it seems a problem. I also read this was documented here Legacy 24bpp DDS.. , sorry for it. Very much appreciate you help.
Feb 22, 2013 at 10:06 PM
Correct, I will investigate further on the legacy format, the texture was taken from the code samples of the book, I thought they at least have a standard format, but it seems a problem. I also read this was documented here Legacy 24bpp DDS.. , sorry for it. Very much appreciate you help.
Coordinator
Feb 22, 2013 at 10:15 PM
To be fair to the book authors, 24bpp was a standard format back in the days of Direct3D 9... it's just not in DirectX 11.
Feb 23, 2013 at 7:11 PM
Two final comments;
  • Apparently the original problem was originated from the legacy 24bpp DDS, library loaded as a reference and manually as an input, resulted on different error behaviors at least on my computer, I could reproduce it again.
  • And truly I appreciate book authors, it was just misleading finding a non compatible texture within a set of DirecX11 [code sample], (http://www.ultimategameprogramming.com/BeginningDirectX11/BeginningDirectX11Code.zip) maybe would be better to drop the authors a mail about it ,to get things easier for everyone.
Coordinator
Feb 24, 2013 at 5:31 AM
Edited Feb 24, 2013 at 5:33 AM
The Beginning DirectX 11 book is probably using the legacy D3DX11 library in legacy DirectX SDK which would load the legacy file format and perform the needed conversions, as would using DirectXTex. MSFT does not have any official review process for 3rd party books, so such books often reflect somewhat dated practices. Given that the book came out in 2011, and the D3DX11 library was declared legacy in 2012, that's not really surprising. The truth is that technical books always age really fast.

By Design DDSTextureLoader does not do any conversions at load time.