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

Crash viewWillTransitionToSize #62

Open
NikKovIos opened this issue Mar 4, 2019 · 9 comments · May be fixed by #63
Open

Crash viewWillTransitionToSize #62

NikKovIos opened this issue Mar 4, 2019 · 9 comments · May be fixed by #63

Comments

@NikKovIos
Copy link

It's better to add weakSelf and strongSelf references to prevent crash in this method.

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

      __weak typeof(self) weakSelf = self;
   dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:coordinator.transitionDuration animations:^{
            [self setNeedsStatusBarAppearanceUpdate];
            [self.alertView layoutValidateWithSize:size];
        }];
    });
}
@halpz
Copy link

halpz commented Mar 14, 2019

im g etting the same crashes here too: many crash reports saying the same thing:

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x1ea35fd70 objc_msgSend + 16
1  &&&&&&                        0x1043de134 __76-[LGAlertViewController viewWillTransitionToSize:withTransitionCoordinator:]_block_invoke (LGAlertViewController.m:59)
2  libdispatch.dylib              0x1eabb26c8 _dispatch_call_block_and_release + 24
3  libdispatch.dylib              0x1eabb3484 _dispatch_client_callout + 16
4  libdispatch.dylib              0x1eab5f9ec _dispatch_main_queue_callback_4CF$VARIANT$mp + 1068
5  CoreFoundation                 0x1eb1091bc __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
6  CoreFoundation                 0x1eb104084 __CFRunLoopRun + 1964
7  CoreFoundation                 0x1eb1035b8 CFRunLoopRunSpecific + 436
8  GraphicsServices               0x1ed377584 GSEventRunModal + 100
9  UIKitCore                      0x217507558 UIApplicationMain + 212
10 &&&&&&                        0x1044d2058 main (main.m:14)
11 libdyld.dylib                  0x1eabc3b94 start + 4

@halpz
Copy link

halpz commented Mar 14, 2019

I've tried this without crashes so far:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
	[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

	[[NSOperationQueue mainQueue] addOperationWithBlock:^{
	    __weak typeof(self) weakSelf = self;
	    [UIView animateWithDuration:coordinator.transitionDuration animations:^{
	        [weakSelf setNeedsStatusBarAppearanceUpdate];
	        [weakSelf.alertView layoutValidateWithSize:size];
	    }];
	}];

}

@NikKovIos
Copy link
Author

Updated PR with your fix, because mine still crashing.

@halpz
Copy link

halpz commented Mar 19, 2019

here's my overly- cautious fix

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    if (coordinator) {
        [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    }

    @try {
        
        [[NSOperationQueue mainQueue] addOperationWithBlock:^{
            __weak typeof(self) weakSelf = self;
            [UIView animateWithDuration:coordinator.transitionDuration animations:^{
                if (weakSelf) {
                    if ([weakSelf respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
                        [weakSelf setNeedsStatusBarAppearanceUpdate];
                    }
                    if (weakSelf.alertView) {
                        [weakSelf.alertView layoutValidateWithSize:size];
                    }
                }
            }];
        }];
        
    } @catch (NSException *exception) {
        //
    } @finally {
        //
    }
    
}

@NikKovIos
Copy link
Author

Done, you can use pod "LGAlertView", :git => 'https://github.com/NikKovIos/LGAlertView' with this fixup.

@NikKovIos
Copy link
Author

Still have crashes..

@NikKovIos
Copy link
Author

The bug occures when the app orientation is portrait, but the status bar orientation is landscape.

@vovnit
Copy link

vovnit commented Aug 12, 2019

The problem is -[_UIViewControllerOneToOneTransitionContext _duration]: message sent to deallocated instance 0x1065261f0. I believe this "deallocated instance" is transitionDuration, because when I'm trying to do
po coordinator.transitionDuration
I'm getting
error: property 'transitionDuration' not found on object of type 'id'
Meanwhile, self and coordinator are perfectly fine.

I don't know reason behind it, so currently I'm using easiest workaround – hardcoded duration. Feel free to use pod 'LGAlertView', :git => 'https://github.com/vovnit/LGAlertView.git' with this "fix" forked from @NikKovIos if you want.

@halpz
Copy link

halpz commented Feb 6, 2020

hard coded duration should fix this - I put '0.3' where 'coordinator.transitionDuration' was

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants