Group Group Group Group Group Group Group Group Group

In Chapter 11 I get an Error when a QRCode is detected

I’m still trying to find the cause of this issue, but I’m putting it out there in case others encounter it.

I am right before the “Playing a video” section of the chapter, and when I run the code and detect a QRCode, I get the following error:

New billboard created
2019-07-21 15:03:57.966683-0500 RazeAd[1319:914941] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior. trace=(
	0   UIKitCore                           0x0000000193e8cfd8 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 14893016
	1   libdispatch.dylib                   0x000000010530ec80 _dispatch_client_callout + 16
	2   libdispatch.dylib                   0x0000000105310570 _dispatch_once_callout + 84
	3   UIKitCore                           0x0000000193e8cf3c 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 14892860
	4   UIKitCore                           0x0000000193e8d0c4 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 14893252
	5   UIKitCore                           0x0000000193216450 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 1823824
	6   UIKitCore                           0x0000000193c3ec08 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 12475400
	7   UIKitCore                           0x0000000193a4fafc 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 10447612
	8   UIKitCore                           0x0000000193c3cef4 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 12467956
	9   UIKitCore                           0x0000000193a4d0b0 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 10436784
	10  UIKitCore                           0x0000000193a4ded0 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 10440400
	11  UIKitCore                           0x0000000193a4dc34 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 10439732
	12  SceneKit                            0x00000001a3e2d6fc E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 2275068
	13  SceneKit                            0x00000001a3e2d860 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 2275424
	14  SceneKit                            0x00000001a3e4d648 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 2405960
	15  SceneKit                            0x00000001a3cc077c E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 780156
	16  SceneKit                            0x00000001a3c90eac E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 585388
	17  SceneKit                            0x00000001a3c90dd4 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 585172
	18  SceneKit                            0x00000001a3cb398c E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 727436
	19  SceneKit                            0x00000001a3cb0bf8 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 715768
	20  SceneKit                            0x00000001a3caf938 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 710968
	21  SceneKit                            0x00000001a3cae8bc E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 706748
	22  SceneKit                            0x00000001a3dd6cd0 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 1920208
	23  SceneKit                            0x00000001a3dd6a24 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 1919524
	24  SceneKit                            0x00000001a3dddc5c E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 1948764
	25  SceneKit                            0x00000001a3c6af44 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 429892
	26  SceneKit                            0x00000001a3c6c58c E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 435596
	27  SceneKit                            0x00000001a3d63238 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 1446456
	28  SceneKit                            0x00000001a3d63b74 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 1448820
	29  SceneKit                            0x00000001a3d640e0 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 1450208
	30  SceneKit                            0x00000001a3d64474 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 1451124
	31  SceneKit                            0x00000001a3dfe7a0 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 2082720
	32  ARKit                               0x00000001aae632f8 B889CC13-C1C2-37B2-A511-DFBB12F0C8CB + 873208
	33  SceneKit                            0x00000001a3cc4f14 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 798484
	34  SceneKit                            0x00000001a3dca038 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 1867832
	35  libdispatch.dylib                   0x000000010530ec80 _dispatch_client_callout + 16
	36  libdispatch.dylib                   0x000000010531d904 _dispatch_lane_barrier_sync_invoke_and_complete + 124
	37  SceneKit                            0x00000001a3dc9fc8 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 1867720
	38  GPUToolsCore                        0x0000000105535628 -[DYDisplayLinkInterposer forwardDisplayLinkCallback:] + 168
	39  QuartzCore                          0x00000001962f4bb8 FB98ED7E-AAEF-3DC5-8FA8-72D7108C3F88 + 72632
	40  QuartzCore                          0x00000001963be790 FB98ED7E-AAEF-3DC5-8FA8-72D7108C3F88 + 898960
	41  CoreFoundation                      0x000000018f9d8fcc 05D70723-5989-31E9-8633-F71B5D0F2CE1 + 524236
	42  CoreFoundation                      0x000000018fa025f4 05D70723-5989-31E9-8633-F71B5D0F2CE1 + 693748
	43  CoreFoundation                      0x000000018fa01d20 05D70723-5989-31E9-8633-F71B5D0F2CE1 + 691488
	44  CoreFoundation                      0x000000018f9fcbf4 05D70723-5989-31E9-8633-F71B5D0F2CE1 + 670708
	45  CoreFoundation                      0x000000018f9fc054 CFRunLoopRunSpecific + 464
	46  Foundation                          0x000000018fd3a8c4 0C953B39-2D12-3FD6-B93A-902C7D918CB8 + 30916
	47  SceneKit                            0x00000001a3cc52f0 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 799472
	48  SceneKit                            0x00000001a3cc5538 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 800056
	49  libsystem_pthread.dylib             0x000000018f7a21c4 _pthread_start + 124
	50  libsystem_pthread.dylib             0x000000018f7a5a00 thread_start + 8
)
2019-07-21 15:03:57.982050-0500 RazeAd[1319:914733] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x28303f430 UIButton:0x110c8b8a0.bottom == UILayoutGuide:0x282935340'UIViewSafeAreaLayoutGuide'.bottom   (active)>",
    "<NSLayoutConstraint:0x28303f480 UIButton:0x110c8b8a0.centerY == RazeAd.BillboardView:0x110cbaa30.centerY   (active)>",
    "<NSLayoutConstraint:0x28303f4d0 UIButton:0x110c8b8a0.top == UILayoutGuide:0x282935340'UIViewSafeAreaLayoutGuide'.top   (active)>",
    "<NSLayoutConstraint:0x28303f340 'UIViewSafeAreaLayoutGuide-bottom' V:[UILayoutGuide:0x282935340'UIViewSafeAreaLayoutGuide']-(0)-|   (active, names: '|':RazeAd.BillboardView:0x110cbaa30 )>",
    "<NSLayoutConstraint:0x28303f2a0 'UIViewSafeAreaLayoutGuide-top' V:|-(20)-[UILayoutGuide:0x282935340'UIViewSafeAreaLayoutGuide']   (active, names: '|':RazeAd.BillboardView:0x110cbaa30 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x28303f480 UIButton:0x110c8b8a0.centerY == RazeAd.BillboardView:0x110cbaa30.centerY   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-07-21 15:03:57.982807-0500 RazeAd[1319:914733] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x28303f7a0 UIButton:0x110c7df90.top == UILayoutGuide:0x282935340'UIViewSafeAreaLayoutGuide'.top   (active)>",
    "<NSLayoutConstraint:0x28303f7f0 UIButton:0x110c7df90.bottom == UILayoutGuide:0x282935340'UIViewSafeAreaLayoutGuide'.bottom   (active)>",
    "<NSLayoutConstraint:0x28303f840 UIButton:0x110c7df90.centerY == RazeAd.BillboardView:0x110cbaa30.centerY   (active)>",
    "<NSLayoutConstraint:0x28303f340 'UIViewSafeAreaLayoutGuide-bottom' V:[UILayoutGuide:0x282935340'UIViewSafeAreaLayoutGuide']-(0)-|   (active, names: '|':RazeAd.BillboardView:0x110cbaa30 )>",
    "<NSLayoutConstraint:0x28303f2a0 'UIViewSafeAreaLayoutGuide-top' V:|-(20)-[UILayoutGuide:0x282935340'UIViewSafeAreaLayoutGuide']   (active, names: '|':RazeAd.BillboardView:0x110cbaa30 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x28303f840 UIButton:0x110c7df90.centerY == RazeAd.BillboardView:0x110cbaa30.centerY   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-07-21 15:03:58.009582-0500 RazeAd[1319:914941] This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.
 Stack:(
	0   Foundation                          0x000000018ff5796c 0C953B39-2D12-3FD6-B93A-902C7D918CB8 + 2247020
	1   Foundation                          0x000000018fd63ea4 0C953B39-2D12-3FD6-B93A-902C7D918CB8 + 200356
	2   Foundation                          0x000000018fd63dbc 0C953B39-2D12-3FD6-B93A-902C7D918CB8 + 200124
	3   Foundation                          0x000000018fd63a30 0C953B39-2D12-3FD6-B93A-902C7D918CB8 + 199216
	4   UIKitCore                           0x0000000193e87cfc 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 14871804
	5   UIKitCore                           0x0000000193e9a444 2C3BF2F2-59FE-346C-8787-6C328FEA0028 + 14947396
	6   QuartzCore                          0x0000000196431230 FB98ED7E-AAEF-3DC5-8FA8-72D7108C3F88 + 1368624
	7   QuartzCore                          0x0000000196435a60 FB98ED7E-AAEF-3DC5-8FA8-72D7108C3F88 + 1387104
	8   QuartzCore                          0x000000019644125c FB98ED7E-AAEF-3DC5-8FA8-72D7108C3F88 + 1434204
	9   QuartzCore                          0x000000019638ce88 FB98ED7E-AAEF-3DC5-8FA8-72D7108C3F88 + 695944
	10  QuartzCore                          0x00000001963b6d04 FB98ED7E-AAEF-3DC5-8FA8-72D7108C3F88 + 867588
	11  QuartzCore                          0x00000001962f4cb8 FB98ED7E-AAEF-3DC5-8FA8-72D7108C3F88 + 72888
	12  QuartzCore                          0x00000001963be790 FB98ED7E-AAEF-3DC5-8FA8-72D7108C3F88 + 898960
	13  CoreFoundation                      0x000000018f9d8fcc 05D70723-5989-31E9-8633-F71B5D0F2CE1 + 524236
	14  CoreFoundation                      0x000000018fa025f4 05D70723-5989-31E9-8633-F71B5D0F2CE1 + 693748
	15  CoreFoundation                      0x000000018fa01d20 05D70723-5989-31E9-8633-F71B5D0F2CE1 + 691488
	16  CoreFoundation                      0x000000018f9fcbf4 05D70723-5989-31E9-8633-F71B5D0F2CE1 + 670708
	17  CoreFoundation                      0x000000018f9fc054 CFRunLoopRunSpecific + 464
	18  Foundation                          0x000000018fd3a8c4 0C953B39-2D12-3FD6-B93A-902C7D918CB8 + 30916
	19  SceneKit                            0x00000001a3cc52f0 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 799472
	20  SceneKit                            0x00000001a3cc5538 E8DAD1B3-2BAE-3757-B4E7-43C2E16E1F3F + 800056
	21  libsystem_pthread.dylib             0x000000018f7a21c4 _pthread_start + 124
	22  libsystem_pthread.dylib             0x000000018f7a5a00 thread_start + 8
)

