From 9cbf7ed62a2000e9ff661d91e4d1bf899428d8f7 Mon Sep 17 00:00:00 2001 From: meancoot Date: Mon, 30 Dec 2013 18:20:31 -0500 Subject: [PATCH] =?UTF-8?q?(iOS)=20Don=E2=80=99t=20crash=20when=20closing?= =?UTF-8?q?=20an=20action=20sheet=20created=20by=20the=20RunActionSheet=20?= =?UTF-8?q?function.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apple/iOS/menu.m | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apple/iOS/menu.m b/apple/iOS/menu.m index a045a36204..d719b38b65 100644 --- a/apple/iOS/menu.m +++ b/apple/iOS/menu.m @@ -24,10 +24,11 @@ /* buttons pulled from a RetroArch */ /* string_list structure. */ /*********************************************/ +static const void* const associated_delegate_key = &associated_delegate_key; + typedef void (^RAActionSheetCallback)(UIActionSheet*, NSInteger); @interface RARunActionSheetDelegate : NSObject -@property (nonatomic, retain) RARunActionSheetDelegate* me; @property (nonatomic, copy) RAActionSheetCallback callbackBlock; @end @@ -36,10 +37,7 @@ typedef void (^RAActionSheetCallback)(UIActionSheet*, NSInteger); - (id)initWithCallbackBlock:(RAActionSheetCallback)callback { if ((self = [super init])) - { - _me = self; _callbackBlock = callback; - } return self; } @@ -47,23 +45,25 @@ typedef void (^RAActionSheetCallback)(UIActionSheet*, NSInteger); { if (self.callbackBlock) self.callbackBlock(actionSheet, buttonIndex); - self.me = nil; } @end static void RunActionSheet(const char* title, const struct string_list* items, UIView* parent, RAActionSheetCallback callback) { + RARunActionSheetDelegate* delegate = [[RARunActionSheetDelegate alloc] initWithCallbackBlock:callback]; + UIActionSheet* actionSheet = [UIActionSheet new]; actionSheet.title = BOXSTRING(title); - actionSheet.delegate = (id)[[RARunActionSheetDelegate alloc] initWithCallbackBlock:callback]; + actionSheet.delegate = delegate; for (int i = 0; i < items->size; i ++) - { [actionSheet addButtonWithTitle:BOXSTRING(items->elems[i].data)]; - } actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"]; + + objc_setAssociatedObject(actionSheet, associated_delegate_key, delegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + [actionSheet showInView:parent]; }