From 66821aa145acbb4f43c74bcbdeefc0bfbd51305d Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Mon, 1 Jun 2009 15:26:26 +0000 Subject: [PATCH] Add some error catching in the OpenGL code, this should make most OpenGL-related problems less fatal, though it can still cause funky UI problems I think. At least the user should get a slightly more useful error message now. Updates #799. Originally committed to SVN as r2998. --- aegisub/src/video_context.cpp | 31 ++++++++++++++++++++++++------- aegisub/src/video_display.cpp | 20 +++++++++++++++++++- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index bf435d06a..0be0e44c8 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -424,15 +424,32 @@ void VideoContext::JumpToFrame(int n) { // Not threaded else { - // Set frame number - frame_n = n; - GetFrameAsTexture(n); + try { + // Set frame number + frame_n = n; + GetFrameAsTexture(n); - // Display - UpdateDisplays(false); + // Display + UpdateDisplays(false); - // Update grid - if (!isPlaying && Options.AsBool(_T("Highlight subs in frame"))) grid->Refresh(false); + // Update grid + if (!isPlaying && Options.AsBool(_T("Highlight subs in frame"))) grid->Refresh(false); + } + catch (const wxChar *err) { + wxLogError( + _T("Failed seeking video. The video will be closed because of this.\n") + _T("If you get this error regardless of which video file you use, and also if you use dummy video, your OpenGL driver might not work with Aegisub.\n") + _T("Error message reported: %s"), + err); + Reset(); + } + catch (...) { + wxLogError( + _T("Failed seeking video. The video will be closed because of this.\n") + _T("If you get this error regardless of which video file you use, and also if you use dummy video, your OpenGL driver might not work with Aegisub.\n") + _T("No further error message given.")); + Reset(); + } } } diff --git a/aegisub/src/video_display.cpp b/aegisub/src/video_display.cpp index e9ede44f7..c0452fa43 100644 --- a/aegisub/src/video_display.cpp +++ b/aegisub/src/video_display.cpp @@ -168,7 +168,10 @@ void VideoDisplay::ShowCursor(bool show) { ////////// // Render -void VideoDisplay::Render() { +void VideoDisplay::Render() +// Yes it's legal C++ to replace the body of a function with one huge try..catch statement +try { + // Is shown? if (!IsShownOnScreen()) return; if (!wxIsMainThread()) throw _T("Error: trying to render from non-primary thread"); @@ -307,6 +310,21 @@ void VideoDisplay::Render() { //if (glGetError()) throw _T("Error finishing gl operation."); SwapBuffers(); } +catch (const wxChar *err) { + wxLogError( + _T("An error occurred trying to render the video frame to screen.\n") + _T("If you get this error regardless of which video file you use, and also if you use dummy video, your OpenGL driver might not work with Aegisub.\n") + _T("Error message reported: %s"), + err); + VideoContext::Get()->Reset(); +} +catch (...) { + wxLogError( + _T("An error occurred trying to render the video frame to screen.\n") + _T("If you get this error regardless of which video file you use, and also if you use dummy video, your OpenGL driver might not work with Aegisub.\n") + _T("No further error message given.")); + VideoContext::Get()->Reset(); +} ///////////////////////////////////