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

Make SimdAabb deserializable in map-like formats like JSON, YAML #125

Merged
merged 2 commits into from
Apr 15, 2023
Merged

Make SimdAabb deserializable in map-like formats like JSON, YAML #125

merged 2 commits into from
Apr 15, 2023

Conversation

shoebe
Copy link
Contributor

@shoebe shoebe commented Feb 5, 2023

This code:

use nalgebra::Isometry2;
use parry2d::shape::{SharedShape};

fn main() {
    let c = SharedShape::compound(
        vec![
            (Isometry2::default(), SharedShape::cuboid(5.0,5.0))
        ]
    );
    let s = serde_yaml::to_string(&c).unwrap();
    let c = serde_yaml::from_str::<SharedShape>(&s).unwrap();
    let s2 = serde_yaml::to_string(&c).unwrap();
    assert_eq!(s, s2);
}

Throws

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("qbvh.nodes[0].simd_aabb: invalid type: map, expected two arrays containing at least 16 floats", line: 23, column: 7)', crates/parry2d/examples/serde.rs:11:53
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/panicking.rs:64:14
   2: core::result::unwrap_failed
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/result.rs:1791:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/result.rs:1113:23
   4: serde::main
             at ./crates/parry2d/examples/serde.rs:11:13
   5: core::ops::function::FnOnce::call_once
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

And this code

use nalgebra::Isometry2;
use parry2d::shape::{SharedShape};

fn main() {
    let c = SharedShape::compound(
        vec![
            (Isometry2::default(), SharedShape::cuboid(5.0,5.0))
        ]
    );
    let s = ron::ser::to_string_pretty(
        &c, 
        ron::ser::PrettyConfig::default()
            .struct_names(true)
    ).unwrap();
    let c = ron::from_str::<SharedShape>(&s).unwrap();
    let s2 = ron::ser::to_string_pretty(
        &c, 
        ron::ser::PrettyConfig::default()
            .struct_names(true)
    ).unwrap();
    assert_eq!(s, s2);
}
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SpannedError { code: ExpectedDifferentStructName { expected: "SimdAabb", found: "simd_aabb" }, position: Position { line: 29, col: 37 } }', crates/parry2d/examples/serde.rs:15:46
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/panicking.rs:64:14
   2: core::result::unwrap_failed
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/result.rs:1791:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/result.rs:1113:23
   4: serde::main
             at ./crates/parry2d/examples/serde.rs:15:13
   5: core::ops::function::FnOnce::call_once
             at /rustc/fc594f15669680fa70d255faec3ca3fb507c3405/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I made the struct names match and added visit_map as described here:
https://serde.rs/deserialize-struct.html

@sebcrozet sebcrozet merged commit 4e1f820 into dimforge:master Apr 15, 2023
@sebcrozet
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants