瀏覽代碼

Check buffer overflow

pull/810/head
Ray 6 年之前
父節點
當前提交
8c22f685d1
共有 1 個文件被更改,包括 18 次插入0 次删除
  1. +18
    -0
      src/models.c

+ 18
- 0
src/models.c 查看文件

@ -295,6 +295,8 @@ void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float hei
float x = position.x; float x = position.x;
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);
@ -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);
@ -440,6 +448,9 @@ void DrawSphereWires(Vector3 centerPos, float radius, int rings, int slices, Col
void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int sides, Color color) void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float height, int sides, Color color)
{ {
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);
@ -496,6 +507,9 @@ void DrawCylinder(Vector3 position, float radiusTop, float radiusBottom, float h
void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int sides, Color color) void DrawCylinderWires(Vector3 position, float radiusTop, float radiusBottom, float height, int sides, Color color)
{ {
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++)
{ {

Loading…
取消
儲存