iOS: port ARC support

This commit is contained in:
Sergey Minakov 2020-10-05 23:26:43 +03:00
parent 2bdfec2418
commit 5d1284204d
16 changed files with 66 additions and 68 deletions

View File

@ -44,6 +44,12 @@
// forward declaration for some needed objects // forward declaration for some needed objects
class ARKitShader; class ARKitShader;
#ifdef __OBJC__
typedef NSObject GodotARAnchor;
#else
typedef void GodotARAnchor;
#endif
class ARKitInterface : public ARVRInterface { class ARKitInterface : public ARVRInterface {
GDCLASS(ARKitInterface, ARVRInterface); GDCLASS(ARKitInterface, ARVRInterface);
@ -115,8 +121,8 @@ public:
virtual void process(); virtual void process();
// called by delegate (void * because C++ and Obj-C don't always mix, should really change all platform/iphone/*.cpp files to .mm) // called by delegate (void * because C++ and Obj-C don't always mix, should really change all platform/iphone/*.cpp files to .mm)
void _add_or_update_anchor(void *p_anchor); void _add_or_update_anchor(GodotARAnchor *p_anchor);
void _remove_anchor(void *p_anchor); void _remove_anchor(GodotARAnchor *p_anchor);
ARKitInterface(); ARKitInterface();
~ARKitInterface(); ~ARKitInterface();

View File

@ -305,10 +305,8 @@ void ARKitInterface::uninitialize() {
remove_all_anchors(); remove_all_anchors();
if (@available(iOS 11.0, *)) { if (@available(iOS 11.0, *)) {
[ar_session release]; ar_session = nil;
ar_session = NULL;
} }
[ar_delegate release];
ar_delegate = NULL; ar_delegate = NULL;
initialized = false; initialized = false;
@ -684,7 +682,7 @@ void ARKitInterface::process() {
} }
} }
void ARKitInterface::_add_or_update_anchor(void *p_anchor) { void ARKitInterface::_add_or_update_anchor(GodotARAnchor *p_anchor) {
_THREAD_SAFE_METHOD_ _THREAD_SAFE_METHOD_
if (@available(iOS 11.0, *)) { if (@available(iOS 11.0, *)) {
@ -746,7 +744,7 @@ void ARKitInterface::_add_or_update_anchor(void *p_anchor) {
} }
} }
void ARKitInterface::_remove_anchor(void *p_anchor) { void ARKitInterface::_remove_anchor(GodotARAnchor *p_anchor) {
_THREAD_SAFE_METHOD_ _THREAD_SAFE_METHOD_
if (@available(iOS 11.0, *)) { if (@available(iOS 11.0, *)) {

View File

@ -124,18 +124,12 @@
if (output) { if (output) {
[self removeOutput:output]; [self removeOutput:output];
[output setSampleBufferDelegate:nil queue:NULL]; [output setSampleBufferDelegate:nil queue:NULL];
[output release];
output = nil; output = nil;
} }
[self commitConfiguration]; [self commitConfiguration];
} }
- (void)dealloc {
// bye bye
[super dealloc];
}
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
// This gets called every time our camera has a new image for us to process. // This gets called every time our camera has a new image for us to process.
// May need to investigate in a way to throttle this if we get more images then we're rendering frames.. // May need to investigate in a way to throttle this if we get more images then we're rendering frames..
@ -270,7 +264,6 @@ CameraFeedIOS::CameraFeedIOS() {
void CameraFeedIOS::set_device(AVCaptureDevice *p_device) { void CameraFeedIOS::set_device(AVCaptureDevice *p_device) {
device = p_device; device = p_device;
[device retain];
// get some info // get some info
NSString *device_name = p_device.localizedName; NSString *device_name = p_device.localizedName;
@ -284,15 +277,13 @@ void CameraFeedIOS::set_device(AVCaptureDevice *p_device) {
}; };
CameraFeedIOS::~CameraFeedIOS() { CameraFeedIOS::~CameraFeedIOS() {
if (capture_session != NULL) { if (capture_session) {
[capture_session release]; capture_session = nil;
capture_session = NULL; }
};
if (device != NULL) { if (device) {
[device release]; device = nil;
device = NULL; }
};
}; };
bool CameraFeedIOS::activate_feed() { bool CameraFeedIOS::activate_feed() {
@ -310,9 +301,8 @@ void CameraFeedIOS::deactivate_feed() {
// end camera capture if we have one // end camera capture if we have one
if (capture_session) { if (capture_session) {
[capture_session cleanup]; [capture_session cleanup];
[capture_session release]; capture_session = nil;
capture_session = NULL; }
};
}; };
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -345,8 +335,6 @@ void CameraFeedIOS::deactivate_feed() {
// remove notifications // remove notifications
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceWasConnectedNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceWasConnectedNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceWasDisconnectedNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceWasDisconnectedNotification object:nil];
[super dealloc];
} }
@end @end
@ -449,5 +437,5 @@ CameraIOS::CameraIOS() {
}; };
CameraIOS::~CameraIOS() { CameraIOS::~CameraIOS() {
[device_notifications release]; device_notifications = nil;
}; };

View File

@ -131,8 +131,7 @@ GD_PINVOKE_EXPORT void *xamarin_timezone_get_data(const char *p_name, uint32_t *
NSTimeZone *tz = nil; NSTimeZone *tz = nil;
if (p_name) { if (p_name) {
NSString *n = [[NSString alloc] initWithUTF8String:p_name]; NSString *n = [[NSString alloc] initWithUTF8String:p_name];
tz = [[[NSTimeZone alloc] initWithName:n] autorelease]; tz = [[NSTimeZone alloc] initWithName:n];
[n release];
} else { } else {
tz = [NSTimeZone localTimeZone]; tz = [NSTimeZone localTimeZone];
} }

View File

@ -144,8 +144,6 @@ static ViewController *mainViewController = nil;
- (void)dealloc { - (void)dealloc {
self.window = nil; self.window = nil;
[super dealloc];
} }
@end @end

View File

@ -115,18 +115,18 @@ def configure(env):
CCFLAGS=( CCFLAGS=(
"-arch " "-arch "
+ arch_flag + arch_flag
+ " -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks -fasm-blocks -isysroot $IPHONESDK -mios-simulator-version-min=10.0" + " -fobjc-arc -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks -fasm-blocks -isysroot $IPHONESDK -mios-simulator-version-min=10.0"
).split() ).split()
) )
elif env["arch"] == "arm": elif env["arch"] == "arm":
detect_darwin_sdk_path("iphone", env) detect_darwin_sdk_path("iphone", env)
env.Append( env.Append(
CCFLAGS='-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -isysroot $IPHONESDK -fvisibility=hidden -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=10.0 -MMD -MT dependencies'.split() CCFLAGS='-fobjc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -isysroot $IPHONESDK -fvisibility=hidden -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=10.0 -MMD -MT dependencies'.split()
) )
elif env["arch"] == "arm64": elif env["arch"] == "arm64":
detect_darwin_sdk_path("iphone", env) detect_darwin_sdk_path("iphone", env)
env.Append( env.Append(
CCFLAGS="-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=10.0 -isysroot $IPHONESDK".split() CCFLAGS="-fobjc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=10.0 -isysroot $IPHONESDK".split()
) )
env.Append(CPPDEFINES=["NEED_LONG_INT"]) env.Append(CPPDEFINES=["NEED_LONG_INT"])
env.Append(CPPDEFINES=["LIBYUV_DISABLE_NEON"]) env.Append(CPPDEFINES=["LIBYUV_DISABLE_NEON"])

View File

@ -130,8 +130,6 @@ bool gles3_available = true;
if (context) { if (context) {
context = nil; context = nil;
} }
[super dealloc];
} }
- (BOOL)createFramebuffer { - (BOOL)createFramebuffer {

View File

@ -71,7 +71,12 @@ Error GameCenter::authenticate() {
// after the view is cancelled or the user logs in. Or if the user's already logged in, it's // after the view is cancelled or the user logs in. Or if the user's already logged in, it's
// called just once to confirm they're authenticated. This is why no result needs to be specified // called just once to confirm they're authenticated. This is why no result needs to be specified
// in the presentViewController phase. In this case, more calls to this function will follow. // in the presentViewController phase. In this case, more calls to this function will follow.
_weakify(root_controller);
_weakify(player);
player.authenticateHandler = (^(UIViewController *controller, NSError *error) { player.authenticateHandler = (^(UIViewController *controller, NSError *error) {
_strongify(root_controller);
_strongify(player);
if (controller) { if (controller) {
[root_controller presentViewController:controller animated:YES completion:nil]; [root_controller presentViewController:controller animated:YES completion:nil];
} else { } else {
@ -106,8 +111,8 @@ Error GameCenter::post_score(Variant p_score) {
float score = params["score"]; float score = params["score"];
String category = params["category"]; String category = params["category"];
NSString *cat_str = [[[NSString alloc] initWithUTF8String:category.utf8().get_data()] autorelease]; NSString *cat_str = [[NSString alloc] initWithUTF8String:category.utf8().get_data()];
GKScore *reporter = [[[GKScore alloc] initWithLeaderboardIdentifier:cat_str] autorelease]; GKScore *reporter = [[GKScore alloc] initWithLeaderboardIdentifier:cat_str];
reporter.value = score; reporter.value = score;
ERR_FAIL_COND_V([GKScore respondsToSelector:@selector(reportScores)], ERR_UNAVAILABLE); ERR_FAIL_COND_V([GKScore respondsToSelector:@selector(reportScores)], ERR_UNAVAILABLE);
@ -137,8 +142,8 @@ Error GameCenter::award_achievement(Variant p_params) {
String name = params["name"]; String name = params["name"];
float progress = params["progress"]; float progress = params["progress"];
NSString *name_str = [[[NSString alloc] initWithUTF8String:name.utf8().get_data()] autorelease]; NSString *name_str = [[NSString alloc] initWithUTF8String:name.utf8().get_data()];
GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier:name_str] autorelease]; GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:name_str];
ERR_FAIL_COND_V(!achievement, FAILED); ERR_FAIL_COND_V(!achievement, FAILED);
ERR_FAIL_COND_V([GKAchievement respondsToSelector:@selector(reportAchievements)], ERR_UNAVAILABLE); ERR_FAIL_COND_V([GKAchievement respondsToSelector:@selector(reportAchievements)], ERR_UNAVAILABLE);
@ -302,7 +307,7 @@ Error GameCenter::show_game_center(Variant p_params) {
controller.leaderboardIdentifier = nil; controller.leaderboardIdentifier = nil;
if (params.has("leaderboard_name")) { if (params.has("leaderboard_name")) {
String name = params["leaderboard_name"]; String name = params["leaderboard_name"];
NSString *name_str = [[[NSString alloc] initWithUTF8String:name.utf8().get_data()] autorelease]; NSString *name_str = [[NSString alloc] initWithUTF8String:name.utf8().get_data()];
controller.leaderboardIdentifier = name_str; controller.leaderboardIdentifier = name_str;
} }
} }

View File

@ -139,8 +139,6 @@ static const int max_touches = 8;
if (self.delayGestureRecognizer) { if (self.delayGestureRecognizer) {
self.delayGestureRecognizer = nil; self.delayGestureRecognizer = nil;
} }
[super dealloc];
} }
- (void)godot_commonInit { - (void)godot_commonInit {

View File

@ -75,7 +75,6 @@ const CGFloat kGLGestureMovementDistance = 0.5;
[self.view touchesBegan:delayedTouches withEvent:delayedEvent]; [self.view touchesBegan:delayedTouches withEvent:delayedEvent];
} }
[delayedTouches release];
delayedTouches = nil; delayedTouches = nil;
delayedEvent = nil; delayedEvent = nil;
} }
@ -103,16 +102,13 @@ const CGFloat kGLGestureMovementDistance = 0.5;
if (distance > kGLGestureMovementDistance) { if (distance > kGLGestureMovementDistance) {
[delayTimer fire]; [delayTimer fire];
[self.view touchesMoved:cleared withEvent:event]; [self.view touchesMoved:cleared withEvent:event];
[cleared release];
return; return;
} }
} }
[cleared release];
return; return;
} }
[self.view touchesMoved:cleared withEvent:event]; [self.view touchesMoved:cleared withEvent:event];
[cleared release];
} }
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
@ -120,7 +116,6 @@ const CGFloat kGLGestureMovementDistance = 0.5;
NSSet *cleared = [self copyClearedTouches:touches phase:UITouchPhaseEnded]; NSSet *cleared = [self copyClearedTouches:touches phase:UITouchPhaseEnded];
[self.view touchesEnded:cleared withEvent:event]; [self.view touchesEnded:cleared withEvent:event];
[cleared release];
} }
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {

View File

@ -142,7 +142,7 @@ Variant nsobject_to_variant(NSObject *object) {
NSObject *variant_to_nsobject(Variant v) { NSObject *variant_to_nsobject(Variant v) {
if (v.get_type() == Variant::STRING) { if (v.get_type() == Variant::STRING) {
return [[[NSString alloc] initWithUTF8String:((String)v).utf8().get_data()] autorelease]; return [[NSString alloc] initWithUTF8String:((String)v).utf8().get_data()];
} else if (v.get_type() == Variant::REAL) { } else if (v.get_type() == Variant::REAL) {
return [NSNumber numberWithDouble:(double)v]; return [NSNumber numberWithDouble:(double)v];
} else if (v.get_type() == Variant::INT) { } else if (v.get_type() == Variant::INT) {
@ -150,11 +150,11 @@ NSObject *variant_to_nsobject(Variant v) {
} else if (v.get_type() == Variant::BOOL) { } else if (v.get_type() == Variant::BOOL) {
return [NSNumber numberWithBool:BOOL((bool)v)]; return [NSNumber numberWithBool:BOOL((bool)v)];
} else if (v.get_type() == Variant::DICTIONARY) { } else if (v.get_type() == Variant::DICTIONARY) {
NSMutableDictionary *result = [[[NSMutableDictionary alloc] init] autorelease]; NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
Dictionary dic = v; Dictionary dic = v;
Array keys = dic.keys(); Array keys = dic.keys();
for (int i = 0; i < keys.size(); ++i) { for (int i = 0; i < keys.size(); ++i) {
NSString *key = [[[NSString alloc] initWithUTF8String:((String)(keys[i])).utf8().get_data()] autorelease]; NSString *key = [[NSString alloc] initWithUTF8String:((String)(keys[i])).utf8().get_data()];
NSObject *value = variant_to_nsobject(dic[keys[i]]); NSObject *value = variant_to_nsobject(dic[keys[i]]);
if (key == NULL || value == NULL) { if (key == NULL || value == NULL) {
@ -165,7 +165,7 @@ NSObject *variant_to_nsobject(Variant v) {
} }
return result; return result;
} else if (v.get_type() == Variant::ARRAY) { } else if (v.get_type() == Variant::ARRAY) {
NSMutableArray *result = [[[NSMutableArray alloc] init] autorelease]; NSMutableArray *result = [[NSMutableArray alloc] init];
Array arr = v; Array arr = v;
for (int i = 0; i < arr.size(); ++i) { for (int i = 0; i < arr.size(); ++i) {
NSObject *value = variant_to_nsobject(arr[i]); NSObject *value = variant_to_nsobject(arr[i]);
@ -188,7 +188,7 @@ NSObject *variant_to_nsobject(Variant v) {
Error ICloud::remove_key(Variant p_param) { Error ICloud::remove_key(Variant p_param) {
String param = p_param; String param = p_param;
NSString *key = [[[NSString alloc] initWithUTF8String:param.utf8().get_data()] autorelease]; NSString *key = [[NSString alloc] initWithUTF8String:param.utf8().get_data()];
NSUbiquitousKeyValueStore *store = [NSUbiquitousKeyValueStore defaultStore]; NSUbiquitousKeyValueStore *store = [NSUbiquitousKeyValueStore defaultStore];
@ -211,7 +211,7 @@ Variant ICloud::set_key_values(Variant p_params) {
String variant_key = keys[i]; String variant_key = keys[i];
Variant variant_value = params[variant_key]; Variant variant_value = params[variant_key];
NSString *key = [[[NSString alloc] initWithUTF8String:variant_key.utf8().get_data()] autorelease]; NSString *key = [[NSString alloc] initWithUTF8String:variant_key.utf8().get_data()];
if (key == NULL) { if (key == NULL) {
error_keys.push_back(variant_key); error_keys.push_back(variant_key);
continue; continue;
@ -234,7 +234,7 @@ Variant ICloud::set_key_values(Variant p_params) {
Variant ICloud::get_key_value(Variant p_param) { Variant ICloud::get_key_value(Variant p_param) {
String param = p_param; String param = p_param;
NSString *key = [[[NSString alloc] initWithUTF8String:param.utf8().get_data()] autorelease]; NSString *key = [[NSString alloc] initWithUTF8String:param.utf8().get_data()];
NSUbiquitousKeyValueStore *store = [NSUbiquitousKeyValueStore defaultStore]; NSUbiquitousKeyValueStore *store = [NSUbiquitousKeyValueStore defaultStore];
if (![[store dictionaryRepresentation] objectForKey:key]) { if (![[store dictionaryRepresentation] objectForKey:key]) {

View File

@ -53,7 +53,6 @@ static NSArray *latestProducts;
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:self.priceLocale]; [numberFormatter setLocale:self.priceLocale];
NSString *formattedString = [numberFormatter stringFromNumber:self.price]; NSString *formattedString = [numberFormatter stringFromNumber:self.price];
[numberFormatter release];
return formattedString; return formattedString;
} }
@end @end
@ -123,8 +122,6 @@ void InAppStore::_bind_methods() {
ret["invalid_ids"] = invalid_ids; ret["invalid_ids"] = invalid_ids;
InAppStore::get_singleton()->_post_event(ret); InAppStore::get_singleton()->_post_event(ret);
[request release];
}; };
@end @end
@ -137,14 +134,14 @@ Error InAppStore::request_product_info(Variant p_params) {
PoolStringArray pids = params["product_ids"]; PoolStringArray pids = params["product_ids"];
printf("************ request product info! %i\n", pids.size()); printf("************ request product info! %i\n", pids.size());
NSMutableArray *array = [[[NSMutableArray alloc] initWithCapacity:pids.size()] autorelease]; NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:pids.size()];
for (int i = 0; i < pids.size(); i++) { for (int i = 0; i < pids.size(); i++) {
printf("******** adding %ls to product list\n", pids[i].c_str()); printf("******** adding %ls to product list\n", pids[i].c_str());
NSString *pid = [[[NSString alloc] initWithUTF8String:pids[i].utf8().get_data()] autorelease]; NSString *pid = [[NSString alloc] initWithUTF8String:pids[i].utf8().get_data()];
[array addObject:pid]; [array addObject:pid];
}; };
NSSet *products = [[[NSSet alloc] initWithArray:array] autorelease]; NSSet *products = [[NSSet alloc] initWithArray:array];
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:products]; SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:products];
ProductsDelegate *delegate = [[ProductsDelegate alloc] init]; ProductsDelegate *delegate = [[ProductsDelegate alloc] init];
@ -256,7 +253,7 @@ Error InAppStore::purchase(Variant p_params) {
Dictionary params = p_params; Dictionary params = p_params;
ERR_FAIL_COND_V(!params.has("product_id"), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(!params.has("product_id"), ERR_INVALID_PARAMETER);
NSString *pid = [[[NSString alloc] initWithUTF8String:String(params["product_id"]).utf8().get_data()] autorelease]; NSString *pid = [[NSString alloc] initWithUTF8String:String(params["product_id"]).utf8().get_data()];
SKProduct *product = nil; SKProduct *product = nil;
@ -301,7 +298,7 @@ void InAppStore::_post_event(Variant p_event) {
void InAppStore::_record_purchase(String product_id) { void InAppStore::_record_purchase(String product_id) {
String skey = "purchased/" + product_id; String skey = "purchased/" + product_id;
NSString *key = [[[NSString alloc] initWithUTF8String:skey.utf8().get_data()] autorelease]; NSString *key = [[NSString alloc] initWithUTF8String:skey.utf8().get_data()];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:key]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:key];
[[NSUserDefaults standardUserDefaults] synchronize]; [[NSUserDefaults standardUserDefaults] synchronize];
}; };

View File

@ -31,6 +31,7 @@
#include "ios.h" #include "ios.h"
#import "app_delegate.h" #import "app_delegate.h"
#import "view_controller.h"
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>

View File

@ -130,8 +130,6 @@ void JoypadIPhone::start_processing() {
- (void)dealloc { - (void)dealloc {
[self finishObserving]; [self finishObserving];
[super dealloc];
} }
- (int)getJoyIdForController:(GCController *)controller { - (int)getJoyIdForController:(GCController *)controller {
@ -250,7 +248,13 @@ void JoypadIPhone::start_processing() {
// The extended gamepad profile has all the input you could possibly find on // The extended gamepad profile has all the input you could possibly find on
// a gamepad but will only be active if your gamepad actually has all of // a gamepad but will only be active if your gamepad actually has all of
// these... // these...
_weakify(self);
_weakify(controller);
controller.extendedGamepad.valueChangedHandler = ^(GCExtendedGamepad *gamepad, GCControllerElement *element) { controller.extendedGamepad.valueChangedHandler = ^(GCExtendedGamepad *gamepad, GCControllerElement *element) {
_strongify(self);
_strongify(controller);
int joy_id = [self getJoyIdForController:controller]; int joy_id = [self getJoyIdForController:controller];
if (element == gamepad.buttonA) { if (element == gamepad.buttonA) {
@ -310,7 +314,13 @@ void JoypadIPhone::start_processing() {
}; };
} else if (controller.microGamepad != nil) { } else if (controller.microGamepad != nil) {
// micro gamepads were added in OS 9 and feature just 2 buttons and a d-pad // micro gamepads were added in OS 9 and feature just 2 buttons and a d-pad
_weakify(self);
_weakify(controller);
controller.microGamepad.valueChangedHandler = ^(GCMicroGamepad *gamepad, GCControllerElement *element) { controller.microGamepad.valueChangedHandler = ^(GCMicroGamepad *gamepad, GCControllerElement *element) {
_strongify(self);
_strongify(controller);
int joy_id = [self getJoyIdForController:controller]; int joy_id = [self getJoyIdForController:controller];
if (element == gamepad.buttonA) { if (element == gamepad.buttonA) {

View File

@ -36,3 +36,10 @@
#define PLATFORM_REFCOUNT #define PLATFORM_REFCOUNT
#define PTHREAD_RENAME_SELF #define PTHREAD_RENAME_SELF
#define _weakify(var) __weak typeof(var) GDWeak_##var = var;
#define _strongify(var) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
__strong typeof(var) var = GDWeak_##var; \
_Pragma("clang diagnostic pop")

View File

@ -122,8 +122,6 @@
self.renderer = nil; self.renderer = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
} }
// MARK: Orientation // MARK: Orientation