diff options
| author | victorfisac <[email protected]> | 2018-03-10 19:25:17 +0100 |
|---|---|---|
| committer | victorfisac <[email protected]> | 2018-03-10 19:25:17 +0100 |
| commit | 3201bad65a8584c2fa587ff4e0df2c0c310d66c3 (patch) | |
| tree | 415e43fc61fb7112636a8009da14104b28e80f5e /examples/physac/physics_demo.c | |
| parent | 8f1d6f38506ff6449866913c6d88b0f25ca2d8f4 (diff) | |
| download | raylib-3201bad65a8584c2fa587ff4e0df2c0c310d66c3.tar.gz raylib-3201bad65a8584c2fa587ff4e0df2c0c310d66c3.zip | |
Fixed memory leaks in physics step operations
Diffstat (limited to 'examples/physac/physics_demo.c')
| -rw-r--r-- | examples/physac/physics_demo.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/examples/physac/physics_demo.c b/examples/physac/physics_demo.c index 1b54d51b..220c5672 100644 --- a/examples/physac/physics_demo.c +++ b/examples/physac/physics_demo.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(); @@ -52,10 +53,9 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsKeyPressed('R')) // Reset physics input + // Delay initialization of variables due to physics reset async + if (needsReset) { - ResetPhysics(); - floor = CreatePhysicsBodyRectangle((Vector2){ screenWidth/2, screenHeight }, 500, 100, 10); floor->enabled = false; @@ -63,6 +63,13 @@ int main() circle->enabled = false; } + // Reset physics input + if (IsKeyPressed('R')) + { + ResetPhysics(); + needsReset = true; + } + // Physics body creation inputs if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) CreatePhysicsBodyPolygon(GetMousePosition(), GetRandomValue(20, 80), GetRandomValue(3, 8), 10); else if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) CreatePhysicsBodyCircle(GetMousePosition(), GetRandomValue(10, 45), 10); |
