Class malfunction in production, but not debugging

I have the following class:

import UIKit class HeaderTableViewController: UITableViewController { var nonDefaultTitle : String? var data: [String: [String]] = [:] var headers : [String] = [] var bodys : [[String]] = [] init(displayData: [String: [String]]) { super.init(style: .Grouped) data = displayData for key in data.keys { headers.append(key) } for arr in data.values { bodys.append(arr) } } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } private override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) } override func viewDidLoad() { super.viewDidLoad() tableView.backgroundColor = UIColor.whiteColor() tableView.registerNib(UINib(nibName: "DefaultCustomCell", bundle: nil), forCellReuseIdentifier: "DefaultCustomCell") tableView.rowHeight = UITableViewAutomaticDimension tableView.estimatedRowHeight = 50 tableView.sectionHeaderHeight = UITableViewAutomaticDimension; tableView.estimatedSectionHeaderHeight = 100; let nib = UINib(nibName: "HeaderTableHeaderView", bundle: nil) tableView.registerNib(nib, forHeaderFooterViewReuseIdentifier: "HeaderTableHeaderView") if let ttle = nonDefaultTitle { self.title = ttle } else { self.title = "Talking Tips" } } } // // MARK: Helpers // extension HeaderTableViewController { override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return headers.count } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { let body = bodys[section] as [String] return body.count } override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let cell = self.tableView.dequeueReusableHeaderFooterViewWithIdentifier("HeaderTableHeaderView") let header = cell as? HeaderTableHeaderView header!.titleLabel.text = headers[section] return cell } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("DefaultCustomCell", forIndexPath: indexPath) as! DefaultCustomCell cell.titleLabel.text = bodys[indexPath.section][indexPath.row] cell.selectionStyle = .None return cell } override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { } } // // MARK: The table headers // class HeaderTableHeaderView: UITableViewHeaderFooterView { @IBOutlet weak var titleLabel: UILabel! } // // MARK: Class that handles the HeaderTableLargeHeaderView (sorry for the terrible naming conventions) // class HeaderTableLargeHeaderView: UIView { // Our title label with autolayout constraints @IBOutlet weak var titleLabel: UILabel! // Convience method to load for xib class func instanceFromNib() -> UIView { return UINib(nibName: "HeaderTableLargeHeaderView", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! UIView } override func layoutSubviews() { super.layoutSubviews() } } 

Pretty straight forward. It works fine if I install via Xcode or AdHoc using Diawi.

If, however, I install through TestFlight or through the AppStore, it crashes every time ... Did I do something wrong? My device logs give me the following:

 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000 Termination Signal: Segmentation fault: 11 Termination Reason: Namespace SIGNAL, Code 0xb Terminating Process: exc handler [0] Triggered by Thread: 0 Filtered syslog: None found Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 UIKit 0x0000000196387a4c __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 424 1 UIKit 0x00000001963879f0 __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 332 2 UIKit 0x0000000196347368 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2712 3 UIKit 0x00000001963467e4 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 536 4 UIKit 0x0000000196346570 -[UITableViewRowData heightForTable] + 60 5 UIKit 0x00000001963463a4 -[UITableView _updateContentSize] + 220 6 UIKit 0x000000019634c918 -[UITableView setContentInset:] + 252 7 UIKit 0x0000000196320438 -[UIViewController _setNavigationControllerContentInsetAdjustment:] + 428 8 UIKit 0x000000019632017c -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 464 9 UIKit 0x0000000196322214 -[UINavigationController _layoutViewController:] + 160 10 UIKit 0x0000000196322094 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 416 11 UIKit 0x0000000196408a58 -[UINavigationController _startCustomTransition:] + 2076 12 UIKit 0x0000000196320d74 -[UINavigationController _startDeferredTransitionIfNeeded:] + 676 13 UIKit 0x00000001963209dc -[UINavigationController __viewWillLayoutSubviews] + 64 14 UIKit 0x0000000196320940 -[UILayoutContainerView layoutSubviews] + 188 15 UIKit 0x0000000196265738 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1196 16 QuartzCore 0x000000019372e40c -[CALayer layoutSublayers] + 148 17 QuartzCore 0x00000001937230e8 CA::Layer::layout_if_needed(CA::Transaction*) + 292 18 QuartzCore 0x0000000193722fa8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32 19 QuartzCore 0x000000019369fc64 CA::Context::commit_transaction(CA::Transaction*) + 252 20 QuartzCore 0x00000001936c70d0 CA::Transaction::commit() + 512 21 UIKit 0x000000019625ae08 _afterCACommitHandler + 324 22 CoreFoundation 0x00000001903cd7dc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32 23 CoreFoundation 0x00000001903cb40c __CFRunLoopDoObservers + 372 24 CoreFoundation 0x00000001903cb89c __CFRunLoopRun + 1024 25 CoreFoundation 0x00000001902fa048 CFRunLoopRunSpecific + 444 26 GraphicsServices 0x0000000191d7d198 GSEventRunModal + 180 27 UIKit 0x00000001962d3818 -[UIApplication _run] + 684 28 UIKit 0x00000001962ce550 UIApplicationMain + 208 29 Care Com 0x00000001000db12c 0x1000b4000 + 160044 30 libdyld.dylib 0x000000018f2dc5b8 start + 4 

So, I was able to track the problem by switching my startup scheme from debugging to release. This is mistake:

 malloc: *** mach_vm_map(size=8589934592) failed (error code=3) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug 

So, I found what I thought was the solution, but I'm not sure why it works. I got the error above on this line:

 bodys[section].count 

If I get this back:

Optimization Level: Fast, Single-File Optimization [-0]

to

Optimization Level: None [-Onone]


Thus, the above fix works when installed through Xcode and TestFlight, however it crashes when downloading from the app store ... still opens and looks for the fix.


I tried changing the init method to this:

 init(displayData: [String: [String]]) { super.init(style: .Grouped) //data = displayData // I get a bad access error thrown when trying to access displayData print(displayData) for key in displayData.keys { headers.append(key) } for arr in displayData.values { bodys.append(arr) } } 

and turned on the optimization again, which gives me EXC_BAD_ACCESS when trying to use the init parameter.


I also worked with tools without optimization to check for leaks and memory allocations, and this is what I got. This is a version that works great through TestFlight and Xcode, but crashes when installing through the AppStore. Red arrows - this is when I pushed to the views, which are a failure in production.

Memory allocation: enter image description here

A leak: enter image description here


This is how I create and put forward a view:

 func testPush() { let data = createTestData() let tableHeaderVC = HeaderTableViewController(displayData: data as! [String : [String]]) self.navigationController?.pushViewController(tableHeaderVC, animated: true) } func createTestData() -> [String : [String]] { let firstSection = ["Row one", "Row two"] let secondSection = ["Row one", "Row two"] return ["First" : firstSection, "Second" : secondSection] } 

In addition, having examined this issue, I thought that perhaps this is a problem with the execution of a custom initializer. So I deleted this and did it when I set the variable before pushing ... still getting the same optimization error.

+6
source share

Source: https://habr.com/ru/post/1011821/


All Articles