Skip to content

Conversation

@mpragnay
Copy link

@mpragnay mpragnay commented Dec 21, 2025

Changed visualize.c defaults to ini configs so it's easier to debug

@mpragnay mpragnay marked this pull request as ready for review December 21, 2025 04:07
@greptile-apps
Copy link

greptile-apps bot commented Dec 21, 2025

Greptile Summary

Refactored visualizer configuration handling by moving INI file parsing from eval_gif() to main(), allowing default values from the config file to be used throughout the visualizer. Extended the INI parser to support visualizer-specific options (show_grid, show_lasers, obs_only, num_maps) and added CLI arguments for collision/offroad behavior and dynamics model.

Key Changes:

  • Moved INI parsing from eval_gif() to main() for centralized configuration
  • Expanded eval_gif() signature from 14 to 22 parameters to accept all configuration values explicitly
  • Simplified scenario_length logic by removing fallback chain
  • Added visualizer config fields to env_init_config struct
  • Added CLI argument parsing for --collision-behavior, --offroad-behavior, and --dynamics-model

Issues Found:

  • Pre-existing bug: INI parser uses atoi() on control_mode and init_mode, which are string enums in the INI file (e.g., "control_vehicles"). This will always evaluate to 0. Python correctly handles the string-to-int conversion, but the C visualizer may not work correctly with non-default modes.

Confidence Score: 4/5

  • This PR is safe to merge with one pre-existing bug noted
  • The refactoring is well-structured and follows good separation of concerns by centralizing config parsing in main(). The changes are primarily organizational with expanded parameter passing. However, a pre-existing bug exists where control_mode and init_mode string values from the INI file are incorrectly parsed using atoi() which always returns 0 for string enum values. This bug predates this PR but affects the visualizer's ability to use non-default control/init modes.
  • The env_config.h file has a pre-existing bug with control_mode/init_mode parsing that should be fixed in a future PR

Important Files Changed

Filename Overview
pufferlib/ocean/env_config.h Added four new configuration fields (num_maps, show_lasers, show_grid, obs_only) to support visualizer configuration from INI file. Parser logic follows existing patterns.
pufferlib/ocean/drive/visualize.c Refactored to move INI parsing from eval_gif() to main(), expanded eval_gif() signature with 8 additional parameters. Added CLI argument parsing for --collision-behavior, --offroad-behavior, and --dynamics-model.

Sequence Diagram

sequenceDiagram
    participant main
    participant ini_parser
    participant eval_gif
    participant Drive_env
    
    Note over main: Program starts
    main->>ini_parser: ini_parse("drive.ini", handler, &conf)
    ini_parser-->>main: Parse all config fields
    Note over main: Initialize defaults from conf:<br/>show_grid, obs_only, lasers,<br/>goal_radius, init_steps, etc.
    
    main->>main: Parse CLI arguments<br/>(override config values)
    
    main->>eval_gif: eval_gif(22 parameters including<br/>dynamics_model, collision_behavior,<br/>reward values, map_dir, etc.)
    
    Note over eval_gif: No longer parses INI file
    
    eval_gif->>Drive_env: Initialize Drive struct<br/>with all configuration values
    
    eval_gif->>eval_gif: allocate(&env)
    eval_gif->>eval_gif: c_reset(&env)
    eval_gif->>eval_gif: Render frames and<br/>generate video output
    
    eval_gif-->>main: Return status
    main-->>main: Exit
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (1)

  1. pufferlib/ocean/env_config.h, line 90-95 (link)

    logic: Pre-existing bug: atoi() returns 0 for string values like "control_vehicles" and "create_all_valid" in the INI file. The Python code correctly converts strings to integers (drive.py:90-109), but the C INI parser doesn't handle these string enum values.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

.reward_ade = conf.reward_ade,
.goal_radius = conf.goal_radius,
.dt = conf.dt,
.dynamics_model = dynamics_model,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mpragnay what is the advantage of doing this? We can just directly take them from the drive.ini (see main)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants