Commit 9743d1e
committed
OSX/MACOS: Fix crash when toggling Suspend Screensaver
-[RetroArch_OSX setDisableDisplaySleep:] stored the NSActivity
token returned by -beginActivityWithOptions:reason: in a raw-id
ivar with no retain. The token is autoreleased and owned by the
system, so under MRR (used by RetroArch_PPC.xcodeproj and the
qb/make build - ARC is not universal in this file) it was
deallocated as soon as the surrounding autorelease pool drained,
leaving _sleepActivity as a dangling pointer. Toggling the
setting back off then sent -endActivity: to freed memory, which
crashed in objc_opt_isKindOfClass at offset 0x1c while checking
-isKindOfClass:_NSActivityAssertion.
Fixes (macOS 12.3, x86_64, 1.22.2):
0 libobjc objc_opt_isKindOfClass + 27
1 Foundation -[NSProcessInfo endActivity:] + 29
2 RetroArch -[RetroArch_OSX setDisableDisplaySleep:] + 125
3 RetroArch general_write_handler + 1646
4 RetroArch setting_bool_action_ok_default + 34
...
- Retain the token (RARCH_RETAIN, no-op under ARC, -retain under
MRR) so it survives across the begin/end pair.
- Capture + nil-out the ivar before calling -endActivity: to make
a re-entrant call from inside AppKit's menu write path unable
to observe a stale pointer and double-end.
- Release any outstanding activity in -dealloc (MRR branch) so
quitting while the screensaver is suspended does not leak the
system-wide display-sleep assertion.
- Guard the whole method with MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
so 10.5-era SDKs (Xcode 3.1 / GCC 4.0, which predate both App
Nap and ARC) still compile, and with -respondsToSelector: so a
binary built on a newer SDK but deployed to 10.5-10.8 no-ops
instead of crashing on unrecognized selector.
Also adds RARCH_RETAIN to cocoa_defines.h next to the existing
RARCH_RELEASE / RARCH_AUTORELEASE / RARCH_SUPER_DEALLOC family.1 parent b0f6690 commit 9743d1e
2 files changed
Lines changed: 54 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
| 101 | + | |
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
615 | 615 | | |
616 | 616 | | |
617 | 617 | | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
618 | 634 | | |
619 | 635 | | |
620 | 636 | | |
| |||
808 | 824 | | |
809 | 825 | | |
810 | 826 | | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
811 | 838 | | |
812 | 839 | | |
813 | 840 | | |
814 | | - | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
815 | 855 | | |
816 | 856 | | |
817 | 857 | | |
818 | 858 | | |
819 | 859 | | |
820 | | - | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
821 | 865 | | |
| 866 | + | |
| 867 | + | |
822 | 868 | | |
823 | 869 | | |
824 | 870 | | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
825 | 875 | | |
826 | 876 | | |
827 | 877 | | |
| |||
0 commit comments