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.
This commit is contained in:
Antonis Ryakiotakis 2015-07-17 12:25:05 +02:00
parent 0b121d6a5d
commit 1b8e0d03d4
3 changed files with 22 additions and 21 deletions

View File

@ -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);

View File

@ -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 */

View File

@ -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: