From 61db8123954e033185a1ce8cdc22bc2a27654254 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Fri, 15 Oct 2010 17:50:15 -0400 Subject: [PATCH] Bug 598838 - Fix WebGL messages (were printing uninitialized values) - r=vladimir --- content/canvas/src/WebGLContext.h | 3 +- content/canvas/src/WebGLContextGL.cpp | 2 +- content/canvas/src/WebGLContextUtils.cpp | 37 +++++++++------------ content/canvas/src/WebGLContextValidate.cpp | 6 ++-- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/content/canvas/src/WebGLContext.h b/content/canvas/src/WebGLContext.h index 476ae59e9d97..99f41f373785 100644 --- a/content/canvas/src/WebGLContext.h +++ b/content/canvas/src/WebGLContext.h @@ -506,9 +506,8 @@ public: // console logging helpers static void LogMessage(const char *fmt, ...); static void LogMessage(const char *fmt, va_list ap); - // if display is false, this won't actually do anything - static void LogMessage(bool display, const char *fmt, ...); void LogMessageIfVerbose(const char *fmt, ...); + void LogMessageIfVerbose(const char *fmt, va_list ap); friend class WebGLTexture; }; diff --git a/content/canvas/src/WebGLContextGL.cpp b/content/canvas/src/WebGLContextGL.cpp index 6f83cf0cd526..7078c039ede7 100644 --- a/content/canvas/src/WebGLContextGL.cpp +++ b/content/canvas/src/WebGLContextGL.cpp @@ -2505,7 +2505,7 @@ WebGLContext::ReadPixels_base(WebGLint x, WebGLint y, WebGLsizei width, WebGLsiz WebGLenum format, WebGLenum type, void *data, PRUint32 byteLength) { if (HTMLCanvasElement()->IsWriteOnly() && !nsContentUtils::IsCallerTrustedForRead()) { - LogMessage(mVerbose, "ReadPixels: Not allowed"); + LogMessageIfVerbose("ReadPixels: Not allowed"); return NS_ERROR_DOM_SECURITY_ERR; } diff --git a/content/canvas/src/WebGLContextUtils.cpp b/content/canvas/src/WebGLContextUtils.cpp index 8a4edaa39e06..e6a6ab4f560a 100644 --- a/content/canvas/src/WebGLContextUtils.cpp +++ b/content/canvas/src/WebGLContextUtils.cpp @@ -214,6 +214,8 @@ WebGLContext::LogMessage(const char *fmt, ...) void WebGLContext::LogMessage(const char *fmt, va_list ap) { + if (!fmt) return; + char buf[1024]; PR_vsnprintf(buf, 1024, fmt, ap); @@ -225,20 +227,6 @@ WebGLContext::LogMessage(const char *fmt, va_list ap) JS_ReportWarning(ccx, "WebGL: %s", buf); } -void -WebGLContext::LogMessage(bool display, const char *fmt, ...) -{ - if (!display) - return; - - va_list ap; - va_start(ap, fmt); - - LogMessage(fmt, ap); - - va_end(ap); -} - void WebGLContext::LogMessageIfVerbose(const char *fmt, ...) { @@ -253,6 +241,15 @@ WebGLContext::LogMessageIfVerbose(const char *fmt, ...) va_end(ap); } +void +WebGLContext::LogMessageIfVerbose(const char *fmt, va_list ap) +{ + if (!mVerbose) + return; + + LogMessage(fmt, ap); +} + nsresult WebGLContext::SynthesizeGLError(WebGLenum err) { @@ -278,8 +275,7 @@ WebGLContext::SynthesizeGLError(WebGLenum err, const char *fmt, ...) { va_list va; va_start(va, fmt); - if (fmt) - LogMessage(mVerbose, fmt, va); + LogMessageIfVerbose(fmt, va); va_end(va); return SynthesizeGLError(err); @@ -290,8 +286,7 @@ WebGLContext::ErrorInvalidEnum(const char *fmt, ...) { va_list va; va_start(va, fmt); - if (fmt) - LogMessage(mVerbose, fmt, va); + LogMessageIfVerbose(fmt, va); va_end(va); return SynthesizeGLError(LOCAL_GL_INVALID_ENUM); @@ -302,8 +297,7 @@ WebGLContext::ErrorInvalidOperation(const char *fmt, ...) { va_list va; va_start(va, fmt); - if (fmt) - LogMessage(mVerbose, fmt, va); + LogMessageIfVerbose(fmt, va); va_end(va); return SynthesizeGLError(LOCAL_GL_INVALID_OPERATION); @@ -314,8 +308,7 @@ WebGLContext::ErrorInvalidValue(const char *fmt, ...) { va_list va; va_start(va, fmt); - if (fmt) - LogMessage(mVerbose, fmt, va); + LogMessageIfVerbose(fmt, va); va_end(va); return SynthesizeGLError(LOCAL_GL_INVALID_VALUE); diff --git a/content/canvas/src/WebGLContextValidate.cpp b/content/canvas/src/WebGLContextValidate.cpp index 42bc551eaf3d..d06bbdae26f3 100644 --- a/content/canvas/src/WebGLContextValidate.cpp +++ b/content/canvas/src/WebGLContextValidate.cpp @@ -111,7 +111,7 @@ WebGLContext::ValidateBuffers(PRUint32 count) continue; if (vd.buf == nsnull) { - LogMessage(mVerbose, "No VBO bound to enabled attrib index %d!", i); + LogMessageIfVerbose("No VBO bound to enabled attrib index %d!", i); return PR_FALSE; } @@ -126,12 +126,12 @@ WebGLContext::ValidateBuffers(PRUint32 count) CheckedUint32(vd.componentSize()) * vd.size; // and the number of bytes needed for these components if (!checked_needed.valid()) { - LogMessage(mVerbose, "Integer overflow computing the size of bound vertex attrib buffer at index %d", i); + LogMessageIfVerbose("Integer overflow computing the size of bound vertex attrib buffer at index %d", i); return PR_FALSE; } if (vd.buf->ByteLength() < checked_needed.value()) { - LogMessage(mVerbose, "VBO too small for bound attrib index %d: need at least %d bytes, but have only %d", + LogMessageIfVerbose("VBO too small for bound attrib index %d: need at least %d bytes, but have only %d", i, checked_needed.value(), vd.buf->ByteLength()); return PR_FALSE; }