52inc / Pulley

A library to imitate the iOS 10 Maps UI.
https://cocoapods.org/pods/Pulley
MIT License
2.02k stars 265 forks source link

EXC_BAD_ACCESS error #95

Closed fariz-siracli closed 6 years ago

fariz-siracli commented 7 years ago

Hi guys. I'm getting such kind of exception from crash reports and do not understand why this happens. Could you please help me with this issue? (my app name is NewGoMapV2.0)

EXC_BAD_ACCESS / KERN_INVALID_ADDRESS 1 libobjc.A.dylib objc_msgSend + 105436 2 UIKit -[UINibStringIDTable lookupKey:identifier:] + 6301264 3 UIKit -[UINibDecoder decodeObjectForKey:] + 6283936 4 UIKit -[UINib instantiateWithOwner:options:] + 5100844 5 UIKit -[UIViewController _loadViewFromNibNamed:bundle:] + 3699512 6 UIKit -[UIViewController loadView] + 1376844 7 UIKit -[UIViewController loadViewIfRequired] + 81256 8 UIKit -[UIViewController view] + 81088

9 NewGoMapV2.0 specialized PulleyViewController.primaryContentViewController.didset + 627508 10 NewGoMapV2.0 PulleyViewController.init(contentViewController : UIViewController, drawerViewController : UIViewController) -> PulleyViewController (PulleyViewController.swift) 11 NewGoMapV2.0 specialized AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool (AppDelegate.swift) 12 NewGoMapV2.0 @objc AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool (AppDelegate.swift)

13 UIKit -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 562944 14 UIKit -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2851116 15 UIKit -[UIApplication _runWithMainScene:transitionContext:completion:] + 2868404 16 UIKit -[UIApplication workspaceDidEndTransaction:] + 2856380 17 FrontBoardServices -[FBSSerialQueue _performNext] + 161676 18 FrontBoardServices -[FBSSerialQueue _performNextFromRunLoopSource] + 162572 19 CoreFoundation CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 904952 20 CoreFoundation CFRunLoopDoSources0 + 903564 21 CoreFoundation CFRunLoopRun + 894604 22 CoreFoundation CFRunLoopRunSpecific + 38524 23 UIKit -[UIApplication _run] + 533884 24 UIKit UIApplicationMain + 511372 25 NewGoMapV2.0 main (AppDelegate.swift:13) 26 libdyld.dylib start + 10420

amyleecodes commented 7 years ago

It’s hard to tell from this stacktrace, but it looks like it’s failing to load the Xib or storyboard file for the view controller you’re using as the primary content view controller.

Make sure you don’t have any outlets in Interface Builder connected to variables that don’t exist anymore. You can check this by right-clicking on your view controller in the left side-bar in Interface Builder. When the menu opens that shows outlet connections, make sure none of yellow warning signs. If they do, you’ll need to click the X to delete them.

fariz-siracli commented 7 years ago

Thank you for attention. I checked again. There is no broken outlet, if it were it would crash during debug. But it does not. When i debug it on simulator or any device it works normally. This comes from crash reports. Here is my initialisation code.

weak var centerViewController:ViewController?
    var mmDrawerController: MMDrawerController?
    var pulleyDrawerVC : PulleyViewController?
    var drawerContentVC : DrawerContentViewController?

 func application(_ application: UIApplication, didFinishLaunchingWithOptions   ........
{
         centerViewController = mainStoryboard.instantiateViewController(withIdentifier: "MViewController") as? ViewController
        let leftViewController = mainStoryboard.instantiateViewController(withIdentifier: "LeftSideViewController") as! LeftSideViewController
        drawerContentVC = mainStoryboard.instantiateViewController(withIdentifier: "DrawerContentViewController") as? DrawerContentViewController
        let centerNav = UINavigationController(rootViewController: centerViewController!)
        pulleyDrawerVC = PulleyViewController(contentViewController: centerNav, drawerViewController: drawerContentVC!)
        mmDrawerController = MMDrawerController(center: pulleyDrawerVC, leftDrawerViewController: leftViewController)
}

And here my storyboard. screen shot 2017-10-23 at 11 07 02

Any advice please. Thanks in advance.

amyleecodes commented 7 years ago

Its something to do with it loading the Storyboard file.

The way you’re creating Pulley isn’t correct. If you have Pulley setup in Interface Builder (and the view controllers setup as embeds), you shouldn’t be attempting to create and assign them separately. You also shouldn’t be using the initializer for Pulley.

Remove your existing code and replace it with a line that instantiates Pulley using the Storyboard. Don’t create the initial view controllers in code, as they’ll be loaded automatically when Pulley is created from the Storyboard (since they’re setup as embed segues).

fariz-siracli commented 7 years ago

You have changed AppDelegate file since i started using Pulley. By the time implemented lib AppDelegate was as following. This code is from sample you provided here :

window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()!

        // To create in code (uncomment this block)

        let mainContentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PrimaryContentViewController")
        let drawerContentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DrawerContentViewController")
        pulleyDrawerVC = PulleyViewController(contentViewController: mainContentVC, drawerViewController: drawerContentVC)

        // Uncomment this next line to give the drawer a starting position, in this case: closed.
          pulleyDrawerVC!.initialDrawerPosition = .closed
        window?.rootViewController = pulleyDrawerVC
        window?.makeKeyAndVisible()

And i have already implemented based on this approach. Now i'm afraid to break app changing to the way you suggest. I also use another class MMDrawerController (left side menu). I think i won't be able to combine both using the Storyboard.

amyleecodes commented 7 years ago

You’ll notice that the AppDelegate for the example has always had those lines commented out, as the example uses Storyboards. Those lines are only for if you aren’t using Storyboards. It’s one approach or the other, but not both.

fariz-siracli commented 7 years ago

So isn't it possible to fix crash with code approach (not storyboard) ???? This crash never occurs in development process. And from users i get it rarely.

amyleecodes commented 7 years ago

The problem is that you can't do both like you're trying to do. You can use initialize in code or Storyboards, but not both. That's likely where you're having the issue.