Posts

Post marked as unsolved
402 Views

Debug libc++abi.dylib: terminating with uncaught exception of type std::runtime_error

I have a Swift app, which consists of an ARScnView, a WebView stacked on top of it, and then a ReactView on top of that. Now my problem: Every 1 out of 5 Rebuilds/Starts (does not matter), I get a terminating crash with the following message: libc++abi.dylib: terminating with uncaught exception of type std::runtime_error There is absolutely no more information to be found in the log. It doesn't matter if I run the app on a simulator or an actual iPhone. As far as I can tell, the error occurs when the metro bundler tries to load the local react-native bundle. I delay the loading of every component of my app for debugging reasons. This is my ViewController.swift: // //	SceneViewRenderer.swift //	realnote_app // //	Created by RealNote on 02.09.20. //	Copyright © 2020 Facebook. All rights reserved. // import Foundation import UIKit import ARKit import WebKit import Vision @objc class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate, RCTBridgeDelegate { 	func sourceURL(for bridge: RCTBridge!) -> URL! { 		return Bundle.main.url(forResource: "main", withExtension: "jsbundle") 	} 	 	 	@IBOutlet weak var sceneView: ARSCNView! 	var webView: WKWebView! 	var webViewManager: WebViewManager! 	var rootView : RCTRootView? 	 	var bridge : RCTBridge? 	 	var interpreterReady = true 	var startTime = Date() 	var endTime = Date() 	var lastCameraImage : UIImage? 	 	let TAG = "ViewController" 	 	override func viewDidLoad() { 		super.viewDidLoad() 		UIApplication.shared.isIdleTimerDisabled = true 		DispatchQueue.main.asyncAfter(deadline: .now() + 4) { 			self.initReactView() 			DispatchQueue.main.asyncAfter(deadline: .now() + 10) { 				self.initWebView() 				let screenWidth = UIScreen.main.bounds.width 				let screenHeight = UIScreen.main.bounds.height 			} 		} 		 		configureLighting() 		addTapGestureToSceneView() 	} 	 	func initWebView() { 		self.webViewManager = WebViewManager(hostViewController: self) 		webView = webViewManager.webView 		 		self.view.insertSubview(webView, aboveSubview: sceneView!) 	} 	 	func initReactView() { 		bridge = RCTBridge(delegate: self, launchOptions: nil) 		rootView = RCTRootView( 			bridge: bridge!, 			moduleName: "realnote", 			initialProperties: nil) 		rootView!.frame = UIScreen.main.bounds 		rootView!.contentView.backgroundColor = UIColor.clear 		 		 		rootView!.backgroundColor = UIColor.clear 		self.view.insertSubview(rootView!, aboveSubview: sceneView) 	} 	 	override func viewWillAppear(_ animated: Bool) { 		super.viewWillAppear(animated) 		setUpSceneView() 	} 	 	override func viewWillDisappear(_ animated: Bool) { 		super.viewWillDisappear(animated) 		sceneView.session.pause() 	} 	 	func setUpSceneView() { 		let configuration = ARWorldTrackingConfiguration() 		configuration.planeDetection = [.horizontal, .vertical] 		sceneView.delegate = self 		sceneView.session.delegate = self 		 		sceneView.session.run(configuration) 		 		sceneView.session.delegate = self 		sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints] 		sceneView.isPlaying = true 		HostARInterface.instance.session = sceneView.session 	} 	 	func configureLighting() { 		sceneView.autoenablesDefaultLighting = true 		sceneView.automaticallyUpdatesLighting = true 	} 	 	func session(_ session: ARSession, didUpdate: ARFrame) { 	} 	 	@objc func tapDelegate(withGestureRecognizer recognizer: UIGestureRecognizer) { 		print("tapped") 	} 	 	@objc func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) { 		// 1 		guard let planeAnchor = anchor as? ARPlaneAnchor else { return } 		 		// 2 		let width = CGFloat(planeAnchor.extent.x) 		let height = CGFloat(planeAnchor.extent.z) 		let plane = SCNPlane(width: width, height: height) 		 		// 3 		plane.materials.first?.diffuse.contents = UIColor.transparentLightBlue 		 		// 4 		let planeNode = SCNNode(geometry: plane) 		 		// 5 		let x = CGFloat(planeAnchor.center.x) 		let y = CGFloat(planeAnchor.center.y) 		let z = CGFloat(planeAnchor.center.z) 		planeNode.position = SCNVector3(x,y,z) 		planeNode.eulerAngles.x = -.pi / 2 		 		// 6 		node.addChildNode(planeNode) 		sceneView.scene.rootNode.addChildNode(planeNode) 	} 	 	 	@objc func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) { 		// 1 		guard let planeAnchor = anchor as?	ARPlaneAnchor, 					let planeNode = node.childNodes.first, 					let plane = planeNode.geometry as? SCNPlane 		else { return } 		 		// 2 		let width = CGFloat(planeAnchor.extent.x) 		let height = CGFloat(planeAnchor.extent.z) 		plane.width = width 		plane.height = height 		 		// 3 		let x = CGFloat(planeAnchor.center.x) 		let y = CGFloat(planeAnchor.center.y) 		let z = CGFloat(planeAnchor.center.z) 		planeNode.position = SCNVector3(x, y, z) 	} } extension float4x4 { 	var translation: float3 { 		let translation = self.columns.3 		return float3(translation.x, translation.y, translation.z) 	} } extension UIColor { 	open class var transparentLightBlue: UIColor { 		return UIColor(red: 90/255, green: 200/255, blue: 250/255, alpha: 0.50) 	} } extension DispatchQueue { 	 	static func background(delay: Double = 0.0, background: (()->Void)? = nil, completion: (() -> Void)? = nil) { 		DispatchQueue.global(qos: .background).async { 			background?() 			if let completion = completion { 				DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: { 					completion() 				}) 			} 		} 	} 	 } And my storyboard looks like this: Storyboard - https://developer.apple.com/forums/content/attachment/08621e77-6f06-489d-a75d-8f5900d7c08f Since this is NOT the often discussed libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)-error, I have absolutely no idea how to even debug this, or to get rid of it. Please note that on 4/5 runs the app behaves exactly as expected, react-native, and everything works like a charm.
Asked
by Noltibus.
Last updated .
Post marked as unsolved
126 Views

