Model loading causes access violation (-1073741819) on Windows

Hi,
I’m new to posting here and also to LibTorch. I’m facing an issue when trying to load a PyTorch model in Debug mode, and I need your help to understand what might be going wrong.
Here’s my code snippet:

#include <torch/torch.h>
#include <torch/script.h>
int main()
{
	try
	{
		model = torch::jit::load("model.pt");
	}
	catch (const c10::Error& e)
	{
		std::cerr << "Error loading model: " << e.what() << std::endl;
		exit(-1);
	}
	return 0;
}

When I run this code in Debug mode, the process exits (without printing any errors) with the code -1073741819, which indicates an access violation. However, in Release mode, the model loads successfully, and I’m able to perform predictions without any issues.

I’m using LibTorch on Windows and Visual Studio 2022, and I’m not sure why this behavior is occurring. Can someone tell me what happened? Thanks.

Just randomly browsing . Had that problem too . You need to use the debug version for debugging and the release version for the release . Which completely blows you project setup up in size