Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2] [iOS] Leaks and deprecations fix #41504

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions platform/iphone/app_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
Error _shell_open(String p_uri) {
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;
}

printf("opening url %ls\n", p_uri.c_str());
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
Expand Down Expand Up @@ -548,7 +550,7 @@ - (void)drawView:(GLView *)view;
// can use that instead? (note that left and right seem swapped)

switch ([[UIApplication sharedApplication] statusBarOrientation]) {
case UIDeviceOrientationLandscapeLeft: {
case UIInterfaceOrientationLandscapeLeft: {
OSIPhone::get_singleton()->update_gravity(-gravity.y, gravity.x,
gravity.z);
OSIPhone::get_singleton()->update_accelerometer(
Expand All @@ -559,7 +561,7 @@ - (void)drawView:(GLView *)view;
OSIPhone::get_singleton()->update_gyroscope(-rotation.y, rotation.x,
rotation.z);
}; break;
case UIDeviceOrientationLandscapeRight: {
case UIInterfaceOrientationLandscapeRight: {
OSIPhone::get_singleton()->update_gravity(gravity.y, -gravity.x,
gravity.z);
OSIPhone::get_singleton()->update_accelerometer(
Expand All @@ -570,7 +572,7 @@ - (void)drawView:(GLView *)view;
OSIPhone::get_singleton()->update_gyroscope(rotation.y, -rotation.x,
rotation.z);
}; break;
case UIDeviceOrientationPortraitUpsideDown: {
case UIInterfaceOrientationPortraitUpsideDown: {
OSIPhone::get_singleton()->update_gravity(-gravity.x, gravity.y,
gravity.z);
OSIPhone::get_singleton()->update_accelerometer(
Expand All @@ -595,7 +597,7 @@ - (void)drawView:(GLView *)view;
};
}

bool quit_request = OSIPhone::get_singleton()->iterate();
OSIPhone::get_singleton()->iterate();
};

}; break;
Expand All @@ -614,7 +616,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

is_focus_out = false;

[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
// disable idle timer
// application.idleTimerDisabled = YES;

Expand Down
2 changes: 1 addition & 1 deletion platform/iphone/gl_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
- (void)keyboardOnScreen:(NSNotification *)notification;
- (void)keyboardHidden:(NSNotification *)notification;

@property NSTimeInterval animationInterval;
@property(nonatomic, assign) NSTimeInterval animationInterval;
@property(nonatomic, assign) BOOL useCADisplayLink;

@end
Expand Down
8 changes: 5 additions & 3 deletions platform/iphone/gl_view.mm
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ void _hide_keyboard() {
};

Rect2 _get_ios_window_safe_area(float p_window_width, float p_window_height) {
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
if (_instance != nil && [_instance respondsToSelector:@selector(safeAreaInsets)]) {
UIEdgeInsets insets = UIEdgeInsetsZero;

if (@available(iOS 11.0, *)) {
insets = [_instance safeAreaInsets];
}

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));
UIEdgeInsets window_insets = UIEdgeInsetsMake(_points_to_pixels(insets.top), _points_to_pixels(insets.left), _points_to_pixels(insets.bottom), _points_to_pixels(insets.right));
Expand Down Expand Up @@ -699,7 +701,7 @@ - (void)dealloc {
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

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();
video_found_error = true;
}
Expand Down
13 changes: 9 additions & 4 deletions platform/iphone/gl_view_gesture_recognizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,18 @@ - (void)fireDelayedTouches:(id)timer {
[self.view touchesBegan:delayedTouches withEvent:delayedEvent];
}

[delayedTouches release];
delayedTouches = nil;
delayedEvent = nil;
}

- (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];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *cleared = [self clearTouches:touches phase:UITouchPhaseMoved];
NSSet *cleared = [self copyClearedTouches:touches phase:UITouchPhaseMoved];

if (delayTimer) {
// We should check if movement was significant enough to fire an event
Expand All @@ -95,28 +96,32 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
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 {
[delayTimer fire];

NSSet *cleared = [self clearTouches:touches phase:UITouchPhaseEnded];
NSSet *cleared = [self copyClearedTouches:touches phase:UITouchPhaseEnded];
[self.view touchesEnded:cleared withEvent:event];
[cleared release];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[delayTimer fire];
[self.view touchesCancelled:touches withEvent:event];
};

- (NSSet *)clearTouches:(NSSet *)touches phase:(UITouchPhase)phaseToSave {
- (NSSet *)copyClearedTouches:(NSSet *)touches phase:(UITouchPhase)phaseToSave {
NSMutableSet *cleared = [touches mutableCopy];

for (UITouch *touch in touches) {
Expand Down
3 changes: 0 additions & 3 deletions platform/iphone/view_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
@interface ViewController : UIViewController <GKGameCenterControllerDelegate> {
};

- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)p_orientation;

- (void)didReceiveMemoryWarning;

- (void)viewDidLoad;
Expand Down
17 changes: 8 additions & 9 deletions platform/iphone/view_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
int add_path(int p_argc, char **p_args) {

NSString *str = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"godot_path"];
if (!str)
if (!str) {
return p_argc;
}

p_args[p_argc++] = "--path";
[str retain]; // memory leak lol (maybe make it static here and delete it in ViewController destructor? @todo
p_args[p_argc++] = (char *)[str cString];
p_args[p_argc++] = (char *)"--path";
p_args[p_argc++] = (char *)[str cStringUsingEncoding:NSUTF8StringEncoding];
p_args[p_argc] = NULL;

return p_argc;
Expand All @@ -60,12 +60,11 @@ int add_cmdline(int p_argc, char **p_args) {
return p_argc;

for (int i = 0; i < [arr count]; i++) {

NSString *str = [arr objectAtIndex:i];
if (!str)
if (!str) {
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;
Expand All @@ -81,7 +80,7 @@ @interface ViewController ()
@implementation ViewController

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];
printf("*********** did receive memory warning!\n");
};

Expand Down