I have an application (running in VS2015) that procedurally creates 3D meshes and then renders them. I set it to run with a lot of different settings in a loop doing this:
1. Create a mesh on the CPU
2. Upload it to the GPU and release it on the CPU
3. Render it and take a screenshot
4. Deallocate it from the GPU
When I run it in debug mode it seems to run fine. But when I run it in release mode, after about 200 iterations (although this varies) I get a _com_error exception when calling ID3D11Device:CreateBuffer and VS breaks on the exception. It might be a GPU memory problem because it often happens for large models (200MB) but I am not sure. I have used process manager to monitor GPU memory usage when the app is running and it seems to work correctly (there are no memory leaks and the usage never goes above 300MB).
My problem is that I can't get to the error mesage from the exception. I have written a try and catch block but the program completely ignores it:
try
{
device->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &model->vertexBuffer);
}
catch (_com_error &e)
{
std::string description = e.Description();
DebugOutput("_com_error exception thrown: \n %s\n", description.c_str());
LPCTSTR errMsg = e.ErrorMessage();
HRESULT h = e.Error();
DebugOutput("%d\n", h);
DebugOutput("%s\n", errMsg);
}
Nothing is ever printed out and if I set a breakpoint in the catch block it is never accessed. When I let VS continue after breaking it ignores the catch block and goes on where the NULL vertexBuffer causes it to crash.
Am I handling the exception correctly?