comparison ios/dw.m @ 2616:a256caa5034c

iOS: Fix a context menu related crash by removing autorelease from DWMenuItem. Something is stil not quite right here, the popup menu lingering from a long touch on another DWRender and causing the popup to show on a DWRender that doesn't respond to the popup. However the crash was critical and the current misbehavior is not. Also check the pointer passed to dw_menu_popup().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 23 Jul 2021 19:26:01 +0000
parents ac51cbdcfbe5
children 07c504257e42
comparison
equal deleted inserted replaced
2615:ac51cbdcfbe5 2616:a256caa5034c
7659 * x: X coordinate. 7659 * x: X coordinate.
7660 * y: Y coordinate. 7660 * y: Y coordinate.
7661 */ 7661 */
7662 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y) 7662 void API dw_menu_popup(HMENUI *menu, HWND parent, int x, int y)
7663 { 7663 {
7664 DWMenu *thismenu = (DWMenu *)*menu; 7664 if(menu)
7665 id object = parent; 7665 {
7666 DWWindow *window = [object isMemberOfClass:[DWWindow class]] ? object : (DWWindow *)[object window]; 7666 DWMenu *thismenu = (DWMenu *)*menu;
7667 [thismenu autorelease]; 7667 id object = parent;
7668 [window setPopupMenu:thismenu]; 7668 DWWindow *window = [object isMemberOfClass:[DWWindow class]] ? object : (DWWindow *)[object window];
7669 *menu = nil; 7669 [window setPopupMenu:thismenu];
7670 *menu = nil;
7671 }
7670 } 7672 }
7671 7673
7672 char _dw_removetilde(char *dest, const char *src) 7674 char _dw_removetilde(char *dest, const char *src)
7673 { 7675 {
7674 int z, cur=0; 7676 int z, cur=0;
7718 accel[1] = 0; 7720 accel[1] = 0;
7719 7721
7720 nstr = [NSString stringWithUTF8String:newtitle]; 7722 nstr = [NSString stringWithUTF8String:newtitle];
7721 free(newtitle); 7723 free(newtitle);
7722 7724
7723 item = [[DWMenuItem actionWithTitle:nstr image:nil identifier:nil 7725 item = [DWMenuItem actionWithTitle:nstr image:nil identifier:nil
7724 handler:^(__kindof UIAction * _Nonnull action) { 7726 handler:^(__kindof UIAction * _Nonnull action) {
7725 [DWObj menuHandler:item]; 7727 [DWObj menuHandler:item];
7726 }] autorelease]; 7728 }];
7727 /* Don't set the tag if the ID is 0 or -1 */ 7729 /* Don't set the tag if the ID is 0 or -1 */
7728 if(itemid != DW_MENU_AUTO && itemid != DW_MENU_POPUP) 7730 if(itemid != DW_MENU_AUTO && itemid != DW_MENU_POPUP)
7729 [item setTag:itemid]; 7731 [item setTag:itemid];
7730 [menu addItem:item]; 7732 [menu addItem:item];
7731 7733