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
Unify way to check readable blender files. #5153
Conversation
95b6d88
to
fe9d48d
Compare
@@ -1338,4 +1295,55 @@ aiNode *BlenderImporter::ConvertNode(const Scene &in, const Object *obj, Convers | |||
return node.release(); | |||
} | |||
|
|||
std::string BlenderImporter::ParseMagicToken(std::shared_ptr<IOStream>& stream) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not pass shared_ptr
via reference. Either pass by value or pass the raw pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we usually shouldn't pass smart pointers by reference.
However, in this specific case the stream is an input/output parameter, as it can internally be reset, if the file is compressed, and will be reused outside of this function. So passing by value wouldn't work. Passing by raw pointer would require us to clean up the old memory, so the whole point of using smart pointers is lost.
Of course if you wished we could rewrite more of the code here, but I didn't want to touch too much of the original logic (besides converting exceptions to strings).
0df49d0
to
808869e
Compare
@turol Would you mind to restart the workflows and take another look? Thanks a lot! |
I still don't like the use of reference parameters. I think the correct solution would be to return a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine!
7d55648
to
8620e87
Compare
@turol I removed all reference arguments and created a helper struct to contain the stream, optional uncompressed data, and error. This is under the assumption that we still want to compile with < c++17 and have no variant support. |
If you're going to rebase it you might as well squash the whole thing into one commit. |
8114572
to
82d3f47
Compare
Done. |
Merged, thanks a lot for your contribution. |
Previously the
InternReadFile
logic was much more restrictive than theCanRead
logic, but able to also parse compressed files. With this change the behavior is unified.