From e77a011188f491f3e701f6741f23ac7462f82ffa Mon Sep 17 00:00:00 2001 From: Janis Kirsteins Date: Fri, 31 Jan 2025 01:03:44 +0100 Subject: [PATCH] Fix a crash in Joypad initialization on iOS Creating a JoypadApple can trigger a notification to add a joypad (if a device is already connected before the game is started). Observed on iOS 18.2.1 with a Nimbus SteelSeries. However at this point the Input singleton is not available yet, so it will crash. This commit moves JoypadApple initialization to `initialize_joypad()` which is called explicitly after the Input singleton is available. This is consistent with other platform joypad initialization. --- platform/ios/os_ios.h | 3 +-- platform/ios/os_ios.mm | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/platform/ios/os_ios.h b/platform/ios/os_ios.h index 94b38f2c40..f2ac1b3662 100644 --- a/platform/ios/os_ios.h +++ b/platform/ios/os_ios.h @@ -65,8 +65,7 @@ private: virtual void initialize_core() override; virtual void initialize() override; - virtual void initialize_joypads() override { - } + virtual void initialize_joypads() override; virtual void set_main_loop(MainLoop *p_main_loop) override; virtual MainLoop *get_main_loop() const override; diff --git a/platform/ios/os_ios.mm b/platform/ios/os_ios.mm index cd05c47b9c..2f75bf9dd5 100644 --- a/platform/ios/os_ios.mm +++ b/platform/ios/os_ios.mm @@ -126,11 +126,13 @@ void OS_IOS::initialize() { initialize_core(); } +void OS_IOS::initialize_joypads() { + joypad_apple = memnew(JoypadApple); +} + void OS_IOS::initialize_modules() { ios = memnew(iOS); Engine::get_singleton()->add_singleton(Engine::Singleton("iOS", ios)); - - joypad_apple = memnew(JoypadApple); } void OS_IOS::deinitialize_modules() {