hdevred
hdevred

Reputation: 11

file_not_found error - directx tool kit with visual studio 2015

I am trying to migrate a program that I wrote a couple of years ago (scientific computation) in order to update it and add new functionalities.

My operating system is Windows 10. I am using Visual Studio Community 2015. No special problem to migrate my Visual 2012 code to it. The graphic part of my code (rendering of plots) was based on Direct3D 9. I understand it’s completely deprecated and I’d like to migrate to Direct3D 11.

After some investigation into that topic, it seemed to me convenient to use the DirectX ToolKit "directxtk_desktop_2015". To get familiarized with it, I decided to go through the “GitHub” tutorial called: The-basic-game-loop, Adding the DirectX Toolkit… etc https://github.com/Microsoft/DirectXTK/wiki/The-basic-game-loop

I am stuck at the 3rd step of the tutorial, which is trying to download a texture to display it on the screen:

DX::ThrowIfFailed(
    CreateWICTextureFromFile(m_d3dDevice.Get(), L"cat.png", nullptr,
    m_texture.ReleaseAndGetAddressOf())); 

It throws me a file_not_found error. What is puzzling is that the cat.png file is visible in the “Assets” of the program in the "solution" window on the right of Visual studio.

What can be causing it?

Upvotes: 1

Views: 184

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41047

The path is a relative path that assumes cat.png is in the current working directory of your program at the time it is run. Typically in a classic Win32 desktop app run with the Visual Studio IDE, the project folder is the CWD but the EXE itself is under a configuration folder (Debug, Release, etc.).

If you run the EXE from the command-line or using some other method, it's quite likely the current working directory is that configuration folder.

If you've saved the cat.png to an Assets folder (actual directory, not just a filter) under the project folder, then you need to use:

DX::ThrowIfFailed(
    CreateWICTextureFromFile(m_d3dDevice.Get(), L".\\Assets\\cat.png", nullptr,
    m_texture.ReleaseAndGetAddressOf())); 

For Universal Windows Platform (UWP) apps rather than Win32 desktop apps, the current working directory at the time you run the program is the root of the AppX package. The AppX package is created by copying all the various content files and the generated EXE into a folder, such as Debug\project name\AppX. If the content file is outside the 'project cone' folder, then it will be in the root directory of the AppX. If it's in a subdirectory, then that will get replicated in the AppX. So for example, if you have a UWP and have cat.png in the Assets folder of a UWP, then in the AppX it will end up at .\Assets\cat.png.

Upvotes: 1

Related Questions