IMP methodForSelector EXC_BAD_ACCESS crash - ios

I have received a couple of crash reports, and the only thing I can see in common is that they are both iPhone 5. I can't reproduce the crash on iPhone 5s or 6 so I I assumed it was a 64/32 bit issue. However the code also runs fine on an iPhone 4s running iOS 7.
The crash is happening on the last line here:
IMP imp = [self.delegate methodForSelector:aSelector];
id (*func)(id, SEL, id) = (void *)imp;
func(self.delegate, aSelector, self);
To be perfectly honest, I don't understand these 3 lines of code. I found them to overcome a compiler warning may cause a leak because its selector is unknown when using [self.delegate performSelector:aSelector withObject:self];
When I push an update using performSelector it doesn't crash.
I need to pass an argument of self along with the selector which is why I used IMP and added self as the third argument which is how I read it should be done.
The actual crash log doesn't reveal much:
Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x00000100 Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x30ca26b8 objc_retain + 7
1 Timeout 0x0009e2a1 __50-[BaseOperation finishedSuccessfullyWithSelector:]_block_invoke_2 (BaseOperation.m:47)
2 libdispatch.dylib 0x311e87bb
_dispatch_call_block_and_release + 10
3 libdispatch.dylib 0x311efe8b _dispatch_after_timer_callback + 66
4 libdispatch.dylib 0x311e87a7 _dispatch_client_callout + 22
5 libdispatch.dylib 0x311f9253 _dispatch_source_latch_and_call + 626
6 libdispatch.dylib 0x311ea2ed _dispatch_source_invoke + 212
7 libdispatch.dylib 0x311ebe1f _dispatch_main_queue_callback_4CF + 330
8 CoreFoundation 0x234a39d1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
9 CoreFoundation 0x234a20d1 __CFRunLoopRun + 1512
10 CoreFoundation 0x233f0211 CFRunLoopRunSpecific + 476
11 CoreFoundation 0x233f0023 CFRunLoopRunInMode + 106
12 GraphicsServices 0x2a7e90a9 GSEventRunModal + 136
13 UIKit 0x269fc1d1 UIApplicationMain + 1440
14 Timeout 0x000a265b main (main.m:14)
Is there anyone that can shed some light on this?
Thanks
EDIT ----
I am now also seeing crashes on iPad 3 (iOS 8.1.2) & iPhone 5 (iOS 8.1). Yet still can't reproduce it myself, I also tried an iPod (iOS 8.1) and iPad mini retina (iOS 8.1.3). This is really bugging me (Pun intended).
EDIT 2 ----
I've added some Crashlytics logs to log self.delegate self imp & func and they all appear to be fine! So why does the very next line crash?
0 | 00:01:33:665 | $ __50-[BaseOperation finishedSuccessfullyWithSelector:]_block_invoke_2 : connectComplete:
1 | 00:01:33:665 | $ delegate: <BaseMenuViewController: 0x17e5e780>
2 | 00:01:33:666 | $ self: <ConnectOperation_Virgin: 0x1902a490>{name = '(null)'}
3 | 00:01:33:667 | $ imp: 0xaa345
4 | 00:01:33:667 | $ func: 0xaa345

I had the same problem, working code 6 months ago now crashes, fixed it with those changes :
//old code
IMP imp = [_target methodForSelector:_action];
id (*func)(id, SEL, id) = (void *)imp;
func(_target, _action, params);
//replaced by
void (*imp)(id, SEL, id) = (void(*)(id,SEL,id))[_target methodForSelector:_action];
if( imp ) imp(_target, _action, params);

Related

Xcode build running on device but failing on simultor

