How can I resolve the access violation exception when opening a USD file using my custom-built USD C++ library?

I am currently trying to use the USD C++ library in a custom C++ project on Windows 11, using Visual Studio 2019.

From the USD GitHub repo https://github.com/PixarAnimationStudios/USD, I downloaded the latest source code release and built the lib using the build_usd.py located in the build_scripts/ directory. I built the libary with a few flags to avoid building unnecessary features (I basically only kept Alembic and HDF5 flags because I am planning to use the Alembic library in the same project).

However, once the library is added to my project, I run this block of code :

#include <iostream>
#include <pxr/pxr.h>
#include <pxr/usd/usd/stage.h>

int main() {
    std::string a("C:\\Users\\h.debouard\\Desktop\\Kitchen_set\\Kitchen_set.usd");
    pxr::UsdStageRefPtr stage = pxr::UsdStage::Open(a);
    return 0;
}

I get the following thrown exception :
Exception thrown at 0x00007FF810001190 (vcruntime140.dll) in alembicwrapper.exe : 0xC0000005 : Access violation reading location 0x00000219EF1A0000.

No matter how many extra libraries I try to add or build options I change, I still encounter this error and I haven’t been able to find the answer on the issue section of the GitHub page.

What am I doing wrong here ? Is this an issue that could be related to the compiler ?

The first problem for me is that I have to include several directories to the project, and not only the USD include/ directory from the build/ folder, otherwise I get errors telling me some header files from the library can’t be located.

What bugs me is that those extra directories are located in the USD include/ directory itself, the paths indicated in some of the source files in the #include <some-source-lib.h> line are not correct, which is why I need to add those.

I also need to link against several libraries that are also located in the build/lib and build/bin dirs in order to avoid some LNK2019 errors.

My goal here is just to open a USD file in order to check if the lib is working correctly. I know my USD file is correct since it is an official example from the USD website.

Hi @hdebouard. I’m not sure about this one. Could you log the issue here? Issues · PixarAnimationStudios/USD · GitHub

1 Like