d3dx9: Correctly set parent_data for direct includes from the main file.
This commit is contained in:
parent
b5db97ac51
commit
d64ec66b41
@ -219,6 +219,20 @@ HRESULT WINAPI D3DXAssembleShader(const char *data, UINT data_len, const D3DXMAC
|
||||
return hr;
|
||||
}
|
||||
|
||||
static const void *main_file_data;
|
||||
|
||||
static CRITICAL_SECTION from_file_mutex;
|
||||
static CRITICAL_SECTION_DEBUG from_file_mutex_debug =
|
||||
{
|
||||
0, 0, &from_file_mutex,
|
||||
{
|
||||
&from_file_mutex_debug.ProcessLocksList,
|
||||
&from_file_mutex_debug.ProcessLocksList
|
||||
},
|
||||
0, 0, {(DWORD_PTR)(__FILE__ ": from_file_mutex")}
|
||||
};
|
||||
static CRITICAL_SECTION from_file_mutex = {&from_file_mutex_debug, -1, 0, 0, 0, 0};
|
||||
|
||||
/* D3DXInclude private implementation, used to implement
|
||||
* D3DXAssembleShaderFromFile() from D3DXAssembleShader(). */
|
||||
/* To be able to correctly resolve include search paths we have to store the
|
||||
@ -233,8 +247,15 @@ static HRESULT WINAPI d3dincludefromfile_open(ID3DXInclude *iface, D3DXINCLUDE_T
|
||||
HANDLE file;
|
||||
UINT size;
|
||||
|
||||
if(parent_data != NULL)
|
||||
if (parent_data)
|
||||
{
|
||||
parent_name = *((const char **)parent_data - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (main_file_data)
|
||||
parent_name = *((const char **)main_file_data - 1);
|
||||
}
|
||||
|
||||
TRACE("Looking up for include file %s, parent %s\n", debugstr_a(filename), debugstr_a(parent_name));
|
||||
|
||||
@ -265,6 +286,8 @@ static HRESULT WINAPI d3dincludefromfile_open(ID3DXInclude *iface, D3DXINCLUDE_T
|
||||
goto error;
|
||||
|
||||
*data = buffer + 1;
|
||||
if (!main_file_data)
|
||||
main_file_data = *data;
|
||||
|
||||
CloseHandle(file);
|
||||
return S_OK;
|
||||
@ -280,6 +303,8 @@ static HRESULT WINAPI d3dincludefromfile_close(ID3DXInclude *iface, const void *
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, *((char **)data - 1));
|
||||
HeapFree(GetProcessHeap(), 0, (char **)data - 1);
|
||||
if (main_file_data == data)
|
||||
main_file_data = NULL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@ -339,9 +364,11 @@ HRESULT WINAPI D3DXAssembleShaderFromFileW(const WCHAR *filename, const D3DXMACR
|
||||
return E_OUTOFMEMORY;
|
||||
WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
|
||||
|
||||
EnterCriticalSection(&from_file_mutex);
|
||||
hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
LeaveCriticalSection(&from_file_mutex);
|
||||
HeapFree(GetProcessHeap(), 0, filename_a);
|
||||
return D3DXERR_INVALIDDATA;
|
||||
}
|
||||
@ -349,6 +376,7 @@ HRESULT WINAPI D3DXAssembleShaderFromFileW(const WCHAR *filename, const D3DXMACR
|
||||
hr = D3DXAssembleShader(buffer, len, defines, include, flags, shader, error_messages);
|
||||
|
||||
ID3DXInclude_Close(include, buffer);
|
||||
LeaveCriticalSection(&from_file_mutex);
|
||||
HeapFree(GetProcessHeap(), 0, filename_a);
|
||||
return hr;
|
||||
}
|
||||
@ -471,9 +499,11 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
|
||||
return E_OUTOFMEMORY;
|
||||
WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, filename_len, NULL, NULL);
|
||||
|
||||
EnterCriticalSection(&from_file_mutex);
|
||||
hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
LeaveCriticalSection(&from_file_mutex);
|
||||
HeapFree(GetProcessHeap(), 0, filename_a);
|
||||
return D3DXERR_INVALIDDATA;
|
||||
}
|
||||
@ -487,6 +517,7 @@ HRESULT WINAPI D3DXCompileShaderFromFileW(const WCHAR *filename, const D3DXMACRO
|
||||
constant_table);
|
||||
|
||||
ID3DXInclude_Close(include, buffer);
|
||||
LeaveCriticalSection(&from_file_mutex);
|
||||
HeapFree(GetProcessHeap(), 0, filename_a);
|
||||
return hr;
|
||||
}
|
||||
@ -591,9 +622,11 @@ HRESULT WINAPI D3DXPreprocessShaderFromFileW(const WCHAR *filename, const D3DXMA
|
||||
return E_OUTOFMEMORY;
|
||||
WideCharToMultiByte(CP_ACP, 0, filename, -1, filename_a, len, NULL, NULL);
|
||||
|
||||
EnterCriticalSection(&from_file_mutex);
|
||||
hr = ID3DXInclude_Open(include, D3D_INCLUDE_LOCAL, filename_a, NULL, &buffer, &len);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
LeaveCriticalSection(&from_file_mutex);
|
||||
HeapFree(GetProcessHeap(), 0, filename_a);
|
||||
return D3DXERR_INVALIDDATA;
|
||||
}
|
||||
@ -604,6 +637,7 @@ HRESULT WINAPI D3DXPreprocessShaderFromFileW(const WCHAR *filename, const D3DXMA
|
||||
(ID3DBlob **)shader, (ID3DBlob **)error_messages);
|
||||
|
||||
ID3DXInclude_Close(include, buffer);
|
||||
LeaveCriticalSection(&from_file_mutex);
|
||||
HeapFree(GetProcessHeap(), 0, filename_a);
|
||||
return hr;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user