Skip to content

Commit 421455d

Browse files
committed
glsl_restart: Stop segfaulting
Using git bisect, e497a08 introduces a window where globalUBOProxy can be null after glsl_restart. Therefore, also return early, if glboalUBOProxy is null. It will be instantiated later. Further, only initialize world shaders *AFTER* all shader storage has been initiialized.
1 parent 6f57fac commit 421455d

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/engine/renderer/tr_backend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3000,7 +3000,7 @@ static void RB_RenderPostProcess()
30003000

30013001
static void SetFrameUniforms() {
30023002
// This can happen with glsl_restart/vid_restart in R_SyncRenderThread()
3003-
if ( !stagingBuffer.Active() ) {
3003+
if ( !stagingBuffer.Active() || globalUBOProxy == nullptr ) {
30043004
return;
30053005
}
30063006

src/engine/renderer/tr_shade.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static void EnableAvailableFeatures()
198198
glConfig.usingGeometryCache = glConfig.usingMaterialSystem && glConfig.geometryCacheAvailable;
199199
}
200200

201-
// For shaders that require map data for compile-time values
201+
// For shaders that require map data for compile-time values
202202
void GLSL_InitWorldShaders() {
203203
// make sure the render thread is stopped
204204
R_SyncRenderThread();
@@ -256,11 +256,6 @@ static void GLSL_InitGPUShadersOrError()
256256
gl_depthReductionShader->MarkProgramForBuilding();
257257
}
258258

259-
if ( tr.world ) // this only happens with /glsl_restart
260-
{
261-
GLSL_InitWorldShaders();
262-
}
263-
264259
if ( glConfig.realtimeLighting )
265260
{
266261
gl_shaderManager.LoadShader( gl_depthtile1Shader );
@@ -344,7 +339,7 @@ static void GLSL_InitGPUShadersOrError()
344339

345340
gl_contrastShader->MarkProgramForBuilding();
346341
}
347-
342+
348343
// portal process effect
349344
gl_shaderManager.LoadShader( gl_portalShader );
350345

@@ -397,6 +392,12 @@ static void GLSL_InitGPUShadersOrError()
397392
gl_shaderManager.PostProcessGlobalUniforms();
398393
gl_shaderManager.InitShaders();
399394

395+
// Init world shaders last so that everyhthing is already initialized.
396+
if ( tr.world ) // this only happens with /glsl_restart
397+
{
398+
GLSL_InitWorldShaders();
399+
}
400+
400401
if ( r_lazyShaders.Get() == 0 )
401402
{
402403
gl_shaderManager.BuildAll( false );
@@ -1481,7 +1482,7 @@ void Render_heatHaze( shaderStage_t *pStage )
14811482

14821483
// bind u_NormalMap
14831484
gl_heatHazeShader->SetUniform_NormalMapBindless(
1484-
GL_BindToTMU( 0, pStage->bundle[TB_NORMALMAP].image[0] )
1485+
GL_BindToTMU( 0, pStage->bundle[TB_NORMALMAP].image[0] )
14851486
);
14861487

14871488
if ( pStage->enableNormalMapping )
@@ -1497,7 +1498,7 @@ void Render_heatHaze( shaderStage_t *pStage )
14971498

14981499
// bind u_CurrentMap
14991500
gl_heatHazeShader->SetUniform_CurrentMapBindless(
1500-
GL_BindToTMU( 1, tr.currentRenderImage[backEnd.currentMainFBO] )
1501+
GL_BindToTMU( 1, tr.currentRenderImage[backEnd.currentMainFBO] )
15011502
);
15021503

15031504
gl_heatHazeShader->SetRequiredVertexPointers();
@@ -1507,7 +1508,7 @@ void Render_heatHaze( shaderStage_t *pStage )
15071508
// copy to foreground image
15081509
R_BindFBO( tr.mainFBO[ backEnd.currentMainFBO ] );
15091510
gl_heatHazeShader->SetUniform_CurrentMapBindless(
1510-
GL_BindToTMU( 1, tr.currentRenderImage[1 - backEnd.currentMainFBO] )
1511+
GL_BindToTMU( 1, tr.currentRenderImage[1 - backEnd.currentMainFBO] )
15111512
);
15121513
gl_heatHazeShader->SetUniform_DeformMagnitude( 0.0f );
15131514
Tess_DrawElements();

0 commit comments

Comments
 (0)