I'm using CocoaPods with a React Native app. I've had various errors when running builds in the Xcode simulator. I don't have issues running it on my device. Here's one that I get when I have breakpoints enabled:
- (void)ensureOnJavaScriptThread:(dispatch_block_t)block
{
RCTAssert(_jsThread, #"This method must not be called before the JS thread is created");
The error here is green (yet breaking, thanks Xcode) and it says com.facebook.react.JavaScript (9): breakpoint 1.2
I get two errors when I disable breakpoints, this is one:
void Instance::loadApplication(std::unique_ptr<RAMBundleRegistry> bundleRegistry,
std::unique_ptr<const JSBigString> string,
std::string sourceURL) {
callback_->incrementPendingJSCalls();
SystraceSection s("Instance::loadApplication", "sourceURL",
sourceURL);
nativeToJsBridge_->loadApplication(std::move(bundleRegistry), std::move(string),
std::move(sourceURL));
}
with the red error on the callback_-> line reading EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
the second is this a signal SIGABRT error from this code:
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
I think i've fixed that issue before by enabling zombies. When I do that, I see this in the console:
2018-07-11 16:56:08.326 [info][tid:main][RCTRootView.m:293] Running application Mapp ({
initialProps = {
};
rootTag = 11;
})
=================================================================
Main Thread Checker: UI API called on a background thread: -[UIApplication setNetworkActivityIndicatorVisible:]
PID: 34682, TID: 5546845, Thread name: (none), Queue name: com.mixpanel.20e6d2c2b6c431dfecfdfaa100ec0a11.0x7fa94db06940.network, QoS: 0
Backtrace:
4 Mapp 0x0000000103a31dd9 -[MPNetwork updateNetworkActivityIndicator:] + 121
5 Mapp 0x0000000103a2ec09 -[MPNetwork flushQueue:endpoint:] + 985
6 Mapp 0x0000000103a2e7b0 -[MPNetwork flushEventQueue:] + 64
7 Mapp 0x0000000103a10418 __32-[Mixpanel flushWithCompletion:]_block_invoke + 312
8 libdispatch.dylib 0x000000010e3f47ab _dispatch_call_block_and_release + 12
9 libdispatch.dylib 0x000000010e3f57ec _dispatch_client_callout + 8
10 libdispatch.dylib 0x000000010e3fdbe5 _dispatch_queue_serial_drain + 1305
11 libdispatch.dylib 0x000000010e3fe4fa _dispatch_queue_invoke + 328
12 libdispatch.dylib 0x000000010e3fa344 _dispatch_queue_override_invoke + 726
13 libdispatch.dylib 0x000000010e40136c _dispatch_root_queue_drain + 664
14 libdispatch.dylib 0x000000010e401076 _dispatch_worker_thread3 + 132
15 libsystem_pthread.dylib 0x000000010e920169 _pthread_wqthread + 1387
16 libsystem_pthread.dylib 0x000000010e91fbe9 start_wqthread + 13
This to me is unreadable. I don't understand what's wrong. Reminder: this build runs without breaking errors on my device, even when breakpoints are enabled. Is this something I should worry about? Please help!
Because in your code UI API called on a background thread. So please disable the Main Thread Checker of xcode. it will work.
Edit Scheme --- > Diagonstics --- > Runtime API Checking ---> Main
Thread Checker (un-check this setting)
Note: Always update the UI inside below method on a background thread
Or
Put your [UIApplication setNetworkActivityIndicatorVisible:] Method inside DispatchQueue.main.async
DispatchQueue.main.async { // Correct
UIApplication.shared.isNetworkActivityIndicatorVisible = true // in swift 4
[UIApplication setNetworkActivityIndicatorVisible:]// in objective-C
}
https://developer.apple.com/documentation/code_diagnostics/main_thread_checker

Parse (iOS): User cannot be deleted unless they have been authenticated via logIn or signUp

I'm experimenting this error only when I'm using saveEventually (iOS 8), and the Object I'm modifying is not PFUser:
var myObj = PFObject(className: "MyClass")
myObj["val"] = 100
myObj.saveEventually()
<- Crash with the error:
'NSInternalInconsistencyException', reason: 'User cannot be deleted unless they have been authenticated via logIn or signUp'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107182f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000109510bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000107182e6d +[NSException raise:format:] + 205
3 AAA 0x0000000105a7a85c -[PFUser(Private) checkDeleteParams] + 71
4 AAA 0x0000000105a3b6e9 -[PFObject(Private) _constructDeleteCommand:sessionToken:] + 81
5 AAA 0x0000000105a45c5c -[PFPinningEventuallyQueue _commandWithIdentifier:error:] + 147
6 AAA 0x0000000105a71b7b -[PFEventuallyQueue _runCommandsWithRetriesCount:] + 951
7 libdispatch.dylib 0x0000000109cb57f4 _dispatch_client_callout + 8
8 libdispatch.dylib 0x0000000109cac09a _dispatch_source_latch_and_call + 852
9 libdispatch.dylib 0x0000000109ca46d2 _dispatch_source_invoke + 412
10 libdispatch.dylib 0x0000000109c9d9ae _dispatch_queue_drain + 1045
11 libdispatch.dylib 0x0000000109c9d432 _dispatch_queue_invoke + 235
12 libdispatch.dylib 0x0000000109c9ffc1 _dispatch_root_queue_drain + 685
13 libdispatch.dylib 0x0000000109ca15d9 _dispatch_worker_thread3 + 111
14 libsystem_pthread.dylib 0x000000010a039637 _pthread_wqthread + 729
15 libsystem_pthread.dylib 0x000000010a03740d start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The same if I'm using:
myObj.saveEventually{(success: Bool!, error: NSError!) -> Void in
The error is not nil neither has something, saveEventually is just crashing.
But if I use just saveInBackgroundWithBlock or save() is working just fine...
any ideas?
I'm completely sure was working yesterday, I'm using saveEventually for almost everything in my project, but the error doesnt make sense for me, because I'm not mofifying a PFUser. Using the last SDK.
Thanks in advance!
OK...the solution was quite simple:
In the simulator: Reset Content & Settings
In XCode: Product -> Clean && Build
Close Xcode
rm -rf ~/library/Developer/Xcode/DerivedData/
Open XCode
Definitely the error looked like a bug or something like that, but probably some Cache or ...whatever... was around somewhere.
Hope this helps
Cheers

iOS crash, EXC_BREAKPOINT, No clue with Xcode 6.1

I am usually able to solve the crashes but here I have not clue from where it comes from.
I use parse, and I am simply doing a request in background with a completion block.
The app crashes at a simple if condition and I can barely identify anything, no way to print description, ...
Do you have any idea ? A starting point ? anything ?
Xcode 6.1 is really strange, it seems that the debugger is buggy.
Here is the log of the crash :
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x000000019657a964 __kill + 8
1 MyAPP 0x00000001001f2b70 0x10009c000 + 1403760
2 libsystem_platform.dylib 0x0000000196610958 _sigtramp + 64
3 MyAPP 0x00000001001318cc 0x10009c000 + 612556
4 MyAPP 0x000000010013797c 0x10009c000 + 637308
5 MyAPP 0x0000000100135fc4 0x10009c000 + 630724
6 MyAPP 0x00000001002e408c 0x10009c000 + 2392204
7 MyAPP 0x00000001001dbf78 0x10009c000 + 1310584
8 libdispatch.dylib 0x00000001964393a8 _dispatch_call_block_and_release + 20
9 libdispatch.dylib 0x0000000196439368 _dispatch_client_callout + 12
10 libdispatch.dylib 0x000000019643d97c _dispatch_main_queue_callback_4CF + 928
11 CoreFoundation 0x000000018566d69c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
12 CoreFoundation 0x000000018566b744 __CFRunLoopRun + 1488
13 CoreFoundation 0x00000001855991f0 CFRunLoopRunSpecific + 392
14 GraphicsServices 0x000000018e7275a0 GSEventRunModal + 164
15 UIKit 0x0000000189eca780 UIApplicationMain + 1484
16 Shuff 0x0000000100129474 0x10009c000 + 578676
17 libdyld.dylib 0x0000000196462a04 start + 0
And here is a sample of the iOS code :
var query = PFQuery(className: "_User")
query.whereKey("facebookId", containedIn: ids)
query.findObjectsInBackgroundWithBlock(){
results, error in
if var resultsvar = results? {
self.functionToCall(resultsvar)
}
}
and the functionToCall crashes.
Maybe this can help :
0 0x00000001001679c8 in specialization of Swift._ArrayBuffer._nonNative.getter : Swift.Optional [inlined] ()
Yes !!! The debugger is not working well ! I was able to find the correct lines by doing the following : put a breakpoint at the start of where you think the app crashes, go step by step, remember the lowest line you've gone through. Even if the debugger crashes on another the line, the line you are looking for is probably the lowest one.
This is just a guess but I was working on something similar and I think you need to change this code to:
query.findObjectsInBackgroundWithBlock(){
results?, error? in
if var resultsvar = results {
self.functionToCall(resultsvar)
}
}
Note that I made both results and error optional. In my case I was providing a block defined in Obj-C, and in Obj-C these objects can legally be == nil. So I think you have to define them as optionals in Swift.

CoreData MagicalRecord save methods crashes on iPhone5

Currently I'm working with MagicalRecord v2.3.0-beta.3 commit:d18e74fe435359238b9593c03e41c1ee0baa0b78 framework. I'm getting 1 a crash log (from Crashlytics) on iPhone 5 all the time. App is still in development. The crash log looks like below:
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x38eee626 objc_msgSend + 5
1 Foundation 0x2f06d02d -[NSError dealloc] + 60
2 libobjc.A.dylib 0x38ef3b6b objc_object::sidetable_release(bool) + 174
3 libobjc.A.dylib 0x38ef40d3 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 358
4 CoreFoundation 0x2e67d481 _CFAutoreleasePoolPop + 16
5 Foundation 0x2f0778e3 -[NSAutoreleasePool drain] + 122
6 CoreData 0x2e4bdfbf -[NSManagedObjectContext save:] + 942
7 MyApp 0x00162f9f __70-[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:]_block_invoke15 (NSManagedObjectContext+MagicalSaves.m:82) // here app crashes
8 CoreData 0x2e5219cd developerSubmittedBlockToNSManagedObjectContextPerform + 88
9 CoreData 0x2e521b13 -[NSManagedObjectContext performBlockAndWait:] + 114
10 MyApp 0x00162e51 -[NSManagedObjectContext(MagicalSaves) MR_saveWithOptions:completion:] (NSManagedObjectContext+MagicalSaves.m:116)
11 MyApp 0x000a2b0d -[SPNCoreDataHandler parseAndSaveDictionaryReturnOperationArray:withSaving:] (SPNCoreDataHandler.m:70)
12 MyApp 0x00078f21 __102-[SPNApiHandler getAllDataWithDownloadingSuccessBlock:savingSuccessBlock:downloadStatus:failureBlock:]_block_invoke (SPNApiHandler.m:69)
13 MyApp 0x000795b9 __66-[SPNApiHandler sendGetRequestWithPath:successBlock:failureBlock:]_block_invoke (SPNApiHandler.m:174)
14 libdispatch.dylib 0x393cdd53 _dispatch_call_block_and_release + 10
15 libdispatch.dylib 0x393cdd3f _dispatch_client_callout + 22
16 libdispatch.dylib 0x393d06c3 _dispatch_main_queue_callback_4CF + 278
17 CoreFoundation 0x2e714641 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
18 CoreFoundation 0x2e712f0d __CFRunLoopRun + 1308
19 CoreFoundation 0x2e67d729 CFRunLoopRunSpecific + 524
20 CoreFoundation 0x2e67d50b CFRunLoopRunInMode + 106
21 GraphicsServices 0x335ec6d3 GSEventRunModal + 138
22 UIKit 0x30fde871 UIApplicationMain + 1136
23 MyApp 0x0009c347 main (main.m:16)
And here's code which I wrote:
NOTE: I removed some parts of this method for sake of readability (that's why method returns void instead of NSArray).
- (NSArray *)parseAndSaveDictionaryReturnOperationArray:(NSDictionary *)dictionary withSaving:(BOOL)saveSynchrounously {
[self truncateAll]; //method which removes all entries in coreData
/* methods below creates entities from array given in dictionary
using [NSManagedObject MR_createEntity] method
e.g. Contact *contact = [Contact MR_createEntity]; */
[self saveContacts:dictionary[#"contact"]];
[self savePeople:dictionary[#"person"]];
[self saveBuildings:dictionary[#"place"]];
[self saveSessions:dictionary[#"session"]];
[self saveLectures:dictionary[#"program"]];
[self savePartners:dictionary[#"partners"]];
[self saveSponsors:dictionary[#"sponsors"]];
[self saveExhibitorsPlans:dictionary[#"exhibitorplan"]];
[self saveMeetingPlans:dictionary[#"meetingplan"]];
[self saveOrganizationalInformation:dictionary[#"info"]];
[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
//continue executing method...
}
I tried also to use [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreWithCompletion:] method but it crashes too.
In other Stackoverflow question someone suggested, that crash can be caused by deleting, creating and saving to many entities at once. In my case it's around 200 deleted entities + 200 new ones. Can it cause crash?
On other devices (iPhone 4s, iPhone 5s, iPad 2, iPad4, iPad mini) it works fine. Any ideas what I'm doing wrong?
Finally I found out what was going on. Tester didn't delete and install an app as I told. Crash appears because DB schema changed. Maybe I should start to think about DB versioning during development to avoid those kind of issues.
Thanks anyone for answers.

iOS8 Beta 3 SpriteKit exc_bad_acces when running on device

I am currently developing an app in Spritekit with Swift. The app worked perfectly on device and in the simulator until I updated to Xcode 6 Beata 3 and iOS 8 Beta 3. When I run the app in the simulator everything still works perfect. But running the app on the device causes a exc_bad_acces when I create a SKTextureAtlas. Is anyone facing a similar problem or can anyone help me how to solve this.
I've alredy tried to run it on a device with iOS8 Beta 2 but I run into the same error here. I also deleted the app but that also didn't solve my problem when running the app on a device.
Here is the place it crashes:
var atlas = SKTextureAtlas(named: "ImageSet")
and that is the log from the device:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0xfffffffc
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libswift_stdlib_core.dylib 0x003a737e 0x286000 + 1184638
1 My Game 0x000f6900 Swift._doesImplicitlyUnwrappedOptionalHaveValue <A>(#inout A!) -> Builtin.Int1 (ComputerPlayer.swift:0)
2 My Game 0x0011c0a0 #!objc ObjectiveC.SKTextureAtlas.__allocating_init (ObjectiveC.SKTextureAtlas.Type)(named : Swift.String!) -> ObjectiveC.SKTextureAtlas (SpriteKit-1CMA4777KYE20.pcm:1)
3 My Game 0x0010e010 My_Game.GameScene.didMoveToView (My_Game.GameScene)(ObjectiveC.SKView) -> () (GameScene.swift:132)
4 My Game 0x00113218 #objc My_Game.GameScene.didMoveToView (My_Game.GameScene)(ObjectiveC.SKView) -> () (GameScene.swift:0)
5 SpriteKit 0x2e6d6340 SKGenerateNormalMap + 65680
6 SpriteKit 0x2e6f02de SKGenerateNormalMap + 172078
7 My Game 0x0011fd38 My_Game.GameViewController.viewWillLayoutSubviews (My_Game.GameViewController)() -> () (GameViewController.swift:71)
8 My Game 0x00121468 #objc My_Game.GameViewController.viewWillLayoutSubviews (My_Game.GameViewController)() -> () (GameViewController.swift:0)
9 UIKit 0x2e844266 0x2e837000 + 53862
10 QuartzCore 0x2e2804c0 CABackingStoreGetTypeID + 892
11 QuartzCore 0x2e27bea0 CARenderServerGetServerPort + 5364
12 QuartzCore 0x2e27bd28 CARenderServerGetServerPort + 4988
13 QuartzCore 0x2e27b70c CARenderServerGetServerPort + 3424
14 QuartzCore 0x2e27b510 CARenderServerGetServerPort + 2916
15 UIKit 0x2eaa6cf8 _UIApplicationIsExtension + 4936
16 UIKit 0x2eaa79e0 _UIApplicationIsExtension + 8240
17 UIKit 0x2eab1a68 _UIApplicationUsesAlternateUI + 38388
18 UIKit 0x2eaa5ec8 _UIApplicationIsExtension + 1304
19 FrontBoardServices 0x319bd04e _FBSLog + 2198
20 CoreFoundation 0x2b1692d2 CFRunLoopTimerSetTolerance + 5878
21 CoreFoundation 0x2b168594 CFRunLoopTimerSetTolerance + 2488
22 CoreFoundation 0x2b166d16 _CFRunLoopGet2b + 2174
23 CoreFoundation 0x2b0b624c CFRunLoopRunSpecific + 472
24 CoreFoundation 0x2b0b605e CFRunLoopRunInMode + 102
25 UIKit 0x2e8ab5ba _UISharedImageSetLoadFactor + 3906
26 UIKit 0x2e8a6844 UIApplicationMain + 1436
27 My Game 0x0012a940 top_level_code (AppDelegate.swift:0)
28 My Game 0x0012a97c main (AppDelegate.swift:0)
29 libdyld.dylib 0x385aaaac _tlv_atexit + 8
Thank you
Try running Clean on the project, a few people had problems with bad access, me included, when updating. Some resolved it with clean and some withe a fresh copy of the project.

Resources