Irritating Direct3D 11/12 Shader Cache Exception

One annoying thing existing for a long time is an internal _com_error exception in Direct3D shader cache, coming from D3DSCache.dll during execution of innocent API calls like D3D11CreateDevice. Also related storage location for the cache files is %LOCALAPPDATA%\D3DSCache, one can try deleting it completely in the case annoying issue persists.

Many of us can afford writing code with random exceptions but given the impact of Direct3D API such exceptions are intolerable. The exception is handled internally and is not passed (even as failure code) through outer API interface, but this is not a sufficient excuse: exceptions are reserved for situations when something serious happens and situation requires attention. What effectively takes place is you start an app expecting debugger to break on exception and the debugger stupidly breaks in the middle of nowhere for no apparent reason.

In some other cases I am running self-debugging applications. For example, this face detecting Telegram bot runs unmanned as a Windows service on an Intel NUC box I might not even log into for weeks. To keep a track of unexpected conditions, the service, however, runs a debugging session against itself and records minidumps for all exceptions happening so that, if needed, they could be investigated retroactively. Why would I want to mess with shader cache exceptions if they are not real problems, and are triggered as early as when I just create a device?

The error codes are sometimes E_FAIL and at other times it is DXGI_ERROR_CACHE_CORRUPT. The exception object itself is _com_error and originates from D3DSCache.dll so I have to end up filtering this stuff with otherwise unnecessary code like this:

BOOL ShouldWriteExceptionMinidump(const ParentProcessDebug::ExceptionData& Exception)
{
	[...]
	if(_wcsicmp(PathFindFileNameW(Exception.m_ModulePath.c_str()), L"D3DSCache.dll") == 0)
	{
		if(Exception.m_TypeName.compare(".?AV_com_error@@") == 0 && (Exception.m_Value == E_FAIL || Exception.m_Value == DXGI_ERROR_CACHE_CORRUPT))
			return FALSE; // D3D11On12CreateDevice API related?
	}
	[...]
	return TRUE;
}

Leave a Reply