Added some security checks on GenMesh*() #1454
This commit is contained in:
parent
7a0e73331d
commit
cd3eb3d8bd
1 changed files with 192 additions and 164 deletions
30
src/models.c
30
src/models.c
|
@ -1310,10 +1310,11 @@ bool IsModelAnimationValid(Model model, ModelAnimation anim)
|
|||
Mesh GenMeshPoly(int sides, float radius)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
if (sides < 3) return mesh;
|
||||
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
int vertexCount = sides*3;
|
||||
|
||||
// Vertices definition
|
||||
|
@ -1680,6 +1681,9 @@ par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron
|
|||
RLAPI Mesh GenMeshSphere(float radius, int rings, int slices)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
|
||||
if ((rings >= 3) && (slices >= 3))
|
||||
{
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
par_shapes_mesh *sphere = par_shapes_create_parametric_sphere(slices, rings);
|
||||
|
@ -1711,6 +1715,8 @@ RLAPI Mesh GenMeshSphere(float radius, int rings, int slices)
|
|||
|
||||
// Upload vertex data to GPU (static mesh)
|
||||
rlLoadMesh(&mesh, false);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "MESH: Failed to generate mesh: sphere");
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
@ -1719,6 +1725,11 @@ RLAPI Mesh GenMeshSphere(float radius, int rings, int slices)
|
|||
RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
|
||||
if ((rings >= 3) && (slices >= 3))
|
||||
{
|
||||
if (radius < 0.0f) radius = 0.0f;
|
||||
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
par_shapes_mesh *sphere = par_shapes_create_hemisphere(slices, rings);
|
||||
|
@ -1750,6 +1761,8 @@ RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices)
|
|||
|
||||
// Upload vertex data to GPU (static mesh)
|
||||
rlLoadMesh(&mesh, false);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "MESH: Failed to generate mesh: hemisphere");
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
@ -1758,6 +1771,9 @@ RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices)
|
|||
Mesh GenMeshCylinder(float radius, float height, int slices)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
|
||||
if (slices >= 3)
|
||||
{
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
// Instance a cylinder that sits on the Z=0 plane using the given tessellation
|
||||
|
@ -1810,6 +1826,8 @@ Mesh GenMeshCylinder(float radius, float height, int slices)
|
|||
|
||||
// Upload vertex data to GPU (static mesh)
|
||||
rlLoadMesh(&mesh, false);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "MESH: Failed to generate mesh: cylinder");
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
@ -1818,6 +1836,9 @@ Mesh GenMeshCylinder(float radius, float height, int slices)
|
|||
Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
|
||||
if ((sides >= 3) && (radSeg >= 3))
|
||||
{
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
if (radius > 1.0f) radius = 1.0f;
|
||||
|
@ -1853,6 +1874,8 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
|
|||
|
||||
// Upload vertex data to GPU (static mesh)
|
||||
rlLoadMesh(&mesh, false);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "MESH: Failed to generate mesh: torus");
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
@ -1861,6 +1884,9 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides)
|
|||
Mesh GenMeshKnot(float radius, float size, int radSeg, int sides)
|
||||
{
|
||||
Mesh mesh = { 0 };
|
||||
|
||||
if ((sides >= 3) && (radSeg >= 3))
|
||||
{
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
if (radius > 3.0f) radius = 3.0f;
|
||||
|
@ -1894,6 +1920,8 @@ Mesh GenMeshKnot(float radius, float size, int radSeg, int sides)
|
|||
|
||||
// Upload vertex data to GPU (static mesh)
|
||||
rlLoadMesh(&mesh, false);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "MESH: Failed to generate mesh: knot");
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue