Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Unified Diff: gpu/command_buffer/client/gles2_c_lib.cc

Issue 5254006: Initialize destinations variables before calling GL functions... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/build_gles2_cmd_buffer.py ('k') | gpu/command_buffer/client/gles2_c_lib_autogen.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/client/gles2_c_lib.cc
===================================================================
--- gpu/command_buffer/client/gles2_c_lib.cc (revision 68425)
+++ gpu/command_buffer/client/gles2_c_lib.cc (working copy)
@@ -4,8 +4,36 @@
// These functions emluate GLES2 over command buffers for C.
+#include <assert.h>
#include "../client/gles2_lib.h"
+// Check that destination pointers point to initialized memory.
+// When the context is lost, calling GL function has no effect so if destination
+// pointers point to initialized memory it can often lead to crash bugs. eg.
+//
+// GLsizei len;
+// glGetShaderSource(shader, max_size, &len, buffer);
+// std::string src(buffer, buffer + len); // len can be uninitialized here!!!
+//
+// Because this check is not official GL this check happens only on Chrome code,
+// not Pepper.
+//
+// If it was up to us we'd just always write to the destination but the OpenGL
+// spec defines the behavior of OpenGL function, not us. :-(
+#if defined(__native_client__)
+ #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v)
+#elif defined(GPU_DCHECK)
+ #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) GPU_DCHECK(v)
+#elif defined(DCHECK)
+ #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) DCHECK(v)
+#else
+ #define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) ASSERT(v)
+#endif
+
+#define GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION(type, ptr) \
+ GL_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(ptr && \
+ (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
+
extern "C" {
// Include the auto-generated part of this file. We split this because it means
// we can easily edit the non-auto generated parts right here in this file
« no previous file with comments | « gpu/command_buffer/build_gles2_cmd_buffer.py ('k') | gpu/command_buffer/client/gles2_c_lib_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698