Commit: 1b8e0d03d413a54ceb7d6397c696b59bb7c6f91b
Author: Antony Riakiotakis
Date:   Fri Jul 17 12:25:05 2015 +0200
Branches: master
https://developer.blender.org/rB1b8e0d03d413a54ceb7d6397c696b59bb7c6f91b

Fix no longer being possible to display a suzanne with 8 levels of
subdivision.

Classic integet overflow/size_t substitution case. Machines are getting
powerful enough to easily expose these kinds of error now.

===================================================================

M       source/blender/blenkernel/intern/cdderivedmesh.c
M       source/blender/gpu/GPU_buffers.h
M       source/blender/gpu/intern/gpu_buffers.c

===================================================================

diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c 
b/source/blender/blenkernel/intern/cdderivedmesh.c
index 5f53fa6..69e69bf 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -945,7 +945,7 @@ static void cdDM_drawMappedFacesGLSL(
                int tot_active_mat;
                GPUBuffer *buffer = NULL;
                char *varray;
-               int max_element_size = 0;
+               size_t max_element_size = 0;
                int tot_loops = 0;
 
                GPU_vertex_setup(dm);
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 12e6626..779521a 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -39,6 +39,8 @@
 #  define DEBUG_VBO(X)
 #endif
 
+#include <stddef.h>
+
 struct BMesh;
 struct CCGElem;
 struct CCGKey;
@@ -50,7 +52,7 @@ struct PBVH;
 struct MVert;
 
 typedef struct GPUBuffer {
-       int size;        /* in bytes */
+       size_t size;        /* in bytes */
        void *pointer;   /* used with vertex arrays */
        unsigned int id; /* used with vertex buffer objects */
        bool use_vbo;    /* true for VBOs, false for vertex arrays */
@@ -58,12 +60,12 @@ typedef struct GPUBuffer {
 
 typedef struct GPUBufferMaterial {
        /* range of points used for this material */
-       int start;
-       int totelements;
-       int totloops;
-       int *polys; /* array of polygons for this material */
-       int totpolys; /* total polygons in polys */
-       int counter; /* general purpose counter, initialize first! */
+       unsigned int start;
+       unsigned int totelements;
+       unsigned int totloops;
+       unsigned int *polys; /* array of polygons for this material */
+       unsigned int totpolys; /* total polygons in polys */
+       unsigned int counter; /* general purpose counter, initialize first! */
 
        /* original material index */
        short mat_nr;
@@ -106,23 +108,22 @@ typedef struct GPUDrawObject {
 #endif
        
        int colType;
-       int index_setup; /* how indices are setup, starting from start of 
buffer or start of material */
 
        GPUBufferMaterial *materials;
        int totmaterial;
        
-       int tot_triangle_point;
-       int tot_loose_point;
+       unsigned int tot_triangle_point;
+       unsigned int tot_loose_point;
        /* different than total loops since ngons get tesselated still */
-       int tot_loop_verts;
+       unsigned int tot_loop_verts;
        
        /* caches of the original DerivedMesh values */
-       int totvert;
-       int totedge;
+       unsigned int totvert;
+       unsigned int totedge;
 
-       int loose_edge_offset;
-       int tot_loose_edge_drawn;
-       int tot_edge_drawn;
+       unsigned int loose_edge_offset;
+       unsigned int tot_loose_edge_drawn;
+       unsigned int tot_edge_drawn;
 } GPUDrawObject;
 
 /* currently unused */
diff --git a/source/blender/gpu/intern/gpu_buffers.c 
b/source/blender/gpu/intern/gpu_buffers.c
index cd3a5d6..e86ca0f 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -75,7 +75,7 @@ typedef struct {
 } GPUBufferTypeSettings;
 
 
-static int gpu_buffer_size_from_type(DerivedMesh *dm, GPUBufferType type);
+static size_t gpu_buffer_size_from_type(DerivedMesh *dm, GPUBufferType type);
 
 const GPUBufferTypeSettings gpu_buffer_type_settings[] = {
     /* vertex */
@@ -471,7 +471,7 @@ void GPU_drawobject_free(DerivedMesh *dm)
        dm->drawObject = NULL;
 }
 
-static GPUBuffer *gpu_try_realloc(GPUBufferPool *pool, GPUBuffer *buffer, int 
size, bool use_VBOs)
+static GPUBuffer *gpu_try_realloc(GPUBufferPool *pool, GPUBuffer *buffer, 
size_t size, bool use_VBOs)
 {
        gpu_buffer_free_intern(buffer);
        gpu_buffer_pool_delete_last(pool);
@@ -498,7 +498,7 @@ static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, 
GPUDrawObject *object,
        const GPUBufferTypeSettings *ts = &gpu_buffer_type_settings[type];
        GLenum target = ts->gl_buffer_type;
        int num_components = ts->num_components;
-       int size = gpu_buffer_size_from_type(dm, type);
+       size_t size = gpu_buffer_size_from_type(dm, type);
        bool use_VBOs = (GLEW_ARB_vertex_buffer_object) && !(U.gameflags & 
USER_DISABLE_VBO);
        GLboolean uploaded;
 
@@ -607,7 +607,7 @@ static GPUBuffer 
**gpu_drawobject_buffer_from_type(GPUDrawObject *gdo, GPUBuffer
 }
 
 /* get the amount of space to allocate for a buffer of a particular type */
-static int gpu_buffer_size_from_type(DerivedMesh *dm, GPUBufferType type)
+static size_t gpu_buffer_size_from_type(DerivedMesh *dm, GPUBufferType type)
 {
        switch (type) {
                case GPU_BUFFER_VERTEX:

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to