Fix: Handle UnicodeDecodeError and suppress exceptions for Motive 3 compatibility #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NatNet 0.2.0 Compatibility Patch for Motive 3.X (NatNet 4.2)
Problem Description
The
natnetpython library (v0.2.0) crashes when connecting to newer Motive servers (e.g., Motive 3.3.0 which uses NatNet Protocol 4.2).The crashes occur in two places:
MODELDEFpackets usingPacketBuffer.read_string. The newer protocol seems to send bytes that are not strictly valid utf-8 in the expected context or the parsing offset is misaligned.DataDescriptions. Because the library does not support Protocol 4.X, it fails to account for new fields or size changes in the packet structure, leading to invalid pointer offsets.Proposed Fix
PacketBuffer.read_stringto useerrors="replace"when decoding utf-8. This prevents the immediate crash on invalid strings.NatNetClient.__process_messageto catch and log exceptions instead of letting them propagate and kill the client thread.MODELDEFpacket parsing is fundamentally incompatible, we simply want to ignore it (or partial failures) so that the client can continue to processFRAMEOFDATApackets, which are backward compatible enough to extract rigid body poses.