Skip to content

Commit b97af10

Browse files
d3d9: Show error when default shaders fail.
1 parent 265094f commit b97af10

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

GPU/Directx9/helper/global.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,25 @@ bool CompileVertexShader(const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, LPD
139139
return true;
140140
}
141141

142-
void CompileShaders() {
143-
std::string errorMsg;
144-
142+
bool CompileShaders(std::string &errorMsg) {
145143
if (!CompileVertexShader(vscode, &pFramebufferVertexShader, NULL, errorMsg)) {
146144
OutputDebugStringA(errorMsg.c_str());
147-
DebugBreak();
145+
return false;
148146
}
149147

150148
if (!CompilePixelShader(pscode, &pFramebufferPixelShader, NULL, errorMsg)) {
151149
OutputDebugStringA(errorMsg.c_str());
152-
DebugBreak();
150+
if (pFramebufferVertexShader) {
151+
pFramebufferVertexShader->Release();
152+
}
153+
return false;
153154
}
154155

155156
pD3Ddevice->CreateVertexDeclaration(VertexElements, &pFramebufferVertexDecl);
156157
pD3Ddevice->SetVertexDeclaration(pFramebufferVertexDecl);
157158
pD3Ddevice->CreateVertexDeclaration(SoftTransVertexElements, &pSoftVertexDecl);
159+
160+
return true;
158161
}
159162

160163
void DestroyShaders() {
@@ -207,7 +210,8 @@ void DirectxInit(HWND window) {
207210
pD3Ddevice->SetRingBufferParameters( &d3dr );
208211
#endif
209212

210-
CompileShaders();
213+
std::string errorMessage;
214+
CompileShaders(errorMessage);
211215

212216
fbo_init(pD3D);
213217
}

GPU/Directx9/helper/global.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern LPDIRECT3DPIXELSHADER9 pFramebufferPixelShader; // Pixel Shader
2525
extern IDirect3DVertexDeclaration9* pFramebufferVertexDecl;
2626
extern IDirect3DVertexDeclaration9* pSoftVertexDecl;
2727

28-
void CompileShaders();
28+
bool CompileShaders(std::string &errorMessage);
2929
bool CompilePixelShader(const char *code, LPDIRECT3DPIXELSHADER9 *pShader, ID3DXConstantTable **pShaderTable, std::string &errorMessage);
3030
bool CompileVertexShader(const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, ID3DXConstantTable **pShaderTable, std::string &errorMessage);
3131
void DestroyShaders();

Windows/D3D9Base.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,7 @@ bool D3D9_Init(HWND hWnd, bool windowed, std::string *error_message) {
153153

154154
if (FAILED(hr)) {
155155
*error_message = "Failed to create D3D device";
156-
if (has9Ex) {
157-
d3dEx->Release();
158-
} else {
159-
d3d->Release();
160-
}
156+
d3d->Release();
161157
return false;
162158
}
163159

@@ -167,7 +163,18 @@ bool D3D9_Init(HWND hWnd, bool windowed, std::string *error_message) {
167163

168164
LoadD3DX9Dynamic();
169165

170-
DX9::CompileShaders();
166+
if (!DX9::CompileShaders(*error_message)) {
167+
*error_message = "Unable to compile shaders: " + *error_message;
168+
device->EndScene();
169+
device->Release();
170+
d3d->Release();
171+
DX9::pD3Ddevice = nullptr;
172+
DX9::pD3DdeviceEx = nullptr;
173+
device = nullptr;
174+
UnloadD3DXDynamic();
175+
return false;
176+
}
177+
171178
DX9::fbo_init(d3d);
172179

173180
if (deviceEx && IsWin7OrLater()) {
@@ -182,12 +189,13 @@ void D3D9_Resize(HWND window) {
182189
// TODO!
183190
}
184191

185-
void D3D9_Shutdown() {
192+
void D3D9_Shutdown() {
186193
DX9::DestroyShaders();
187194
DX9::fbo_shutdown();
188195
device->EndScene();
189196
device->Release();
190197
d3d->Release();
198+
UnloadD3DXDynamic();
191199
DX9::pD3Ddevice = nullptr;
192200
DX9::pD3DdeviceEx = nullptr;
193201
device = nullptr;

0 commit comments

Comments
 (0)