ARKit plane detection and visualisation won't work

I have an app, where I want to combine React Native, a WebView, and ARKit. So I stacked three views on top of each other with this code: #import "AppDelegate.h" #import <React/RCTBridge.h> #import <React/RCTBundleURLProvider.h> #import <React/RCTRootView.h> #import <SDImageCodersManager.h> #import <SDWebImageWebPCoder/SDImageWebPCoder.h> #import <WebKit/WebKit.h> #import "realnote_app-Swift.h" #import <ARKit/ARKit.h> @implementation AppDelegate (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { &#9;WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init]; &#9;[theConfiguration.preferences setValue:@"TRUE" forKey:@"allowFileAccessFromFileURLs"]; &#9;[theConfiguration setValue:@"TRUE" forKey:@"allowUniversalAccessFromFileURLs"]; &#9;UrlHandler *urlHandler = [[UrlHandler alloc] init]; &#9;[theConfiguration setURLSchemeHandler:urlHandler&#9;forURLScheme:@"localhost"]; &#9;WKWebView *webView = [[WKWebView alloc] initWithFrame:[UIScreen mainScreen].bounds configuration:theConfiguration]; &#9;webView.opaque = false; &#9;webView.scrollView.backgroundColor = UIColor.clearColor; &#9;webView.backgroundColor = UIColor.clearColor; &#9; &#9;NSURL *urlpath = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html" subdirectory:@"html"]; &#9;urlpath = [urlHandler changeURLSchemeWithNewScheme:@"localhost" forURL:urlpath]; &#9; &#9;NSURLRequest *nsrequest=[NSURLRequest requestWithURL:urlpath]; &#9;[webView loadRequest:nsrequest]; &#9; &#9;//ARSCNView *arView = [[ARSCNView alloc] initWithFrame:[UIScreen mainScreen].bounds]; &#9;SceneViewRenderer *sceneViewRenderer = [[SceneViewRenderer alloc] init]; &#9; &#9; &#9;RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; &#9;RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; moduleName:@"realnote_app" &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;initialProperties:nil]; &#9;rootView.contentView.backgroundColor = UIColor.clearColor; &#9; &#9;rootView.backgroundColor = UIColor.clearColor; &#9;self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; &#9;UIViewController *rootViewController = [UIViewController new]; &#9; &#9;UIView *holderView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; &#9;holderView.backgroundColor = UIColor.clearColor; &#9; &#9;rootView.frame = [UIScreen mainScreen].bounds; &#9;[holderView insertSubview:sceneViewRenderer.view belowSubview:rootView]; &#9;[holderView insertSubview:webView belowSubview:rootView]; &#9; &#9;[holderView addSubview:rootView]; &#9; &#9; &#9;rootViewController.view = holderView; &#9;self.window.rootViewController = rootViewController; &#9; &#9;[self.window makeKeyAndVisible]; &#9;[SDImageCodersManager.sharedManager addCoder:SDImageWebPCoder.sharedCoder]; &#9; &#9;return YES; } (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG &#9;return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; #else &#9;return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } @end My SceneViewRenderer class looks like this: import Foundation import UIKit import ARKit @objc class SceneViewRenderer: UIViewController, ARSCNViewDelegate { &#9; &#9;public var sceneView: ARSCNView! &#9; &#9;override func loadView() { &#9;&#9;self.view = ARSCNView(frame: UIScreen.main.bounds) &#9;&#9;sceneView = (self.view as! ARSCNView) &#9;} &#9; &#9;override func viewDidLoad() { &#9;&#9;super.viewDidLoad() &#9;&#9; &#9;&#9;let scene = SCNScene() &#9;&#9;let boxGeometry = SCNBox( &#9;&#9;&#9;&#9;width: 0.1, &#9;&#9;&#9;&#9;height: 0.1, &#9;&#9;&#9;&#9;length: 0.1, &#9;&#9;&#9;&#9;chamferRadius: 0.0) &#9;&#9;let boxNode = SCNNode(geometry: boxGeometry) &#9;&#9;boxNode.position = SCNVector3Make(0, 0, -0.5) &#9;&#9;scene.rootNode.addChildNode(boxNode) &#9;&#9;sceneView.scene = scene &#9;} &#9; &#9;override func viewWillAppear(_ animated: Bool) { &#9;&#9;super.viewWillAppear(animated) &#9;&#9;setUpSceneView() &#9;} &#9; &#9;override func viewWillDisappear(_ animated: Bool) { &#9;&#9;super.viewWillDisappear(animated) &#9;&#9;sceneView.session.pause() &#9;} &#9; &#9;func setUpSceneView() { &#9;&#9;let configuration = ARWorldTrackingConfiguration() &#9;&#9;configuration.planeDetection = [.horizontal, .vertical] &#9;&#9; &#9;&#9;sceneView.session.run(configuration) &#9;&#9; &#9;&#9;sceneView.delegate = self &#9;&#9;sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints] &#9;} &#9; &#9;@objc func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) { &#9;&#9;guard let planeAnchor = anchor as? ARPlaneAnchor else { return } &#9;&#9; &#9;&#9;let width = CGFloat(planeAnchor.extent.x) &#9;&#9;let height = CGFloat(planeAnchor.extent.z) &#9;&#9;let plane = SCNPlane(width: width, height: height) &#9;&#9; &#9;&#9;plane.materials.first?.diffuse.contents = UIColor.Blue &#9;&#9; &#9;&#9;let planeNode = SCNNode(geometry: plane) &#9;&#9; &#9;&#9;let x = CGFloat(planeAnchor.center.x) &#9;&#9;let y = CGFloat(planeAnchor.center.y) &#9;&#9;let z = CGFloat(planeAnchor.center.z) &#9;&#9;planeNode.position = SCNVector3(x,y,z) &#9;&#9;planeNode.eulerAngles.x = -.pi / 2 &#9;&#9; &#9;&#9;node.addChildNode(planeNode) &#9;&#9;sceneView.scene.rootNode.addChildNode(planeNode) &#9;} &#9; &#9; &#9;@objc func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) { &#9;&#9;guard let planeAnchor = anchor as?&#9;ARPlaneAnchor, &#9;&#9;&#9;let planeNode = node.childNodes.first, &#9;&#9;&#9;let plane = planeNode.geometry as? SCNPlane &#9;&#9;&#9;else { return } &#9;&#9; &#9;&#9;let width = CGFloat(planeAnchor.extent.x) &#9;&#9;let height = CGFloat(planeAnchor.extent.z) &#9;&#9;plane.width = width &#9;&#9;plane.height = height &#9;&#9; &#9;&#9;let x = CGFloat(planeAnchor.center.x) &#9;&#9;let y = CGFloat(planeAnchor.center.y) &#9;&#9;let z = CGFloat(planeAnchor.center.z) &#9;&#9;planeNode.position = SCNVector3(x, y, z) &#9;} } extension float4x4 { &#9;var translation: float3 { &#9;&#9;let translation = self.columns.3 &#9;&#9;return float3(translation.x, translation.y, translation.z) &#9;} } I can see my react buttons (they are only in the corners, the rest is transparent), I can also see the contents of my WebView (one element, the rest is transparent as well), and I can see the cube I rendered with ARKit as well as the feature points by ARKit. What doesn't work, is to visualize the planes. Even if I set breakpoints in the two functions I implemented, those won't get called. Any mistake I'm making?
Asked
by Noltibus.
Last updated .