summaryrefslogtreecommitdiffhomepage
path: root/examples/physac/physics_shatter.c
diff options
context:
space:
mode:
authorvictorfisac <[email protected]>2018-03-10 19:25:17 +0100
committervictorfisac <[email protected]>2018-03-10 19:25:17 +0100
commit3201bad65a8584c2fa587ff4e0df2c0c310d66c3 (patch)
tree415e43fc61fb7112636a8009da14104b28e80f5e /examples/physac/physics_shatter.c
parent8f1d6f38506ff6449866913c6d88b0f25ca2d8f4 (diff)
downloadraylib-3201bad65a8584c2fa587ff4e0df2c0c310d66c3.tar.gz
raylib-3201bad65a8584c2fa587ff4e0df2c0c310d66c3.zip
Fixed memory leaks in physics step operations
Diffstat (limited to 'examples/physac/physics_shatter.c')
-rw-r--r--examples/physac/physics_shatter.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/examples/physac/physics_shatter.c b/examples/physac/physics_shatter.c
index 6b474cd3..f4291cac 100644
--- a/examples/physac/physics_shatter.c
+++ b/examples/physac/physics_shatter.c
@@ -32,6 +32,7 @@ int main()
// Physac logo drawing position
int logoX = screenWidth - MeasureText("Physac", 30) - 10;
int logoY = 15;
+ bool needsReset = false;
// Initialize physics and default physics bodies
InitPhysics();
@@ -48,14 +49,19 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- if (IsKeyPressed('R')) // Reset physics input
+ // Delay initialization of variables due to physics reset asynchronous
+ if (needsReset)
{
- ResetPhysics();
-
// Create random polygon physics body to shatter
body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
}
+ if (IsKeyPressed('R')) // Reset physics input
+ {
+ ResetPhysics();
+ needsReset = true;
+ }
+
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // Physics shatter input
{
// Note: some values need to be stored in variables due to asynchronous changes during main thread