Post

Replies

Boosts

Views

Activity

Reply to EXC_BAD_INSTRUCTION on dispatch_sync()
This is the whole code of that function to show the str in text view. Memo1 is the textview outlet. ERROR happens calling this function. -(void)showMeg:(NSString *)str { dispatch_sync(dispatch_get_main_queue(), ^{ [[[Memo1 textStorage] mutableString]appendString:[NSString stringWithFormat:@"%@", str]]; [Memo1 scrollRangeToVisible:NSMakeRange(Memo1.string.length, 0)];//auto scroll down }); } Someone suggested me change dispatch_sync to dispatch_async or close the dispatch_sync with a dispatch_async like following. Then the error, EXC_BAD..., disappeared but I found the order of the strings showed on textview is wrong few times, not often. For example, I'd like to show 0x01, 0x02, 0x03. But it shows 0x01, 0x03, 0x02.     dispatch_async(dispatch_get_global_queue(0, 0), ^{         dispatch_sync(dispatch_get_main_queue(), ^{         [[[Memo1 textStorage] mutableString]appendString:[NSString stringWithFormat:@"%@", str]];         [Memo1 scrollRangeToVisible:NSMakeRange(Memo1.string.length, 0)];//auto scroll down         });     });
Topic: Programming Languages SubTopic: General Tags:
Jun ’22
Reply to EXC_BAD_INSTRUCTION on dispatch_sync()
This is the whole code of that function to show the str in text view. Memo1 is the textview outlet. ERROR happens calling this function. -(void)showMeg:(NSString *)str { dispatch_sync(dispatch_get_main_queue(), ^{ [[[Memo1 textStorage] mutableString]appendString:[NSString stringWithFormat:@"%@", str]]; [Memo1 scrollRangeToVisible:NSMakeRange(Memo1.string.length, 0)];//auto scroll down }); } Someone suggested me change dispatch_sync to dispatch_async or close the dispatch_sync with a dispatch_async like following. Then the error, EXC_BAD..., disappeared but I found the order of the strings showed on textview is wrong few times, not often. For example, I'd like to show 0x01, 0x02, 0x03. But it shows 0x01, 0x03, 0x02.     dispatch_async(dispatch_get_global_queue(0, 0), ^{         dispatch_sync(dispatch_get_main_queue(), ^{         [[[Memo1 textStorage] mutableString]appendString:[NSString stringWithFormat:@"%@", str]];         [Memo1 scrollRangeToVisible:NSMakeRange(Memo1.string.length, 0)];//auto scroll down         });     });
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Thread1: EXE_BAD_INSTRUTION. How does this error show up, I just removed some line that are not important?
I found the bug. This error solved. An array only has one object but I call the 2nd index of that array, so it caused the error.
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
May ’22
Reply to Show-message function got error: Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
Sorry, the second section was copied the same code. The following is what I actually called.
Replies
Boosts
Views
Activity
May ’22