Fix Memory out of bounds in [shapes] example - ball physics (#5683)

Update screenshot to shapes_bouncing_ball.png
This commit is contained in:
Jopestpe
2026-03-23 07:28:28 -03:00
committed by GitHub
parent 1b084ff9f2
commit 22cc2554b1
2 changed files with 4 additions and 2 deletions

View File

@ -45,7 +45,8 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - ball physics"); InitWindow(screenWidth, screenHeight, "raylib [shapes] example - ball physics");
Ball balls[MAX_BALLS] = {{ Ball *balls = (Ball*)malloc(sizeof(Ball)*MAX_BALLS);
balls[0] = (Ball){
.pos = { GetScreenWidth()/2.0f, GetScreenHeight()/2.0f }, .pos = { GetScreenWidth()/2.0f, GetScreenHeight()/2.0f },
.vel = { 200, 200 }, .vel = { 200, 200 },
.ppos = { 0 }, .ppos = { 0 },
@ -54,7 +55,7 @@ int main(void)
.elasticity = 0.9f, .elasticity = 0.9f,
.color = BLUE, .color = BLUE,
.grabbed = false .grabbed = false
}}; };
int ballCount = 1; int ballCount = 1;
Ball *grabbedBall = NULL; // A pointer to the current ball that is grabbed Ball *grabbedBall = NULL; // A pointer to the current ball that is grabbed
@ -214,6 +215,7 @@ int main(void)
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
free(balls);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB