Check controlled state safely#115
Merged
Merged
Conversation
| }, | ||
| .maxNumControlledVehicles = 0, | ||
| }, | ||
| .enableBatchRenderer = true, |
Contributor
There was a problem hiding this comment.
Thank you for catching it
SamanKazemkhani
left a comment
Collaborator
There was a problem hiding this comment.
The only blocking comment is about the else if.
|
|
||
| // Technically there would never be a collision between (non valid expert) and (non expert). So one of the below checks would always be false. | ||
| if(ctx.get<ControlledState>(candidateCollision.a).controlledState == ControlMode::EXPERT) | ||
| if(controlledStateA.valid()) |
Collaborator
There was a problem hiding this comment.
The bodies of these if statements are identical save for the Loc. It would be nice if you factored out the logic into a lambda:
auto isExpertAgentInInvalidState = [&](Loc loc) {
auto maybeControlledState = ctx.getCheck<ControlledState>(loc);
if (not maybeControlledState.valid()) {
return false;
}
if (maybeControlledState.value().controlledState != ControlMode::EXPERT) {
return false;
}
auto currStep = getCurrentStep(ctx.get<StepsRemaining>(loc));
return not ctx.get<Trajectory>(loc).valids[currStep];
};
then the if-statements would be
Suggested change
| if(controlledStateA.valid()) | |
| if(isExpertAgentInInvalidState(candidateCollision.a)) { | |
| return; | |
| } |
|
|
||
| } | ||
| else if(ctx.get<ControlledState>(candidateCollision.b).controlledState == ControlMode::EXPERT) | ||
| else if(controlledStateB.valid()) |
Collaborator
There was a problem hiding this comment.
I don't think this should be an else if. For instance, if candidateCollision.a is a non-expert agent and candidateCollision.b is an expert-agent in an invalid state, this function will not be short-ciruited.
SamanKazemkhani
approved these changes
May 14, 2024
wangbingke0
pushed a commit
to wangbingke0/gpudrive
that referenced
this pull request
Feb 13, 2026
* Check controlled state safely * Revert headless * Use lambda function and inclusive or * Type def the lambda * Invert the booleans
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the previous, we were checking the control state on entities to determine if they were non valid experts. However, that is error prone as not all entities have control states (physics entities like roads). This PR fixes that by using the safer
getCheck<>.