You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After not working with SLikeNet (or RakNet in my case) for a while, I came back to it and made a simple mistake that the library and API happily let me do.
I passed a std::string to BitStream::Write, and then received it via BitStream::Read(std::string&). Because I was testing client+server in the same process, it didn't crash immediately. What happened was the BitStream happily serialized the entire string, not just its contents, and then reassembled on the other side, such that the server and client strings were both pointing to the same string memory, and so when the client's string was destroyed going out of scope, it took the server's string out with it.
I don't think it's sensible for the catch-all templated functions to allow this. Instead, they should static_assert on std::is_trivially_copyable, such that a template specialization is required if the user is trying to serialize a not as-of-yet supported type.
This would help solidify the API and avoid a very simple beginner-trap of an issue.
The text was updated successfully, but these errors were encountered:
After not working with SLikeNet (or RakNet in my case) for a while, I came back to it and made a simple mistake that the library and API happily let me do.
I passed a std::string to BitStream::Write, and then received it via BitStream::Read(std::string&). Because I was testing client+server in the same process, it didn't crash immediately. What happened was the BitStream happily serialized the entire string, not just its contents, and then reassembled on the other side, such that the server and client strings were both pointing to the same string memory, and so when the client's string was destroyed going out of scope, it took the server's string out with it.
I don't think it's sensible for the catch-all templated functions to allow this. Instead, they should static_assert on std::is_trivially_copyable, such that a template specialization is required if the user is trying to serialize a not as-of-yet supported type.
This would help solidify the API and avoid a very simple beginner-trap of an issue.
The text was updated successfully, but these errors were encountered: