Sergey Minakov преди 5 години
родител
ревизия
5d1284204d

+ 8 - 2
modules/arkit/arkit_interface.h

@@ -44,6 +44,12 @@
 // forward declaration for some needed objects
 class ARKitShader;
 
+#ifdef __OBJC__
+typedef NSObject GodotARAnchor;
+#else
+typedef void GodotARAnchor;
+#endif
+
 class ARKitInterface : public ARVRInterface {
 	GDCLASS(ARKitInterface, ARVRInterface);
 
@@ -115,8 +121,8 @@ public:
 	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)
-	void _add_or_update_anchor(void *p_anchor);
-	void _remove_anchor(void *p_anchor);
+	void _add_or_update_anchor(GodotARAnchor *p_anchor);
+	void _remove_anchor(GodotARAnchor *p_anchor);
 
 	ARKitInterface();
 	~ARKitInterface();

+ 3 - 5
modules/arkit/arkit_interface.mm

@@ -305,10 +305,8 @@ void ARKitInterface::uninitialize() {
 		remove_all_anchors();
 
 		if (@available(iOS 11.0, *)) {
-			[ar_session release];
-			ar_session = NULL;
+			ar_session = nil;
 		}
-		[ar_delegate release];
 
 		ar_delegate = NULL;
 		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_
 
 	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_
 
 	if (@available(iOS 11.0, *)) {

+ 9 - 21
modules/camera/camera_ios.mm

@@ -124,18 +124,12 @@
 	if (output) {
 		[self removeOutput:output];
 		[output setSampleBufferDelegate:nil queue:NULL];
-		[output release];
 		output = nil;
 	}
 
 	[self commitConfiguration];
 }
 
-- (void)dealloc {
-	// bye bye
-	[super dealloc];
-}
-
 - (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.
 	// 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) {
 	device = p_device;
-	[device retain];
 
 	// get some info
 	NSString *device_name = p_device.localizedName;
@@ -284,15 +277,13 @@ void CameraFeedIOS::set_device(AVCaptureDevice *p_device) {
 };
 
 CameraFeedIOS::~CameraFeedIOS() {
-	if (capture_session != NULL) {
-		[capture_session release];
-		capture_session = NULL;
-	};
+	if (capture_session) {
+		capture_session = nil;
+	}
 
-	if (device != NULL) {
-		[device release];
-		device = NULL;
-	};
+	if (device) {
+		device = nil;
+	}
 };
 
 bool CameraFeedIOS::activate_feed() {
@@ -310,9 +301,8 @@ void CameraFeedIOS::deactivate_feed() {
 	// end camera capture if we have one
 	if (capture_session) {
 		[capture_session cleanup];
-		[capture_session release];
-		capture_session = NULL;
-	};
+		capture_session = nil;
+	}
 };
 
 //////////////////////////////////////////////////////////////////////////
@@ -345,8 +335,6 @@ void CameraFeedIOS::deactivate_feed() {
 	// remove notifications
 	[[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceWasConnectedNotification object:nil];
 	[[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceWasDisconnectedNotification object:nil];
-
-	[super dealloc];
 }
 
 @end
@@ -449,5 +437,5 @@ CameraIOS::CameraIOS() {
 };
 
 CameraIOS::~CameraIOS() {
-	[device_notifications release];
+	device_notifications = nil;
 };

+ 1 - 2
modules/mono/mono_gd/support/ios_support.mm

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

+ 0 - 2
platform/iphone/app_delegate.mm

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

+ 3 - 3
platform/iphone/detect.py

@@ -115,18 +115,18 @@ def configure(env):
             CCFLAGS=(
                 "-arch "
                 + 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()
         )
     elif env["arch"] == "arm":
         detect_darwin_sdk_path("iphone", env)
         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":
         detect_darwin_sdk_path("iphone", env)
         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=["LIBYUV_DISABLE_NEON"])

+ 0 - 2
platform/iphone/display_layer.mm

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

+ 10 - 5
platform/iphone/game_center.mm

@@ -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
 	// 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.
+	_weakify(root_controller);
+	_weakify(player);
 	player.authenticateHandler = (^(UIViewController *controller, NSError *error) {
+		_strongify(root_controller);
+		_strongify(player);
+
 		if (controller) {
 			[root_controller presentViewController:controller animated:YES completion:nil];
 		} else {
@@ -106,8 +111,8 @@ Error GameCenter::post_score(Variant p_score) {
 	float score = params["score"];
 	String category = params["category"];
 
-	NSString *cat_str = [[[NSString alloc] initWithUTF8String:category.utf8().get_data()] autorelease];
-	GKScore *reporter = [[[GKScore alloc] initWithLeaderboardIdentifier:cat_str] autorelease];
+	NSString *cat_str = [[NSString alloc] initWithUTF8String:category.utf8().get_data()];
+	GKScore *reporter = [[GKScore alloc] initWithLeaderboardIdentifier:cat_str];
 	reporter.value = score;
 
 	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"];
 	float progress = params["progress"];
 
-	NSString *name_str = [[[NSString alloc] initWithUTF8String:name.utf8().get_data()] autorelease];
-	GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier:name_str] autorelease];
+	NSString *name_str = [[NSString alloc] initWithUTF8String:name.utf8().get_data()];
+	GKAchievement *achievement = [[GKAchievement alloc] initWithIdentifier:name_str];
 	ERR_FAIL_COND_V(!achievement, FAILED);
 
 	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;
 		if (params.has("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;
 		}
 	}

+ 0 - 2
platform/iphone/godot_view.mm

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

+ 0 - 5
platform/iphone/godot_view_gesture_recognizer.mm

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

+ 7 - 7
platform/iphone/icloud.mm

@@ -142,7 +142,7 @@ Variant nsobject_to_variant(NSObject *object) {
 
 NSObject *variant_to_nsobject(Variant v) {
 	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) {
 		return [NSNumber numberWithDouble:(double)v];
 	} else if (v.get_type() == Variant::INT) {
@@ -150,11 +150,11 @@ NSObject *variant_to_nsobject(Variant v) {
 	} else if (v.get_type() == Variant::BOOL) {
 		return [NSNumber numberWithBool:BOOL((bool)v)];
 	} else if (v.get_type() == Variant::DICTIONARY) {
-		NSMutableDictionary *result = [[[NSMutableDictionary alloc] init] autorelease];
+		NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
 		Dictionary dic = v;
 		Array keys = dic.keys();
 		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]]);
 
 			if (key == NULL || value == NULL) {
@@ -165,7 +165,7 @@ NSObject *variant_to_nsobject(Variant v) {
 		}
 		return result;
 	} else if (v.get_type() == Variant::ARRAY) {
-		NSMutableArray *result = [[[NSMutableArray alloc] init] autorelease];
+		NSMutableArray *result = [[NSMutableArray alloc] init];
 		Array arr = v;
 		for (int i = 0; i < arr.size(); ++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) {
 	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];
 
@@ -211,7 +211,7 @@ Variant ICloud::set_key_values(Variant p_params) {
 		String variant_key = keys[i];
 		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) {
 			error_keys.push_back(variant_key);
 			continue;
@@ -234,7 +234,7 @@ Variant ICloud::set_key_values(Variant p_params) {
 Variant ICloud::get_key_value(Variant 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];
 
 	if (![[store dictionaryRepresentation] objectForKey:key]) {

+ 5 - 8
platform/iphone/in_app_store.mm

@@ -53,7 +53,6 @@ static NSArray *latestProducts;
 	[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
 	[numberFormatter setLocale:self.priceLocale];
 	NSString *formattedString = [numberFormatter stringFromNumber:self.price];
-	[numberFormatter release];
 	return formattedString;
 }
 @end
@@ -123,8 +122,6 @@ void InAppStore::_bind_methods() {
 	ret["invalid_ids"] = invalid_ids;
 
 	InAppStore::get_singleton()->_post_event(ret);
-
-	[request release];
 };
 
 @end
@@ -137,14 +134,14 @@ Error InAppStore::request_product_info(Variant p_params) {
 	PoolStringArray pids = params["product_ids"];
 	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++) {
 		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];
 	};
 
-	NSSet *products = [[[NSSet alloc] initWithArray:array] autorelease];
+	NSSet *products = [[NSSet alloc] initWithArray:array];
 	SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:products];
 
 	ProductsDelegate *delegate = [[ProductsDelegate alloc] init];
@@ -256,7 +253,7 @@ Error InAppStore::purchase(Variant p_params) {
 	Dictionary params = p_params;
 	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;
 
@@ -301,7 +298,7 @@ void InAppStore::_post_event(Variant p_event) {
 void InAppStore::_record_purchase(String 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] synchronize];
 };

+ 1 - 0
platform/iphone/ios.mm

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

+ 12 - 2
platform/iphone/joypad_iphone.mm

@@ -130,8 +130,6 @@ void JoypadIPhone::start_processing() {
 
 - (void)dealloc {
 	[self finishObserving];
-
-	[super dealloc];
 }
 
 - (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
 		// a gamepad but will only be active if your gamepad actually has all of
 		// these...
+		_weakify(self);
+		_weakify(controller);
+
 		controller.extendedGamepad.valueChangedHandler = ^(GCExtendedGamepad *gamepad, GCControllerElement *element) {
+			_strongify(self);
+			_strongify(controller);
+
 			int joy_id = [self getJoyIdForController:controller];
 
 			if (element == gamepad.buttonA) {
@@ -310,7 +314,13 @@ void JoypadIPhone::start_processing() {
 		};
 	} else if (controller.microGamepad != nil) {
 		// 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) {
+			_strongify(self);
+			_strongify(controller);
+
 			int joy_id = [self getJoyIdForController:controller];
 
 			if (element == gamepad.buttonA) {

+ 7 - 0
platform/iphone/platform_config.h

@@ -36,3 +36,10 @@
 #define PLATFORM_REFCOUNT
 
 #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")

+ 0 - 2
platform/iphone/view_controller.mm

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