Commit f02e34b
authored
Fix Metal renderer crash in packaged apps (Bundle.module fatalErrors) (#593)
MetalTerminalRenderer.candidateBundles() included Bundle.module as its
first candidate for locating SwiftTerm_SwiftTerm.bundle (the shaders).
SwiftPM's generated accessor for executable targets doesn't behave like
a normal Bundle lookup: it fatalErrors (aborting the whole process, not
throwing or returning nil) if the bundle isn't found at either of its
two hardcoded candidates - Bundle.main.bundleURL (the .app's root, not
Contents/Resources where a packaged .app actually places SwiftPM
resource bundles) or the build machine's absolute .build/.../
SwiftTerm_SwiftTerm.bundle path baked into the binary at compile time.
The practical effect: any app that depends on this package via SPM,
ships the resource bundle correctly in its own build pipeline, and
enables the Metal renderer will crash instantly on any machine other
than the one that built it - candidateBundles()'s other two fallbacks
(Bundle(for:), Bundle.main) never get a chance to run, because merely
evaluating the Bundle.module property is what crashes.
Fix: probe for the same bundle by name ourselves via Bundle(url:),
which is a normal failable initializer (verified it returns nil for a
missing path and a working bundle for a present one, no fatalError
either way) - mirroring the generated accessor's own main-bundle-
relative lookup, plus the Contents/Resources location it misses. Falls
through to the existing fallback candidates exactly as before for any
environment where the old code didn't crash.1 parent ac99a54 commit f02e34b
1 file changed
Lines changed: 24 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2770 | 2770 | | |
2771 | 2771 | | |
2772 | 2772 | | |
2773 | | - | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
2774 | 2797 | | |
2775 | 2798 | | |
2776 | 2799 | | |
| |||
0 commit comments