2019-07-21 15:04:18.328563-0500 RazeAd[1319:914941] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'
*** First throw call stack:
(0x18fa84028 0x18f7ae384 0x18ff579fc 0x18fd63ea4 0x18fd63dbc 0x18fd63a30 0x193e87cfc 0x193e9a444 0x196431230 0x196435a60 0x19644125c 0x19638ce88 0x1963b6d04 0x1962f4cb8 0x1963be790 0x18f9d8fcc 0x18fa025f4 0x18fa01d20 0x18f9fcbf4 0x18f9fc054 0x18fd3a8c4 0x1a3cc52f0 0x1a3cc5538 0x18f7a21c4 0x18f7a5a00)
libc++abi.dylib: terminating with uncaught exception of type NSException

Well, it seems to be happening when you get to this line of setBillboardImage

self.billboard?.billboardNode?.geometry?.materials = [material]

I traced it in the debugger a bit, but it isn’t making any sense to me right now.

If anyone has a work-around, I would love to see it!

Hi,

I don’t have my Mac nearby at this moment, so I cannot check the code more carefully, and give you a better answer, but it looks like that line of code must be executed on the main thread - so if you embed it (or the whole block where that line is contained) in an async dispatch on the main thread it should work - something like

DispatchQueue.main.async {
  self.billboard?.billboardNode?.geometry?.materials = [material]
}

Antonio

Thanks. That part of the code is already running on the main thread…

func setBillboardImage(_ images: [UIImage]) {
        let material = SCNMaterial()
    
    material.isDoubleSided = true
    
    DispatchQueue.main.async {
        let billboardViewController = BillboardViewController(nibName: "BillboardViewController", bundle: nil)
        billboardViewController.images = images
        
        material.diffuse.contents = billboardViewController.view
        
        self.billboard?.viewController = billboardViewController
        self.billboard?.billboardNode?.geometry?.materials = [material]
    }
}

I even tried wrapping that line in another DispatchQueue.main.asnyc {} block, but that didn’t fix anything.

:frowning:

Oh, also… I am running this in Xcode 11. So, if anyone knows of any changes, maybe to SceneKit, that could be causing this, please let me know.

Oh I see, now I understand.

It looks like in Xcode 11 (at least in beta 3), when a view is attached to a SceneKit node, autolayout constraints are resolved in the scene kit thread instead of the main thread. I couldn’t find a fix myself - the only way to make it to work is by temporarily removing all autolayout constraints.

I think this is a bug, that it will be fixed in a future version. However this doesn’t affect Xcode 10, in case you prefer the “blue” pill :]

Is there a solution now in Xcode 11.0?

1 Like