Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift 4 & Xcode 9] Unexpected Crash When Presenting View Controller #5026

Closed
luispadron opened this issue Jun 12, 2017 · 10 comments
Closed
Labels

Comments

@luispadron
Copy link

luispadron commented Jun 12, 2017

Goals

Present view controller and load Realm without crashing

Expected Results

Expected normal operation like what was previously working with Xcode 8.x and Swift 3.1

Actual Results

Unexpected crash with no error message.
All Error & Swift Error Breakpoints do not seem to catch the crash either.

Stacktrace:
screen shot 2017-06-12 at 6 12 19 pm

Following the first event in RLMNotification stack trace, the error line seems to be this

// Line 202 in external_commit_helper.cpp
ret = kevent(m_kq, nullptr, 0, &event, 1, nullptr);

Second line in stack trace points to this:

    // Line 159 in external_commit_helper.cpp
    m_thread = std::async(std::launch::async, [=] {
        try {
            listen();
        }

Steps to Reproduce

Clone the project at: https://github.com/luispadron/GradePoint

When using Xcode 9 Beta 1 switch to the features/ios11 branch, run through the intro screens, and click on the Add new class or the + button.

Code Sample

I believe the issue is caused when instantiating a Realm instance.
Inside the AddEditClassViewController.swift file of my project there is this line

// Here realm is a property of this view controller thus gets instantiated when loading the view controller
let realm = try! Realm()

Another oddity is when removing the above line Xcode 9 Beta 1 Refuses to compile with error
Command failed due to signal: Segmentation fault: 11

The log reveals this:

1.	While type-checking 'saveNewInProgressClass' at /Users/luis/Programming/iOS/GradePoint/GradePoint/AddEditClassViewController.swift:449:5
2.	While type-checking expression at [/Users/luis/Programming/iOS/GradePoint/GradePoint/AddEditClassViewController.swift:474:9 - line:476:9] RangeText="try! realm.write {
            realm.add(newClass)
        }"
3.	While reading from /Users/luis/Library/Developer/Xcode/DerivedData/GradePoint-bcqivkdwawhfzphbxypksxkvsblz/Build/Products/Debug-iphonesimulator/RealmSwift/RealmSwift.framework/Modules/RealmSwift.swiftmodule/x86_64.swiftmodule
4.	While deserializing 'SyncPermissionResults' (TypeAliasDecl #507) in 'RealmSwift'
5.	While deserializing 'RLMSyncPermissionResults' (ClassDecl #509) in 'RealmSwift'
6.	Cross-reference to module 'Realm'
	... RLMSyncPermissionResults
7.	/Users/luis/Library/Developer/Xcode/DerivedData/GradePoint-bcqivkdwawhfzphbxypksxkvsblz/Build/Products/Debug-iphonesimulator/Realm/Realm.framework/Headers/RLMSyncPermissionResults.h:49:12: importing 'RLMSyncPermissionResults'
8.	While type-checking 'deinit' in module 'Realm'
9.	While loading conformances for extension of RLMSyncPermissionResults in module 'RealmSwift'
10.	While reading conformance for type 'RLMSyncPermissionResults'
11.	While ... to 'BidirectionalCollection' in module 'Swift'
12.	While reading conformance for type 'RLMSyncPermissionResults'
13.	While ... to 'Collection' in module 'Swift'
14.	While reading conformance for type 'RLMSyncPermissionResults'
15.	While ... to 'Sequence' in module 'Swift'
16.	While deserializing 'Iterator' (TypeAliasDecl #514) in 'RealmSwift'

This is strange but it might just be a bug in Xcode 9 and radar should be filed.

Version of Realm and Tooling

Realm framework version: 2.8.1

Realm Object Server version: n/a

Xcode version: Xcode 9 Beta 1

iOS/OSX version: Target iOS 9, ran on iOS 11 simulator.

Dependency manager + version: CocoaPods 1.3.0.beta.1

@bdash
Copy link
Contributor

bdash commented Jun 13, 2017

The exception is being thrown on your main thread. The Realm notification listener thread is sitting idle, and isn't relevant to what you're seeing. Can you please share the backtrace of your main thread at the point the exception is thrown?

@luispadron
Copy link
Author

Ahh, makes sense.

The stack trace doesn't really give me anything I understand but here it is

* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x0000000104fbbd42 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x0000000104ff3457 libsystem_pthread.dylib`pthread_kill + 90
    frame #2: 0x0000000104ce9ba7 libsystem_c.dylib`abort + 127
    frame #3: 0x0000000104a7ffaf libc++abi.dylib`abort_message + 245
    frame #4: 0x0000000104a8014b libc++abi.dylib`default_terminate_handler() + 265
    frame #5: 0x00000001028e439e libobjc.A.dylib`_objc_terminate() + 97
    frame #6: 0x0000000104a9b8c9 libc++abi.dylib`std::__terminate(void (*)()) + 8
    frame #7: 0x0000000104a9b57a libc++abi.dylib`__cxa_rethrow + 99
    frame #8: 0x00000001028e42bc libobjc.A.dylib`objc_exception_rethrow + 40
    frame #9: 0x0000000102f091c9 CoreFoundation`CFRunLoopRunSpecific + 537
    frame #10: 0x000000010b2e99d7 GraphicsServices`GSEventRunModal + 62
    frame #11: 0x000000010547b91d UIKit`UIApplicationMain + 159
    frame #12: 0x000000010115caf7 GradePoint`main at AppDelegate.swift:13
    frame #13: 0x0000000104c21b65 libdyld.dylib`start + 1

Just puts a breakpoint with Thread 1: signal SIGABRT at

class AppDelegate: UIResponder, UIApplicationDelegate {

And prints this to console

libc++abi.dylib: terminating with uncaught exception of type NSException

If you'd like to take a look at the project yourself you can clone it here: https://github.com/luispadron/GradePoint, in the features/ios11 branch.
This happens on iOS 11 Sim and iOS 10.1, only when using Xcode 9 Beta 1.

I thought it might have been a Realm issue due to the fact I was getting Swift errors after updating, however, Realm 2.8.1 has fixed these errors but still getting this odd crash.

I've put a breakpoint on every method in the class but can't seem to find where it is actually crashing

@austinzheng
Copy link
Contributor

Can you set an exception breakpoint in Xcode and then re-run your application?

@bdash
Copy link
Contributor

bdash commented Jun 13, 2017

That backtrace indicates that an uncaught Objective-C exception is making it to the main runloop. Adding an exception breakpoint in Xcode for Objective-C exceptions should help you track down where the exception is thrown, and let you inspect the exception object.

@luispadron
Copy link
Author

Yeah, I've tried catching all exceptions before posting the issue, but it just completely ignores this and throws at AppDelegate which isn't very helpful.

Not sure what else could be going on, I've even checked all interface builder connections and they're all fine and connected (no missing/broken connections) which usually causes these types of crashes.

Here are my breakpoints if you guys were curious:

screen shot 2017-06-13 at 12 02 50 am

Well, if this doesn't seem like a Realm error to you guys feel free to close the issue. Again, I thought it might have had something to do with Realm due to some breaking Swift 4/Xcode 9 stuff.

@bdash
Copy link
Contributor

bdash commented Jun 13, 2017

The first backtrace you shared in your initial report appears to show your app stopped at the point that the Objective-C exception was thrown.

@luispadron
Copy link
Author

luispadron commented Jun 13, 2017

I was able to print the reason using LLDB

(lldb) po $arg1

-[UIDeviceRGBColor pointSize]: unrecognized selector sent to instance 0x60000067a6c0
(null)

However still confused about what this even is haha.

This doesn't seem to be a Realm issue so I'll go ahead and close the issue now and try to figure out what's going on without wasting your time. I'll update if I find a solution, thanks for all the help!

@luispadron
Copy link
Author

Just updating this issue in case anyone wanders upon it.
The issue was completely unrelated to Realm and just a dumb mistake on my part.

I was assigning a UIColor instance to a UIFont via an NSAttributedString. Due to the fact attributes for attributed strings can be of type Any I was not getting any compiler warnings/errors. Fixing this assignment fixed the crash for me.

@arbitur
Copy link

arbitur commented Nov 3, 2017

@luispadron Thanks, I had this problem and was really confused what was causing this crash, it was NSAttributedString that screwed me over too.

@arunprasathsivasamy
Copy link

@luispadron

Just updating this issue in case anyone wanders upon it.
The issue was completely unrelated to Realm and just a dumb mistake on my part.

I was assigning a UIColor instance to a UIFont via an NSAttributedString. Due to the fact attributes for attributed strings can be of type Any I was not getting any compiler warnings/errors. Fixing this assignment fixed the crash for me.

In which file we need to change UIColor instance to a UIFont via an NSAttributedString.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants