Skip to content

SDL: SetVertexAttributes works with NativeAOT, and the library checks itself for it - #38

Merged
lithiumtoast merged 1 commit into
mainfrom
sdl-trim-safe-vertex-attributes
Dec 1, 2026
Merged

lithiumtoast merged 1 commit into
mainfrom
sdl-trim-safe-vertex-attributes

Conversation

@lithiumtoast

@lithiumtoast lithiumtoast commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

A game's NativeAOT publishes failed with IL2104: Assembly 'SDL' produced trim warnings. The warning behind it:

IL2090: GpuGraphicsPipelineOptions.SetVertexAttributes(): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'System.Type.GetFields()'.

SetVertexAttributes reads the vertex type's fields with reflection, but didn't tell the trimmer to keep them. It hadn't come up before, because no published game called it yet. Besides failing the publish, the fields could have been trimmed away, so a published game would fail at startup with "Vertex type has no fields".

Changes

  • The fix: TVertex is [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)].
  • Analyzers: SDL.csproj sets IsAotCompatible, so the trim and NativeAOT analyzers run when the library builds. The SDK's own projects don't get the analyzers games get, which is how this slipped through. With them on, this was the only finding in the library.
  • Regression test: the game consumer calls SetVertexAttributes on a two-field vertex type and checks that it finds 2. test.sh checks that the NativeAOT-published game prints Vertex attributes: 2, on every OS.

Checked locally on macOS: with IsAotCompatible and without the annotation, the library build fails with IL2090. With it, the solution builds, and TEST_SCOPE=platform ./src/cs/tests/Consumers/test.sh passes, including the published game's vertex check.

After this merges, a release lets games that call it publish again.

…g, and the library checks itself for NativeAOT

SetVertexAttributes<TVertex> reads TVertex's fields with reflection, without telling the trimmer to keep them: a NativeAOT publish of a game that calls it failed with IL2104 (Ageborn's did), and could have trimmed the fields away. TVertex is now [DynamicallyAccessedMembers(PublicFields)].

SDL.csproj sets IsAotCompatible, so the trim and NativeAOT analyzers run when the library builds; this was their only finding. The game consumer calls SetVertexAttributes, and test.sh checks that its NativeAOT publish still finds both fields.
@lithiumtoast
lithiumtoast merged commit 505f2d2 into main Dec 1, 2026
28 checks passed
@lithiumtoast
lithiumtoast deleted the sdl-trim-safe-vertex-attributes branch December 1, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant