Fix #199: Register generated formatters without relying on [MRubyObject] attribute instances - #200
Closed
hadashiA wants to merge 1 commit into
Closed
Fix #199: Register generated formatters without relying on [MRubyObject] attribute instances#200hadashiA wants to merge 1 commit into
hadashiA wants to merge 1 commit into
Conversation
Unity 6000.5's linker unconditionally strips attribute instances of PreserveAttribute-derived attributes from player builds, so type.GetCustomAttribute<MRubyObjectAttribute>() returns null for generated types on IL2CPP builds and no formatter was ever registered. The __RegisterMRubyValueFormatter method lookup alone is a sufficient and stripping-proof signal, since only generated types have that method. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #199.
Unity 6000.5's UnityLinker unconditionally removes custom attribute instances of
PreserveAttributeand anything inheriting from it (matched by name, walking base types). SinceMRubyObjectAttribute : PreserveAttribute, the[MRubyObject]instances disappear from stripped assemblies, and the runtime gate inGeneratedResolver.TryInvokeRegisterFormatter(GetCustomAttribute<MRubyObjectAttribute>() == null) made every registration fail on Unity 6000.5 IL2CPP builds — everyDeserialize<T>then threwMRubySerializationException.This takes suggested fix (1) from the issue: drop the attribute gate and rely on the
__RegisterMRubyValueFormattermethod lookup alone. Only generated types have that method, and it survives stripping thanks to its own[Preserve], so it is a sufficient and stripping-proof signal.The
PreserveAttributeinheritance onMRubyObjectAttributeis kept as-is: per the issue's analysis, 6000.5 still honors the preserve semantics (annotated types/members are kept); only the runtime-visible attribute instance is removed, and nothing else reads it at runtime anymore.Test
Added
RegisterFormatterWithoutAttributeInstance, using a hand-written type that mimics a generated type after attribute stripping (has__RegisterMRubyValueFormatter, lacks[MRubyObject]). Verified it fails against the previous resolver and passes with this change; all 22 serializer tests pass.🤖 Generated with Claude Code