Mercurial > dwindows
comparison mac/dw.m @ 2952:7d12fd73ef54
Mac/iOS: Implement failsafe for dw_window_s/get_data() so we don't crash.
Some objects don't support setting data on them, so if called on one of
those objects, silently fail in Release mode and give a warning in DEBUG.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 04 Jan 2023 10:28:20 +0000 |
parents | 0577a97fe36d |
children | fffb4904c90b |
comparison
equal
deleted
inserted
replaced
2951:34d16576c156 | 2952:7d12fd73ef54 |
---|---|
11636 else if([object isMemberOfClass:[NSBox class]]) | 11636 else if([object isMemberOfClass:[NSBox class]]) |
11637 { | 11637 { |
11638 NSBox *box = window; | 11638 NSBox *box = window; |
11639 object = [box contentView]; | 11639 object = [box contentView]; |
11640 } | 11640 } |
11641 /* Failsafe so we don't crash */ | |
11642 if(![object respondsToSelector:NSSelectorFromString(@"userdata")]) | |
11643 { | |
11644 #ifdef DEBUG | |
11645 NSLog(@"WARNING: Object class %@ does not support dw_window_set_data()\n", [object className]); | |
11646 #endif | |
11647 return; | |
11648 } | |
11641 WindowData *blah = (WindowData *)[object userdata]; | 11649 WindowData *blah = (WindowData *)[object userdata]; |
11642 | 11650 |
11643 if(!blah) | 11651 if(!blah) |
11644 { | 11652 { |
11645 if(!dataname) | 11653 if(!dataname) |
11682 } | 11690 } |
11683 else if([object isMemberOfClass:[NSBox class]]) | 11691 else if([object isMemberOfClass:[NSBox class]]) |
11684 { | 11692 { |
11685 NSBox *box = window; | 11693 NSBox *box = window; |
11686 object = [box contentView]; | 11694 object = [box contentView]; |
11695 } | |
11696 /* Failsafe so we don't crash */ | |
11697 if(![object respondsToSelector:NSSelectorFromString(@"userdata")]) | |
11698 { | |
11699 #ifdef DEBUG | |
11700 NSLog(@"WARNING: Object class %@ does not support dw_window_get_data()\n", [object className]); | |
11701 #endif | |
11702 return NULL; | |
11687 } | 11703 } |
11688 WindowData *blah = (WindowData *)[object userdata]; | 11704 WindowData *blah = (WindowData *)[object userdata]; |
11689 | 11705 |
11690 if(blah && blah->root && dataname) | 11706 if(blah && blah->root && dataname) |
11691 { | 11707 { |