-
Notifications
You must be signed in to change notification settings - Fork 13
Collision checking fixes #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Greptile SummaryReplaced fixed-size static array allocation with dynamic allocation in collision checking to support variable entity counts per grid cell. Key Changes:
Critical Issues Found:
Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant CAM as compute_agent_metrics
participant CN as checkNeighbors
participant GI as getGridIndex
participant GM as GridMap
participant MEM as Memory
CAM->>CN: checkNeighbors(env, x, y, offsets, 25, &list_size)
CN->>GI: getGridIndex(env, x, y)
alt Invalid position
GI-->>CN: -1
CN-->>CAM: NULL (no NULL check!)
CAM->>CAM: Segfault accessing entity_list[i]
else Valid position
GI-->>CN: valid index
CN->>CN: Calculate entity_list_count (loop through neighbors)
CN->>MEM: calloc(entity_list_count, sizeof(GridMapEntity))
alt Allocation fails
MEM-->>CN: NULL (no check!)
CN->>GM: memcpy to NULL pointer
CN->>CAM: Segfault
else Allocation succeeds
MEM-->>CN: entity_list pointer
CN->>GM: memcpy entities from cells[neighborIndex]
CN-->>CAM: entity_list pointer
CAM->>CAM: Process entities in loop
CAM->>CAM: Check collisions with entities
CAM->>MEM: free(entity_list)
end
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 3 comments
pufferlib/ocean/drive/drive.h
Outdated
| int min_neighbor_index = INT16_MAX; | ||
| for (int i = 0; i < offset_size; i++) { | ||
| int nx = gridX + local_offsets[i][0]; | ||
| int ny = gridY + local_offsets[i][1]; | ||
| if (nx < 0 || nx >= env->grid_map->grid_cols || ny < 0 || ny >= env->grid_map->grid_rows) | ||
| continue; | ||
| int neighborIndex = ny * env->grid_map->grid_cols + nx; | ||
| min_neighbor_index = fmin(min_neighbor_index, neighborIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: min_neighbor_index is calculated but never used. Remove unused variable.
| int min_neighbor_index = INT16_MAX; | |
| for (int i = 0; i < offset_size; i++) { | |
| int nx = gridX + local_offsets[i][0]; | |
| int ny = gridY + local_offsets[i][1]; | |
| if (nx < 0 || nx >= env->grid_map->grid_cols || ny < 0 || ny >= env->grid_map->grid_rows) | |
| continue; | |
| int neighborIndex = ny * env->grid_map->grid_cols + nx; | |
| min_neighbor_index = fmin(min_neighbor_index, neighborIndex); | |
| // Calculate entities count in neighboring cells | |
| for (int i = 0; i < offset_size; i++) { |
Prompt To Fix With AI
This is a comment left during a code review.
Path: pufferlib/ocean/drive/drive.h
Line: 1009:1016
Comment:
**style:** `min_neighbor_index` is calculated but never used. Remove unused variable.
```suggestion
// Calculate entities count in neighboring cells
for (int i = 0; i < offset_size; i++) {
```
How can I resolve this? If you propose a fix, please make it concise.
nadarenator
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much does this impact SPS?


Change collision checking to dynamic allocation to use all entities in vision range
Remove corresponding constants(unnecessary, can be replaced with env->grid_map->grid_cell_count[idx] in all branches