Skip to content

fix(switch): prevent stub leaking into supported builds - #2849

Merged
bitsandfoxes merged 9 commits into
fix/ios-plugin-platform-scopefrom
fix/switch-native-stub-linkage
Sep 14, 2026
Merged

bitsandfoxes merged 9 commits into
fix/ios-plugin-platform-scopefrom
fix/switch-native-stub-linkage

Conversation

@bitsandfoxes

@bitsandfoxes bitsandfoxes commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

The Issue

Switch and Switch 2 players were linking Sentry's no-op stubs even when the actual sentry-switch libraries were installed. This caused the native SDK to "fail" to initialize.

The idea was to have the SDK toggle the targeted platforms on the stubs on or off, depending on whether sentry-switch was present. But a package installed from a registry or a Git URL lives in Library/PackageCache. Unity treats it as basically immutable.

What changed

The stub is no longer an asset in the package. It sits in Plugins/Switch/SentryStub~ and gets ignored by the AssetDatabase. When the actual sentry-switch libraries are missing SwitchNativeStub copies the stub into Assets/Plugins/Sentry/<target>. It also deletes them when imported. That location is part of the actual project. It's similar to how we treat the proguard file. Similar shape as the iOS bridge, which already copies SentryNativeBridgeNoOp.m into the generated Xcode project.

github-actions Bot and others added 3 commits September 11, 2026 16:09
sentry-switch is under NDA, so the no-op stubs exist to keep a Switch
player linking for anyone who does not have it. They shipped as a plugin
in the package, enabled by default, and SwitchNativePluginBuildPreProcess
turned them off once the real libraries appeared.

That cannot work. A package installed from a registry or a Git URL lives
in Library/PackageCache, which Unity treats as immutable, so
PluginImporter.SaveAndReimport never reaches disk. The stub stayed
enabled and the linker took it in preference to the archive, because an
archive is only searched for symbols that are still undefined. Players
shipped with no native crash reporting while the build log said the real
libraries had been found.

The stub is no longer an asset in the package. It sits in
Plugins/Switch/SentryStub~, which the AssetDatabase does not import, and
SwitchNativeStub copies it into Assets/Plugins/Sentry/<target> while that
target's libraries are missing, deleting it once they arrive. That
location belongs to the user, so the write lands whatever the package was
installed from.

Only the active build target gains a copy, so a project that does not
build for Switch sees no change in its tree. Removal is not gated that
way, because a stale stub shadows the libraries it sits next to. It runs
on domain reload and on plugin folder changes, never during a build, so
the database has settled long before one starts.
SwitchNativePluginBuildPreProcess now only validates, repairing and
failing the build rather than mutating assets Unity is already collecting.

The copy carries a version stamp in its header, compared against the
package's, so an SDK upgrade that adds a binding refreshes every copy.
Comparing the stamp rather than the whole file keeps source control's
line ending normalization from rewriting it on every domain reload.

Also fixes three stubs that returned void where sentry-native returns
int: sentry_close, sentry_value_decref and sentry_reinstall_backend.
Nothing reads those values, but a caller that did would have read
whatever was in the return register.

The pinned plugin scope table in test-plugin-platforms.ps1 loses its row
for the stub, which is no longer an imported asset.
@bitsandfoxes
bitsandfoxes force-pushed the fix/switch-native-stub-linkage branch from bf6ec38 to 195a9c2 Compare September 11, 2026 17:00
@bitsandfoxes
bitsandfoxes changed the base branch from main to fix/ios-plugin-platform-scope September 11, 2026 17:00
Comment thread src/Sentry.Unity.Editor/Native/SwitchNativePluginBuildPreProcess.cs Outdated
Comment thread src/Sentry.Unity.Editor/Native/SwitchNativeStub.cs Outdated
Comment thread src/Sentry.Unity.Editor/Native/SwitchNativeStub.cs

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 195a9c2. Configure here.

Comment thread src/Sentry.Unity.Editor/Native/SwitchNativeStub.cs
Comment thread src/Sentry.Unity.Editor/Native/SwitchNativeStub.cs
Comment thread src/Sentry.Unity.Editor/Native/SwitchNativeStub.cs
@bitsandfoxes bitsandfoxes changed the title fix(switch): stop shipping the no-op stubs as a plugin inside the package fix(switch): prevent stub leaking into supported builds Sep 11, 2026
Comment thread src/Sentry.Unity.Editor/Native/SwitchNativePluginBuildPreProcess.cs
@bitsandfoxes
bitsandfoxes merged commit 5ea1a39 into fix/ios-plugin-platform-scope Sep 14, 2026
60 of 61 checks passed
@bitsandfoxes
bitsandfoxes deleted the fix/switch-native-stub-linkage branch September 14, 2026 08:02
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.

2 participants