症状:
当消息框弹出后,按Home键切出来,再重新进程序,然后点消息框上的取消按钮,当消息框关闭后,程序偶尔(只是偶尔)会报错,
有时是EXC_BAD_INSTRUCTION 有时是EXC_BAD_ACCESS 感觉像是堆栈坏了 导致返回的时候乱执行 ? 而很多时候又不会报错,很正常
我是在一个schedule定时器回调中调用MessageBox_Mz(只会调用一次不会反复调用)的,iOS部分实现代码如下:
// 模态消息框代理
@interface ModalDelegate_Mz : NSObject
{
bool mRunLoop;
}
- (void)showModalAlert:(UIAlertView *)alertView;
@end // ModalDelegate_Mz
@implementation ModalDelegate_Mz
-
(void)showModalAlert:(UIAlertView *)alertView
{
retain];
setDelegate:self];
show];mRunLoop = true;
while (mRunLoop)
{
NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:NSDate distantFuture]];
// runMode:NSDefaultRunLoopMode beforeDate:];
}setDelegate:nil];
release];
} -
(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
mRunLoop = false;
}
@end // ModalDelegate_Mz
void MessageBox_Mz(const char * msg, const char * title)
{
ModalDelegate_Mz * modalDelegate = ModalDelegate_Mz alloc] init];
NSString * tmpTitle = (title) ? NSString stringWithUTF8String : title] : nil;
NSString * tmpMsg = (msg) ? NSString stringWithUTF8String : msg] : nil;
UIAlertView * messageBox = UIAlertView alloc] initWithTitle: tmpTitle
message: tmpMsg
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
//;
showModalAlert:messageBox];
//开始怀疑是这两句引起的,注释掉一样会报错
//;
//;
}