Skip to content
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

reflect: avoid deadlock in GenericTypeCell #8957

Merged
merged 1 commit into from
Jun 27, 2023

Conversation

soqb
Copy link
Contributor

@soqb soqb commented Jun 26, 2023

Objective

  • There was a deadlock discovered in the implementation of bevy_reflect::utility::GenericTypeCell, when called on a recursive type, e.g. Vec<Vec<VariableCurve>>

Solution

  • Drop the lock before calling the initialisation function, and then pick it up again afterwards.

Additional Context

@soqb soqb changed the title reflect: avoid deadlock in GenericTypedCell reflect: avoid deadlock in GenericTypeCell Jun 26, 2023
@soqb soqb marked this pull request as ready for review June 26, 2023 09:09
@soqb soqb mentioned this pull request Jun 26, 2023
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Reflection Runtime information about types labels Jun 26, 2023
@alice-i-cecile alice-i-cecile requested a review from MrGVSV June 27, 2023 16:58
Copy link
Member

@MrGVSV MrGVSV left a comment

Choose a reason for hiding this comment

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

LGTM!


One issue this brings up (and that this PR does not need to be the one to fix) is that we apparently don't support self-referential types. The following won't compile:

#[derive(Reflect, FromReflect)]
struct Foo {
  foo: Vec<Foo>
}
Errors
error[E0275]: overflow evaluating the requirement `tests::recursive_typed_storage_does_not_hang::Foo: type_path::TypePath`
    --> crates/bevy_reflect/src/lib.rs:1856:18
     |
1856 |         #[derive(Reflect, FromReflect)]
     |                  ^^^^^^^
     |
note: required for `Vec<tests::recursive_typed_storage_does_not_hang::Foo>` to implement `reflect::Reflect`
    --> crates/bevy_reflect/src/impls/std.rs:326:41
     |
326  |           impl<T: FromReflect + TypePath> Reflect for $ty {
     |                                 --------  ^^^^^^^     ^^^
     |                                 |
     |                                 unsatisfied trait bound introduced here
...
error[E0275]: overflow evaluating the requirement `tests::recursive_typed_storage_does_not_hang::Foo: from_reflect::FromReflect`
    --> crates/bevy_reflect/src/lib.rs:1856:27
     |
1856 |         #[derive(Reflect, FromReflect)]
     |                           ^^^^^^^^^^^
     |
note: required for `Vec<tests::recursive_typed_storage_does_not_hang::Foo>` to implement `from_reflect::FromReflect`
    --> crates/bevy_reflect/src/impls/std.rs:410:41
     |
410  |           impl<T: FromReflect + TypePath> FromReflect for $ty {
     |                   -----------             ^^^^^^^^^^^     ^^^
     |                   |
     |                   unsatisfied trait bound introduced here
...

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jun 27, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 27, 2023
Merged via the queue into bevyengine:main with commit e17fc53 Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Bug An unexpected or incorrect behavior S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants