[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60331] branches/soc-2013-viewport_fx/ source/blender/gpu/intern/gpu_safety.c: Changed method of detecting infinite loop in gpu_check from a count to seeing the same error flag twice

Jason Wilkins Jason.A.Wilkins at gmail.com
Mon Sep 23 14:46:50 CEST 2013


Revision: 60331
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60331
Author:   jwilkins
Date:     2013-09-23 12:46:50 +0000 (Mon, 23 Sep 2013)
Log Message:
-----------
Changed method of detecting infinite loop in gpu_check from a count to seeing the same error flag twice

Modified Paths:
--------------
    branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_safety.c

Modified: branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_safety.c
===================================================================
--- branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_safety.c	2013-09-23 12:25:22 UTC (rev 60330)
+++ branches/soc-2013-viewport_fx/source/blender/gpu/intern/gpu_safety.c	2013-09-23 12:46:50 UTC (rev 60331)
@@ -1,35 +1,36 @@
 /*
-* ***** BEGIN GPL LICENSE BLOCK *****
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software Foundation,
-* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-*
-* The Original Code is Copyright (C) 2012 Blender Foundation.
-* All rights reserved.
-*
-* The Original Code is: all of this file.
-*
-* Contributor(s): Jason Wilkins.
-*
-* ***** END GPL LICENSE BLOCK *****
-*/
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2012 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Jason Wilkins.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
 
 /** \file blender/gpu/intern/gpu_safety.c
-*  \ingroup gpu
-*/
+ *  \ingroup gpu
+ */
 
-#include "gpu_safety.h"
+/* my interface */
+#include "GPU_safety.h"
 
 #if GPU_SAFETY
 
@@ -41,31 +42,35 @@
 
 void gpu_check(const char* file, int line, const char* text)
 {
-	GLboolean no_error = GL_TRUE;
-	int error_count  = 0;
+	GLboolean no_gl_error   = GL_TRUE;
+	GLenum    last_gl_error = GL_NO_ERROR;
 
 	for (;;) {
-		GLenum code = glGetError();
+		GLenum gl_error = glGetError();
 
-		if (code == GL_NO_ERROR) {
+		if (gl_error == GL_NO_ERROR) {
 			break;
 		}
 		else {
-			no_error = GL_FALSE;
+			/* glGetError should have cleared the error flag, so if we get the
+			   same flag twice that means glGetError itself probably triggered
+			   the error. This happens on Windows if the GL context is invalid.
+			 */
+			BLI_assert(gl_error != last_gl_error);
 
+			no_gl_error = GL_FALSE;
+
 			if (text == NULL)
-				fprintf(stderr, "%s(%d): GL Error (0x%04X): %s: %s\n", file, line, code, gpuErrorSymbol(code), gpuErrorString(code));
+				fprintf(stderr, "%s(%d): GL Error (0x%04X - %s): %s\n", file, line, gl_error, gpuErrorSymbol(gl_error), gpuErrorString(gl_error));
 			else
-				fprintf(stderr, "%s(%d):[%s] -> GL Error (0x%04X): %s\n", file, line, text, code, gpuErrorSymbol(code), gpuErrorString(code));
+				fprintf(stderr, "%s(%d):[%s] -> GL Error (0x%04X - %s): %s\n", file, line, text, gl_error, gpuErrorSymbol(gl_error), gpuErrorString(gl_error));
+
+			last_gl_error = gl_error;
 		}
-
-		error_count ++;
-
-		/* There should never be so many errors, but it can happen if there isn't a valid context. */
-		GPU_ASSERT(error_count < 20);
 	}
 
-	GPU_ASSERT(no_error);
+	if (!no_gl_error)
+		abort();
 }
 
 #endif




More information about the Bf-blender-cvs mailing list