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

amethyst_animation::util::get_animation_set panics if Entity is dead. #686

Closed
Xaeroxe opened this Issue Apr 30, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy May 17, 2018

Member

I'm adding this issue for first-time contributors. Here's a more detailed description of the issue:

The following function is using an unwrap on the Result of entry. In case the Entity is dead, the result is an error and the unwrap will make the function panic.

pub fn get_animation_set<'a, I, T>(
controls: &'a mut WriteStorage<AnimationControlSet<I, T>>,
entity: Entity,
) -> &'a mut AnimationControlSet<I, T>
where
I: Send + Sync + 'static,
T: AnimationSampling,
{
controls
.entry(entity)
.unwrap()
.or_insert_with(AnimationControlSet::default)
}

Your task is to evaluate whether the function should return an Option or a Result and replace the unwrap accordingly. If you're interested in fixing this issue or you need help with something, please comment here.

There's a rough overview of the animation crate available in our book.

Member

torkleyy commented May 17, 2018

I'm adding this issue for first-time contributors. Here's a more detailed description of the issue:

The following function is using an unwrap on the Result of entry. In case the Entity is dead, the result is an error and the unwrap will make the function panic.

pub fn get_animation_set<'a, I, T>(
controls: &'a mut WriteStorage<AnimationControlSet<I, T>>,
entity: Entity,
) -> &'a mut AnimationControlSet<I, T>
where
I: Send + Sync + 'static,
T: AnimationSampling,
{
controls
.entry(entity)
.unwrap()
.or_insert_with(AnimationControlSet::default)
}

Your task is to evaluate whether the function should return an Option or a Result and replace the unwrap accordingly. If you're interested in fixing this issue or you need help with something, please comment here.

There's a rough overview of the animation crate available in our book.

@hashedone

This comment has been minimized.

Show comment
Hide comment
@hashedone

hashedone Jun 22, 2018

Contributor

I don't think, that returning Result makes sense here, as long, as only information available in Err is actual_gen. Am I right?

Contributor

hashedone commented Jun 22, 2018

I don't think, that returning Result makes sense here, as long, as only information available in Err is actual_gen. Am I right?

@Xaeroxe

This comment has been minimized.

Show comment
Hide comment
@Xaeroxe

Xaeroxe Jun 22, 2018

Member

It's the only information we have and I don't see much harm in returning a Result

Member

Xaeroxe commented Jun 22, 2018

It's the only information we have and I don't see much harm in returning a Result

@hashedone

This comment has been minimized.

Show comment
Hide comment
@hashedone

hashedone Jun 23, 2018

Contributor

I made a correction and submitted pull request for this.

Contributor

hashedone commented Jun 23, 2018

I made a correction and submitted pull request for this.

bors bot added a commit that referenced this issue Jun 25, 2018

Merge #801
801:  amethyst_animation::util::get_animation_set returns Option instead of panicking when entity is invalid r=Xaeroxe a=hashedone

Patch for #686.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/amethyst/amethyst/801)
<!-- Reviewable:end -->


Co-authored-by: Bartłomiej Kuras <hash.deb@gmail.com>

@Xaeroxe Xaeroxe closed this Jul 5, 2018

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