From e54107033d1046cc2aab2e00eca6858ee6892231 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 13 Oct 2013 12:05:50 +0200 Subject: [PATCH] Don't crash on post-shader compile errors. --- GPU/GLES/Framebuffer.cpp | 27 ++++++++++++++++++++++----- UI/OnScreenDisplay.cpp | 17 +++++++++++++---- native | 2 +- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index f28cb2d8f..c27330164 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -34,6 +34,8 @@ #include "GPU/GLES/TextureCache.h" #include "GPU/GLES/ShaderManager.h" +#include "UI/OnScreenDisplay.h" + #include #if defined(USING_GLES2) @@ -168,9 +170,14 @@ void FramebufferManager::SetNumExtraFBOs(int num) { void FramebufferManager::CompileDraw2DProgram() { if (!draw2dprogram_) { - draw2dprogram_ = glsl_create_source(basic_vs, tex_fs); - glsl_bind(draw2dprogram_); - glUniform1i(draw2dprogram_->sampler0, 0); + std::string errorString; + draw2dprogram_ = glsl_create_source(basic_vs, tex_fs, &errorString); + if (!draw2dprogram_) { + ERROR_LOG_REPORT(G3D, "Failed to compile draw2dprogram! This shouldn't happen.\n%s", errorString.c_str()); + } else { + glsl_bind(draw2dprogram_); + glUniform1i(draw2dprogram_->sampler0, 0); + } SetNumExtraFBOs(0); @@ -180,9 +187,19 @@ void FramebufferManager::CompileDraw2DProgram() { } if (shaderInfo) { - postShaderProgram_ = glsl_create(shaderInfo->vertexShaderFile.c_str(), shaderInfo->fragmentShaderFile.c_str()); + postShaderProgram_ = glsl_create(shaderInfo->vertexShaderFile.c_str(), shaderInfo->fragmentShaderFile.c_str(), &errorString); if (!postShaderProgram_) { - ERROR_LOG(G3D, "Failed to build post-processing program"); + // DO NOT turn this into a report, as it will pollute our logs with all kinds of + // user shader experiments. + ERROR_LOG(G3D, "Failed to build post-processing program from %s and %s!\n%s", shaderInfo->vertexShaderFile.c_str(), shaderInfo->fragmentShaderFile.c_str(), errorString.c_str()); + // let's show the first line of the error string as an OSM. + for (int i = 0; i < errorString.size(); i++) { + if (errorString[i] == '\n') { + errorString = errorString.substr(0, i); + break; + } + } + osm.Show("Post-shader error: " + errorString + " ...", 10.0f, 0xFF3090FF); usePostShader_ = false; } else { glsl_bind(postShaderProgram_); diff --git a/UI/OnScreenDisplay.cpp b/UI/OnScreenDisplay.cpp index 402d93d71..9fe23cfe5 100644 --- a/UI/OnScreenDisplay.cpp +++ b/UI/OnScreenDisplay.cpp @@ -28,10 +28,19 @@ restart: float y = 10.0f; // Then draw them all. for (auto iter = messages_.begin(); iter != messages_.end(); ++iter) { - float alpha = (iter->endTime - time_now_d()) * 4; - if (alpha > 1.0) alpha = 1.0; - if (alpha < 0.0) alpha = 0.0; - draw.DrawTextShadow(UBUNTU24, iter->text.c_str(), dp_xres / 2, y, colorAlpha(iter->color, alpha), ALIGN_TOP | ALIGN_HCENTER); + float alpha = (iter->endTime - time_now_d()) * 4.0f; + if (alpha > 1.0) alpha = 1.0f; + if (alpha < 0.0) alpha = 0.0f; + // Messages that are wider than the screen are left-aligned instead of centered. + float tw, th; + draw.MeasureText(UBUNTU24, iter->text.c_str(), &tw, &th); + float x = dp_xres / 2; + int align = ALIGN_TOP | ALIGN_HCENTER; + if (tw > dp_xres) { + align = ALIGN_TOP | ALIGN_LEFT; + x = 2; + } + draw.DrawTextShadow(UBUNTU24, iter->text.c_str(), x, y, colorAlpha(iter->color, alpha), align); y += h; } } diff --git a/native b/native index a25169dc4..d19cef239 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit a25169dc4c6a2e26c16b26faa0b37bb474c0d37e +Subproject commit d19cef23951ce6e9ff8402f9fa1b9304e940805b