BlocksKit / BlocksKit

The Objective-C block utilities you always wish you had.
MIT License
6.89k stars 1.26k forks source link

UIAlertView causes NSInvalidArgumentException (incompatible signatures) #260

Closed myster-t closed 8 years ago

myster-t commented 10 years ago

I'm experiencing an intermittent bug when showing UIAlertView's through blockskit's shortcut bk_showAlertViewWithTitle:.... The crash:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempted to create block invocation with incompatible signatures'

If you comment out the lines 177-179 in A2BlockInvocation.m, then everything works fine. It seems to be more prevalent in older generation phones (iphone 4/4s, iphone 5...). Could this have something to do with how isSignature:compatibleWithSignature: works on 32 bit devices vs 64 bit devices?

As for whether or not the block signatures are actually incorrect... I've triple checked every single one and they're correct.

segiddins commented 10 years ago

What version of BlocksKit are you running?

myster-t commented 10 years ago

The latest through cocoapods. 2.2.5 I believe.

vani2 commented 10 years ago

I have the same issue, I suspect it's not depend on 32 or 64 bit devices. I got this only in swift. The problem is in the last argument of handler block. I tried to use NSInteger or Int(!) argument with no success.

andrebraga commented 10 years ago

++

andrebraga commented 10 years ago

Quick and filthy hack to make it work, by special casing this situation and this situation alone. Not written with brevity in mind but to show the special casing step by step:

    for (NSUInteger i = 2; i < numberOfArguments; i++) {
        const char methodArgument = [methodSignature getArgumentTypeAtIndex:i][0];
        const char blockArgument = [blockSignature getArgumentTypeAtIndex:i - 1][0];
        if (methodArgument != blockArgument) {
            if (@encode(int)[0] == methodArgument && @encode(long)[0] == blockArgument) {
                return YES;
            }
            return NO;
        }
    }
myster-t commented 9 years ago

Thanks @zwaldowski for addressing this. I haven't moved to swift yet. Does your fix also work for obj-c?

mpurland commented 9 years ago

@zwaldowski I have run into this issue as well. Will the commits on next branch including the fix for #260 be available on master soon?

zwaldowski commented 9 years ago

Yes, absolutely. We wanted to get a few things into the next branch first.

eikebartels commented 9 years ago

Any news on this side? The issue still exist

hiltonc commented 9 years ago

Just ran into this.