Merge pull request #41504 from naithar/fix/analyzer-3.2

[3.2] [iOS] Leaks and deprecations fix
This commit is contained in:
Rémi Verschelde 2020-08-25 18:37:02 +02:00 committed by GitHub
commit 6b5102cf90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 26 deletions

View file

@ -49,8 +49,10 @@ void _set_keep_screen_on(bool p_enabled);
Error _shell_open(String p_uri) { Error _shell_open(String p_uri) {
NSString *url = [[NSString alloc] initWithUTF8String:p_uri.utf8().get_data()]; NSString *url = [[NSString alloc] initWithUTF8String:p_uri.utf8().get_data()];
if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url]]) if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url]]) {
[url release];
return ERR_CANT_OPEN; return ERR_CANT_OPEN;
}
printf("opening url %ls\n", p_uri.c_str()); printf("opening url %ls\n", p_uri.c_str());
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
@ -548,7 +550,7 @@ static int frame_count = 0;
// can use that instead? (note that left and right seem swapped) // can use that instead? (note that left and right seem swapped)
switch ([[UIApplication sharedApplication] statusBarOrientation]) { switch ([[UIApplication sharedApplication] statusBarOrientation]) {
case UIDeviceOrientationLandscapeLeft: { case UIInterfaceOrientationLandscapeLeft: {
OSIPhone::get_singleton()->update_gravity(-gravity.y, gravity.x, OSIPhone::get_singleton()->update_gravity(-gravity.y, gravity.x,
gravity.z); gravity.z);
OSIPhone::get_singleton()->update_accelerometer( OSIPhone::get_singleton()->update_accelerometer(
@ -559,7 +561,7 @@ static int frame_count = 0;
OSIPhone::get_singleton()->update_gyroscope(-rotation.y, rotation.x, OSIPhone::get_singleton()->update_gyroscope(-rotation.y, rotation.x,
rotation.z); rotation.z);
}; break; }; break;
case UIDeviceOrientationLandscapeRight: { case UIInterfaceOrientationLandscapeRight: {
OSIPhone::get_singleton()->update_gravity(gravity.y, -gravity.x, OSIPhone::get_singleton()->update_gravity(gravity.y, -gravity.x,
gravity.z); gravity.z);
OSIPhone::get_singleton()->update_accelerometer( OSIPhone::get_singleton()->update_accelerometer(
@ -570,7 +572,7 @@ static int frame_count = 0;
OSIPhone::get_singleton()->update_gyroscope(rotation.y, -rotation.x, OSIPhone::get_singleton()->update_gyroscope(rotation.y, -rotation.x,
rotation.z); rotation.z);
}; break; }; break;
case UIDeviceOrientationPortraitUpsideDown: { case UIInterfaceOrientationPortraitUpsideDown: {
OSIPhone::get_singleton()->update_gravity(-gravity.x, gravity.y, OSIPhone::get_singleton()->update_gravity(-gravity.x, gravity.y,
gravity.z); gravity.z);
OSIPhone::get_singleton()->update_accelerometer( OSIPhone::get_singleton()->update_accelerometer(
@ -595,7 +597,7 @@ static int frame_count = 0;
}; };
} }
bool quit_request = OSIPhone::get_singleton()->iterate(); OSIPhone::get_singleton()->iterate();
}; };
}; break; }; break;
@ -614,7 +616,6 @@ static int frame_count = 0;
is_focus_out = false; is_focus_out = false;
[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
// disable idle timer // disable idle timer
// application.idleTimerDisabled = YES; // application.idleTimerDisabled = YES;

View file

@ -107,7 +107,7 @@
- (void)keyboardOnScreen:(NSNotification *)notification; - (void)keyboardOnScreen:(NSNotification *)notification;
- (void)keyboardHidden:(NSNotification *)notification; - (void)keyboardHidden:(NSNotification *)notification;
@property NSTimeInterval animationInterval; @property(nonatomic, assign) NSTimeInterval animationInterval;
@property(nonatomic, assign) BOOL useCADisplayLink; @property(nonatomic, assign) BOOL useCADisplayLink;
@end @end

View file

@ -80,10 +80,12 @@ void _hide_keyboard() {
}; };
Rect2 _get_ios_window_safe_area(float p_window_width, float p_window_height) { Rect2 _get_ios_window_safe_area(float p_window_width, float p_window_height) {
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0); UIEdgeInsets insets = UIEdgeInsetsZero;
if (_instance != nil && [_instance respondsToSelector:@selector(safeAreaInsets)]) {
if (@available(iOS 11.0, *)) {
insets = [_instance safeAreaInsets]; insets = [_instance safeAreaInsets];
} }
ERR_FAIL_COND_V(insets.left < 0 || insets.top < 0 || insets.right < 0 || insets.bottom < 0, ERR_FAIL_COND_V(insets.left < 0 || insets.top < 0 || insets.right < 0 || insets.bottom < 0,
Rect2(0, 0, p_window_width, p_window_height)); Rect2(0, 0, p_window_width, p_window_height));
UIEdgeInsets window_insets = UIEdgeInsetsMake(_points_to_pixels(insets.top), _points_to_pixels(insets.left), _points_to_pixels(insets.bottom), _points_to_pixels(insets.right)); UIEdgeInsets window_insets = UIEdgeInsetsMake(_points_to_pixels(insets.top), _points_to_pixels(insets.left), _points_to_pixels(insets.bottom), _points_to_pixels(insets.right));
@ -699,7 +701,7 @@ static void clear_touches() {
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == _instance.avPlayerItem && [keyPath isEqualToString:@"status"]) { if (object == _instance.avPlayerItem && [keyPath isEqualToString:@"status"]) {
if (_instance.avPlayerItem.status == AVPlayerStatusFailed || _instance.avPlayer.status == AVPlayerStatusFailed) { if (_instance.avPlayerItem.status == AVPlayerItemStatusFailed || _instance.avPlayer.status == AVPlayerStatusFailed) {
_stop_video(); _stop_video();
video_found_error = true; video_found_error = true;
} }

View file

@ -68,17 +68,18 @@ 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;
} }
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *cleared = [self clearTouches:touches phase:UITouchPhaseBegan]; NSSet *cleared = [self copyClearedTouches:touches phase:UITouchPhaseBegan];
[self delayTouches:cleared andEvent:event]; [self delayTouches:cleared andEvent:event];
} }
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *cleared = [self clearTouches:touches phase:UITouchPhaseMoved]; NSSet *cleared = [self copyClearedTouches:touches phase:UITouchPhaseMoved];
if (delayTimer) { if (delayTimer) {
// We should check if movement was significant enough to fire an event // We should check if movement was significant enough to fire an event
@ -95,20 +96,24 @@ 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 {
[delayTimer fire]; [delayTimer fire];
NSSet *cleared = [self clearTouches: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 {
@ -116,7 +121,7 @@ const CGFloat kGLGestureMovementDistance = 0.5;
[self.view touchesCancelled:touches withEvent:event]; [self.view touchesCancelled:touches withEvent:event];
}; };
- (NSSet *)clearTouches:(NSSet *)touches phase:(UITouchPhase)phaseToSave { - (NSSet *)copyClearedTouches:(NSSet *)touches phase:(UITouchPhase)phaseToSave {
NSMutableSet *cleared = [touches mutableCopy]; NSMutableSet *cleared = [touches mutableCopy];
for (UITouch *touch in touches) { for (UITouch *touch in touches) {

View file

@ -34,9 +34,6 @@
@interface ViewController : UIViewController <GKGameCenterControllerDelegate> { @interface ViewController : UIViewController <GKGameCenterControllerDelegate> {
}; };
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)p_orientation;
- (void)didReceiveMemoryWarning; - (void)didReceiveMemoryWarning;
- (void)viewDidLoad; - (void)viewDidLoad;

View file

@ -42,12 +42,12 @@ int add_cmdline(int, char **);
int add_path(int p_argc, char **p_args) { int add_path(int p_argc, char **p_args) {
NSString *str = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_path"]; NSString *str = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_path"];
if (!str) if (!str) {
return p_argc; return p_argc;
}
p_args[p_argc++] = "--path"; p_args[p_argc++] = (char *)"--path";
[str retain]; // memory leak lol (maybe make it static here and delete it in ViewController destructor? @todo p_args[p_argc++] = (char *)[str cStringUsingEncoding:NSUTF8StringEncoding];
p_args[p_argc++] = (char *)[str cString];
p_args[p_argc] = NULL; p_args[p_argc] = NULL;
return p_argc; return p_argc;
@ -60,12 +60,11 @@ int add_cmdline(int p_argc, char **p_args) {
return p_argc; return p_argc;
for (int i = 0; i < [arr count]; i++) { for (int i = 0; i < [arr count]; i++) {
NSString *str = [arr objectAtIndex:i]; NSString *str = [arr objectAtIndex:i];
if (!str) if (!str) {
continue; continue;
[str retain]; // @todo delete these at some point }
p_args[p_argc++] = (char *)[str cString]; p_args[p_argc++] = (char *)[str cStringUsingEncoding:NSUTF8StringEncoding];
}; };
p_args[p_argc] = NULL; p_args[p_argc] = NULL;
@ -81,7 +80,7 @@ int add_cmdline(int p_argc, char **p_args) {
@implementation ViewController @implementation ViewController
- (void)didReceiveMemoryWarning { - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
printf("*********** did receive memory warning!\n"); printf("*********** did receive memory warning!\n");
}; };