Check buffer overflow

This commit is contained in:
Ray 2019-04-14 22:29:14 +02:00
parent d690e734f9
commit 8c22f685d1

View file

@ -296,6 +296,8 @@ void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float hei
float y = position.y; float y = position.y;
float z = position.z; float z = position.z;
if (rlCheckBufferLimit(36)) rlglDraw();
rlEnableTexture(texture.id); rlEnableTexture(texture.id);
//rlPushMatrix(); //rlPushMatrix();
@ -357,6 +359,9 @@ void DrawSphere(Vector3 centerPos, float radius, Color color)
// Draw sphere with extended parameters // Draw sphere with extended parameters
void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color) void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color color)
{ {
int numVertex = (rings + 2)*slices*6;
if (rlCheckBufferLimit(numVertex)) rlglDraw();
rlPushMatrix(); rlPushMatrix();
// NOTE: Transformation is applied in inverse order (scale -> translate) // NOTE: Transformation is applied in inverse order (scale -> translate)
rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlTranslatef(centerPos.x, centerPos.y, centerPos.z);
@ -397,6 +402,9 @@ void DrawSphereEx(Vector3 centerPos, float radius, int rings, int slices, Color
// Draw sphere wires // Draw sphere wires
void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color) void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Color color)
{ {
int numVertex = (rings + 2)*slices*6;
if (rlCheckBufferLimit(numVertex)) rlglDraw();
rlPushMatrix(); rlPushMatrix();
// NOTE: Transformation is applied in inverse order (scale -> translate) // NOTE: Transformation is applied in inverse order (scale -> translate)
rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlTranslatef(centerPos.x, centerPos.y, centerPos.z);
@ -441,6 +449,9 @@ void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float h
{ {
if (sides < 3) sides = 3; if (sides < 3) sides = 3;
int numVertex = sides*6;
if (rlCheckBufferLimit(numVertex)) rlglDraw();
rlPushMatrix(); rlPushMatrix();
rlTranslatef(position.x, position.y, position.z); rlTranslatef(position.x, position.y, position.z);
@ -497,6 +508,9 @@ void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, fl
{ {
if (sides < 3) sides = 3; if (sides < 3) sides = 3;
int numVertex = sides*8;
if (rlCheckBufferLimit(numVertex)) rlglDraw();
rlPushMatrix(); rlPushMatrix();
rlTranslatef(position.x, position.y, position.z); rlTranslatef(position.x, position.y, position.z);
@ -524,6 +538,8 @@ void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, fl
// Draw a plane // Draw a plane
void DrawPlane(Vector3 centerPos, Vector2 size, Color color) void DrawPlane(Vector3 centerPos, Vector2 size, Color color)
{ {
if (rlCheckBufferLimit(4)) rlglDraw();
// NOTE: Plane is always created on XZ ground // NOTE: Plane is always created on XZ ground
rlPushMatrix(); rlPushMatrix();
rlTranslatef(centerPos.x, centerPos.y, centerPos.z); rlTranslatef(centerPos.x, centerPos.y, centerPos.z);
@ -560,6 +576,8 @@ void DrawGrid(int slices, float spacing)
{ {
int halfSlices = slices/2; int halfSlices = slices/2;
if (rlCheckBufferLimit(slices*4)) rlglDraw();
rlBegin(RL_LINES); rlBegin(RL_LINES);
for (int i = -halfSlices; i <= halfSlices; i++) for (int i = -halfSlices; i <= halfSlices; i++)
{ {