Skip to content

Commit f8ea6ba

Browse files
committed
fix: allocate truncations buffer in drive.h
1 parent ace715f commit f8ea6ba

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

pufferlib/ocean/drive/drive.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,13 +1437,15 @@ void allocate(Drive *env) {
14371437
env->actions = (float *)calloc(env->active_agent_count * 2, sizeof(float));
14381438
env->rewards = (float *)calloc(env->active_agent_count, sizeof(float));
14391439
env->terminals = (unsigned char *)calloc(env->active_agent_count, sizeof(unsigned char));
1440+
env->truncations = (unsigned char *)calloc(env->active_agent_count, sizeof(unsigned char));
14401441
}
14411442

14421443
void free_allocated(Drive *env) {
14431444
free(env->observations);
14441445
free(env->actions);
14451446
free(env->rewards);
14461447
free(env->terminals);
1448+
free(env->truncations);
14471449
c_close(env);
14481450
}
14491451

@@ -1994,9 +1996,7 @@ void respawn_agent(Drive *env, int agent_idx) {
19941996
void c_step(Drive *env) {
19951997
memset(env->rewards, 0, env->active_agent_count * sizeof(float));
19961998
memset(env->terminals, 0, env->active_agent_count * sizeof(unsigned char));
1997-
if (env->truncations != NULL) {
1998-
memset(env->truncations, 0, env->active_agent_count * sizeof(unsigned char));
1999-
}
1999+
memset(env->truncations, 0, env->active_agent_count * sizeof(unsigned char));
20002000
env->timestep++;
20012001

20022002
// Move static experts
@@ -2124,10 +2124,8 @@ void c_step(Drive *env) {
21242124
int reached_time_limit = (env->timestep + 1) >= env->episode_length;
21252125
int reached_early_termination = (!originals_remaining && env->termination_mode == 1);
21262126
if (reached_time_limit || reached_early_termination) {
2127-
if (env->truncations != NULL) {
2128-
for (int i = 0; i < env->active_agent_count; i++) {
2129-
env->truncations[i] = 1;
2130-
}
2127+
for (int i = 0; i < env->active_agent_count; i++) {
2128+
env->truncations[i] = 1;
21312129
}
21322130
add_log(env);
21332131
c_reset(env);

0 commit comments

Comments
 (0)