From 88b4b96c6e71bf541eb9cf1724d939d6e71572da Mon Sep 17 00:00:00 2001 From: xinpw8 Date: Fri, 9 Jan 2026 05:18:56 -0600 Subject: [PATCH] Fix cartpole standalone demo after contextualization Commit 941198fc ("Contextualize cartpole") moved physics parameters from #define constants to struct fields for Python configurability, but did not update cartpole.c to initialize them. This broke the standalone demo with division-by-zero / NaN errors. Initialize physics parameters using designated initializers, consistent with other ocean environments like pong.c. --- pufferlib/ocean/cartpole/cartpole.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pufferlib/ocean/cartpole/cartpole.c b/pufferlib/ocean/cartpole/cartpole.c index 20e834b37..839818a10 100644 --- a/pufferlib/ocean/cartpole/cartpole.c +++ b/pufferlib/ocean/cartpole/cartpole.c @@ -29,8 +29,15 @@ void demo() { int logit_sizes[1] = {ACTIONS_SIZE}; net = make_linearlstm(weights, 1, OBSERVATIONS_SIZE, logit_sizes, 1); - Cartpole env = {0}; - env.continuous = CONTINUOUS; + Cartpole env = { + .continuous = CONTINUOUS, + .cart_mass = 1.0f, + .pole_mass = 0.1f, + .pole_length = 0.5f, + .gravity = 9.8f, + .force_mag = 10.0f, + .tau = 0.02f, + }; allocate(&env); c_reset(&env); c_render(&env);