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

bevy_reflect: Fix dynamic type serialization #10103

Merged
merged 2 commits into from
Oct 16, 2023

Conversation

MrGVSV
Copy link
Member

@MrGVSV MrGVSV commented Oct 12, 2023

Objective

Fixes #10086

Solution

Instead of serializing via DynamicTypePath::reflect_type_path, now uses the TypePath found on the TypeInfo returned by Reflect::get_represented_type_info.

This issue was happening because the dynamic types implement TypePath themselves and do not (and cannot) forward their proxy's TypePath data. The solution was to access the proxy's type information in order to get the correct TypePath data.

Changed

  • The Debug impl for TypePathTable now includes output for all fields.

@MrGVSV MrGVSV added P-Regression Functionality that used to work but no longer does. Add a test for this! A-Reflection Runtime information about types labels Oct 12, 2023
@alice-i-cecile alice-i-cecile added this to the 0.12 milestone Oct 13, 2023
@alice-i-cecile
Copy link
Member

@raffaeleragni, if you feel equipped, your review / approval would be appreciated here :)

@MrGVSV
Copy link
Member Author

MrGVSV commented Oct 13, 2023

This also has a change to TypePathTable's Debug impl (which was useful for debugging this issue). Maybe also just a thumbs up from @soqb on that?

@raffaeleragni
Copy link
Contributor

raffaeleragni commented Oct 13, 2023

Pointing to the fork & branch.
Still having issues, it seems I have to register DynamicStruct in my test registry: registry.register::<DynamicStruct>();, but DynamicStruct not implementing GetTypeRegistration

(my branch is https://github.com/raffaeleragni/bevy_sync/tree/bevy_0_12)

@raffaeleragni
Copy link
Contributor

I see in the new test DynamicStruct is asserted directly, but how do you bring back the TestStruct from deserialization instead? Without knowing its type at compile time, that is.

@raffaeleragni
Copy link
Contributor

My test runs fine too now, thanks.

@raffaeleragni
Copy link
Contributor

As an extra, but this could be unrelated to this PR and require a new one, not sure:

https://github.com/raffaeleragni/bevy_sync/blob/bevy_0_12/src/proto_serde.rs#L148
I am serializing a material too here now, and this happens:

---- proto_serde::test::material_serde stdout ----
thread 'proto_serde::test::material_serde' panicked at src/proto_serde.rs:29:57:
called `Result::unwrap()` on an `Err` value: Custom("no variant found at index `4128768` on enum `bevy_pbr::alpha::AlphaMode`")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@MrGVSV
Copy link
Member Author

MrGVSV commented Oct 13, 2023

As an extra, but this could be unrelated to this PR and require a new one, not sure:

https://github.com/raffaeleragni/bevy_sync/blob/bevy_0_12/src/proto_serde.rs#L148

I am serializing a material too here now, and this happens:


---- proto_serde::test::material_serde stdout ----

thread 'proto_serde::test::material_serde' panicked at src/proto_serde.rs:29:57:

called `Result::unwrap()` on an `Err` value: Custom("no variant found at index `4128768` on enum `bevy_pbr::alpha::AlphaMode`")

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace



This seems possibly unrelated. Could you open a new issue?

@raffaeleragni
Copy link
Contributor

Sure

@raffaeleragni
Copy link
Contributor

#10110

Copy link
Contributor

@soqb soqb left a comment

Choose a reason for hiding this comment

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

LGTM! i like this direction.

crates/bevy_reflect/src/serde/ser.rs Outdated Show resolved Hide resolved
@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 Oct 15, 2023
@alice-i-cecile
Copy link
Member

@MrGVSV those CI failures look real; failing bevy_reflect test.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 16, 2023
Merged via the queue into bevyengine:main with commit 01b910a Oct 16, 2023
21 checks passed
@MrGVSV MrGVSV deleted the reflect-serialize-dynamics branch October 17, 2023 00:03
ameknite pushed a commit to ameknite/bevy that referenced this pull request Nov 6, 2023
# Objective

Fixes bevyengine#10086

## Solution

Instead of serializing via `DynamicTypePath::reflect_type_path`, now
uses the `TypePath` found on the `TypeInfo` returned by
`Reflect::get_represented_type_info`.

This issue was happening because the dynamic types implement `TypePath`
themselves and do not (and cannot) forward their proxy's `TypePath`
data. The solution was to access the proxy's type information in order
to get the correct `TypePath` data.

## Changed

- The `Debug` impl for `TypePathTable` now includes output for all
fields.
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
# Objective

Fixes bevyengine#10086

## Solution

Instead of serializing via `DynamicTypePath::reflect_type_path`, now
uses the `TypePath` found on the `TypeInfo` returned by
`Reflect::get_represented_type_info`.

This issue was happening because the dynamic types implement `TypePath`
themselves and do not (and cannot) forward their proxy's `TypePath`
data. The solution was to access the proxy's type information in order
to get the correct `TypePath` data.

## Changed

- The `Debug` impl for `TypePathTable` now includes output for all
fields.
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 P-Regression Functionality that used to work but no longer does. Add a test for this! 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.

Potential reflect issue: DynamicStruct not registered
5 participants