Skip to content

C++ fix rotation serialization#3935

Merged
Wumpf merged 2 commits intomainfrom
andreas/cpp/fix-rotation-serialization
Oct 20, 2023
Merged

C++ fix rotation serialization#3935
Wumpf merged 2 commits intomainfrom
andreas/cpp/fix-rotation-serialization

Conversation

@Wumpf
Copy link
Copy Markdown
Member

@Wumpf Wumpf commented Oct 19, 2023

What

It seems this was caused by undefined behavior via calling an assignment operator on uninitialized memory!

Bulldozered the entire responsible codegen section over to make it super simple :)
(which we can do now in part because recent std::array use - should have done so from the start, makes things way simpler!)

Checklist

  • I have read and agree to Contributor Guide and the Code of Conduct
  • I've included a screenshot or gif (if applicable)
  • I have tested demo.rerun.io (if applicable)
  • The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG

@Wumpf Wumpf added 🪳 bug Something isn't working sdk-cpp C/C++ API specific exclude from changelog PRs with this won't show up in CHANGELOG.md labels Oct 19, 2023
@Wumpf
Copy link
Copy Markdown
Member Author

Wumpf commented Oct 19, 2023

oh and as expected this also fixes issues for me that I saw on just cpp-test but not on CI (reportedly Emil experienced the same)!

Copy link
Copy Markdown
Member

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Super!

new (&self._data.many_optional) TypeAlias(std::move(many_optional));
new (&self._data.many_optional
) std::optional<std::vector<rerun::datatypes::AffixFuzzer3>>(std::move(many_optional
));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this formatting 😬

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it's just a test and it wasn't me, it was clang format :D ;)

@Wumpf Wumpf merged commit c7306fc into main Oct 20, 2023
@Wumpf Wumpf deleted the andreas/cpp/fix-rotation-serialization branch October 20, 2023 09:01
Wumpf added a commit that referenced this pull request Oct 23, 2023
…g on ctor/assignment (#3936)

### What

⚠️ for ease of conflict avoidance use based on #3935

_Clarification: This PR is mostly scratching an itch of mine & addresses
(in my experience) mostly aesthetic problems_

Using std::array makes a bunch of codegen things easier. This in turn
made it easy to revisit how parameters are passed on constructors.


---
Previous rationale on now discarded "more like cpp guidelines" approach:

This follows now the usual "common sense" logic that I believe people
expect from C++ constructors:
* primitive type, no array: pass by value, copy
* primitive type, fixed size array: pass by const&, copy
* anything that is movable: pass by value, move

The latter one is what we had exclusively before. It's less common in
the wild which is why codegen has a bit of rationale in the comments
about it.


You might say: "But @Wumpf! Passing large fixed size arrays or structs
not by value is important as it avoids a copy, this isn't just
aesthetic!". My reply being that from a language lawyer perspective this
might be true, but practically there is no such thing as passing structs
by value as [calling
conventions](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=msvc-170#parameter-passing)
will almost _always_ force (sufficiently large) structs to be passed by
reference (with some exceptions to the rule to be fair). Meaning the
compiler has a _very_ easy time to optimize both caller and callee even
without any inlining what-so-ever ... but I digress... ;)


### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3936) (if
applicable)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/3936)
- [Docs
preview](https://rerun.io/preview/bc4dd6a959cafd47b49230b00586d554c2e57208/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/bc4dd6a959cafd47b49230b00586d554c2e57208/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🪳 bug Something isn't working exclude from changelog PRs with this won't show up in CHANGELOG.md sdk-cpp C/C++ API specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++: Failure to serialize rotations (code-examples/transform3d_simple)

2 participants