I would like to know what it means when we get an error like the 'NSInvalidArgumentException', reason: 'A Node can't parent itself' :
2015-03-04 01:51:33.421 FlappyPOOSwift[1789:155918] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'A Node can't parent itself: <SKSpriteNode> name:'(null)' texture:[<SKTexture> 'pipeDown' (30 x 160)] position:{0, 851} size:{60, 320} rotation:0.00'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105361f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010705bbb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000105361e6d +[NSException raise:format:] + 205
3 SpriteKit 0x0000000105c23d14 -[SKNode(setParent) setParent:] + 134
4 SpriteKit 0x0000000105c1c1ea -[SKNode addChild:] + 179
5 FlappyPOOSwift 0x00000001051754d6 _TFC14FlappyPOOSwift9GameScene10spawnPipesfS0_FT_T_ + 2294
6 FlappyPOOSwift 0x0000000105176e28 _TFFC14FlappyPOOSwift9GameScene13didMoveToViewFS0_FCSo6SKViewT_U_FT_T_ + 56
7 FlappyPOOSwift 0x0000000105176e67 _TTRXFo__dT__XFdCb__dT__ + 39
8 SpriteKit 0x0000000105c11586 -[SKRunBlock updateWithTarget:forTime:] + 99
9 SpriteKit 0x0000000105beb586 _ZN11SKCSequence27cpp_updateWithTargetForTimeEP9SKCSprited + 92
10 SpriteKit 0x0000000105be374c _ZN9SKCRepeat27cpp_updateWithTargetForTimeEP9SKCSprited + 40
11 SpriteKit 0x0000000105c3bce8 _ZN9SKCSprite6updateEd + 170
12 SpriteKit 0x0000000105bf5435 -[SKScene _update:] + 120
13 SpriteKit 0x0000000105c0f949 -[SKView(Private) _update:] + 563
14 SpriteKit 0x0000000105c0d2d9 -[SKView renderCallback:shouldBlock:] + 837
15 SpriteKit 0x0000000105c0a391 __29-[SKView setUpRenderCallback]_block_invoke + 56
16 SpriteKit 0x0000000105c36df4 -[SKDisplayLink _callbackForNextFrame:] + 256
17 QuartzCore 0x0000000109c73747 _ZN2CA7Display15DisplayLinkItem8dispatchEv + 37
18 QuartzCore 0x0000000109c7360f _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 315
19 CoreFoundation 0x00000001052c9f64 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
20 CoreFoundation 0x00000001052c9b25 __CFRunLoopDoTimer + 1045
21 CoreFoundation 0x000000010528ce5d __CFRunLoopRun + 1901
22 CoreFoundation 0x000000010528c486 CFRunLoopRunSpecific + 470
23 GraphicsServices 0x000000010c70e9f0 GSEventRunModal + 161
24 UIKit 0x0000000105da3420 UIApplicationMain + 1282
25 FlappyPOOSwift 0x000000010517a89e top_level_code + 78
26 FlappyPOOSwift 0x000000010517a8da main + 42
27 libdyld.dylib 0x0000000107847145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Thanks in advance.
hi i guess ill just show you the code
func spawnPipes() {
let pipePair = SKNode()
pipePair.position = CGPointMake(self.frame.size.width + pipeUpTexture.size().width * 2, 0)
pipePair.zPosition = -10
let height = UInt32(self.frame.size.height / 4)
let y = arc4random() % height + height
let pipeDown = SKSpriteNode (texture: pipeDownTexture)
pipeDown.setScale(2.0)
pipeDown.position = CGPointMake(0.0 , CGFloat(y) + pipeDown.size.height + CGFloat(pipeGap))
pipeDown.physicsBody = SKPhysicsBody (rectangleOfSize: pipeDown.size)
pipeDown.physicsBody?.dynamic = false
pipeDown.addChild(pipeDown)
//pipe Up
**let pipeUp = SKSpriteNode (texture: pipeUpTexture)**
pipeUp.setScale(2.0)
pipeUp.position = CGPointMake(0.0 , CGFloat(y))
pipeUp.physicsBody = SKPhysicsBody (rectangleOfSize: pipeUp.size)
pipeUp.physicsBody?.dynamic = false
pipeUp.addChild(pipeUp)
pipePair.runAction(PipesMoveAndRemove)
self.addChild(pipePair)
}
I guess the lines which are ** marked have the error but i can't see them in the Xcode. I hope you understand what I'm trying to say
My guess is that either :
You are trying to add the node to itself (as the error mention), like for example : pipeDownNode.addChild(pipeDownNode) instead of anotherNode.addChild(pipeDownNode)
You are trying to add node at the same node twice, like : aNode.addChild(pipeDownNode) and pipeDownNode.parent = aNode
Let me know if it helped. Otherwise, please add some code (where you add the node).
Related
I am using Kotlin multiplatform to build framework for iOS, and everything works well except the strange issue.
The code from Kotlin:
fun example(): Map<Int, Double> {
val result = mutableMapOf<Int, Double>()
result[1] = 9.99
return result
}
Using framework is Swift:
let example = example()
The app will crash and display the trace as following
2019-10-30 15:37:19.096474+0800 Test[73756:3057881] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -getValue: only defined for abstract class. Define -[KotlinInt getValue:]!'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23baa1ee __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50864b20 objc_exception_throw + 48
2 Foundation 0x00007fff2584a6b3 _NSRequestConcreteObject + 0
3 Foundation 0x00007fff256bea7e -[NSNumber copyWithZone:] + 129
4 CoreFoundation 0x00007fff23add550 __NSSingleEntryDictionaryI_new + 128
5 CoreFoundation 0x00007fff23ba56f3 -[NSDictionary initWithDictionary:copyItems:] + 403
6 CoreFoundation 0x00007fff23c07fc7 -[__NSPlaceholderDictionary initWithDictionary:copyItems:] + 135
7 libswiftFoundation.dylib 0x00007fff511ef3a0 $sSD10FoundationE26_forceBridgeFromObjectiveC_6resultySo12NSDictionaryC_SDyxq_GSgztFZ + 192
8 libswiftFoundation.dylib 0x00007fff511e3593 $sSD10FoundationE36_unconditionallyBridgeFromObjectiveCySDyxq_GSo12NSDictionaryCSgFZ + 67
9 Test 0x0000000102f54320 $s4Test11ContentViewV3calSSyF + 1104
10 Test 0x0000000102f53e3b $s4Test11ContentViewV4bodyQrvg + 91
11 Test 0x0000000102f549c1 $s4Test11ContentViewV7SwiftUI0C0AadEP4body4BodyQzvgTW + 17
12 SwiftUI 0x00007fff2bfb1c49 $s7SwiftUI8ViewBody33_9F92ACD17B554E8AB7D29ABB1E796415LLV5applyy0D0QzxF + 585
13 SwiftUI 0x00007fff2bfb2df9 $s7SwiftUI8ViewBody33_9F92ACD17B554E8AB7D29ABB1E796415LLVyxG14AttributeGraph07UntypedM0AafGP7_update_5graph9attributeySv_So10AGGraphRefaSo11AGAttributeatFZTW + 137
14 AttributeGraph 0x00007fff2f8f1849 $sTA + 25
15 AttributeGraph 0x00007fff2f8d9255 _ZN2AG5Graph11UpdateStack6updateEv + 1111
16 AttributeGraph 0x00007fff2f8d9513 _ZN2AG5Graph16update_attributeEjb + 377
17 AttributeGraph 0x00007fff2f8de131 _ZN2AG8Subgraph6updateEj + 929
18 SwiftUI 0x00007fff2c10d100 $s7SwiftUI9ViewGraphC14runTransaction33_D63C4EB7F2B205694B6515509E76E98BLL2inySo10AGGraphRefa_tF + 224
19 SwiftUI 0x00007fff2c10d517 $s7SwiftUI9ViewGraphC13updateOutputs2atyAA4TimeV_tFSb5prefs_Sb9idealSizeAC0F0V7outputstSo10AGGraphRefaXEfU_ + 103
20 SwiftUI 0x00007fff2c10d1d1 $s7SwiftUI9ViewGraphC13updateOutputs2atyAA4TimeV_tF + 145
21 SwiftUI 0x00007fff2c4af579 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtFyyXEfU_yyXEfU_ + 1001
22 SwiftUI 0x00007fff2c4aef8a $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtFyyXEfU_ + 634
23 SwiftUI 0x00007fff2c4a4274 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtF + 436
24 SwiftUI 0x00007fff2c65a182 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyF + 226
25 SwiftUI 0x00007fff2c65a1a5 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyFTo + 21
26 UIKitCore 0x00007fff47a52ad5 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
27 QuartzCore 0x00007fff2b06e91d -[CALayer layoutSublayers] + 255
28 QuartzCore 0x00007fff2b073323 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
29 QuartzCore 0x00007fff2b07fa7c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
30 QuartzCore 0x00007fff2afc6e54 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
31 QuartzCore 0x00007fff2affc32f _ZN2CA11Transaction6commitEv + 643
32 UIKitCore 0x00007fff475906cd __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
33 CoreFoundation 0x00007fff23b0d09c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
34 CoreFoundation 0x00007fff23b0c808 __CFRunLoopDoBlocks + 312
35 CoreFoundation 0x00007fff23b07694 __CFRunLoopRun + 1284
36 CoreFoundation 0x00007fff23b06e66 CFRunLoopRunSpecific + 438
37 GraphicsServices 0x00007fff38346bb0 GSEventRunModal + 65
38 UIKitCore 0x00007fff47578dd0 UIApplicationMain + 1621
39 Test 0x0000000102f526fb main + 75
40 libdyld.dylib 0x00007fff516ecd29 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Actually, I want to implement the function to return the Map, but I inspect the type of example() in the Xocde's IDE is [KotlinInt : KotlinDouble]. I don't know how to fix this to use this function in the Xcode normally without the exception.
I thought there is no structure type "Map" in Kotlin corresponding to "Dictionary" in iOS Swift. Try to replace the Map with MutableMap and solve this issue.
fun example(): MutableMap <Int, Double> {
val result = mutableMapOf<Int, Double>()
result[1] = 9.99
return result
}
However, you can also cast the type in Swift for another using. For example,
let example = example() as! [Int64 : Double]
Map exist in kotlin, here an example:
val map = mutableMapOf(1 to 1.2, 2 to 1.2, 3 to 1.5)
println(map)
map[4] = 3.4
println(map)
output:
{1=1.2, 2=1.2, 3=1.5}
{1=1.2, 2=1.2, 3=1.5, 4=3.4}
Help
There is an error:
2017-09-13 11:21:04.405 Seer[1413:69626] *** Terminating app due to
uncaught exception 'GMSThreadException', reason: 'The API method must
be called from the main thread'
*** First throw call stack:
(
0 CoreFoundation 0x000000010bb30b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010aef2141 objc_exception_throw + 48
2 CoreFoundation 0x000000010bb99625 +[NSException raise:format:] + 197
3 Seer 0x0000000104638ed2 -[GMSMapView clear] + 97
4 Seer 0x000000010461a4ff _TFC4Seer14ViewController12markercreatefT_T_ + 159
5 Seer 0x000000010461950f _TFFC4Seer14ViewController9outputphpFT_T_U_FTGSqV10Foundation4Data_GSqCSo11URLResponse_GSqPs5Error___T_ + 2927
6 Seer 0x00000001046178db _TTRXFo_oGSqV10Foundation4Data_oGSqCSo11URLResponse_oGSqPs5Error____XFdCb_dGSqCSo6NSData_dGSqS1__dGSqCSo7NSError___ + 203
7 CFNetwork 0x000000010b3bd87b __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19
8 CFNetwork 0x000000010b3bd095 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 143
9 Foundation 0x000000010a9fc3b7 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
10 Foundation 0x000000010a9fc0bb -[NSBlockOperation main] + 101
11 Foundation 0x000000010a9fa877 -[__NSOperationInternal _start:] + 627
12 Foundation 0x000000010a9f65fc __NSOQSchedule_f + 198
13 libdispatch.dylib 0x000000010caa905c _dispatch_client_callout + 8
14 libdispatch.dylib 0x000000010ca8794f _dispatch_queue_serial_drain + 221
15 libdispatch.dylib 0x000000010ca88669 _dispatch_queue_invoke + 1084
16 libdispatch.dylib 0x000000010ca8aec4 _dispatch_root_queue_drain + 634
17 libdispatch.dylib 0x000000010ca8abef _dispatch_worker_thread3 + 123
18 libsystem_pthread.dylib 0x000000010ce405a2 _pthread_wqthread + 1299
19 libsystem_pthread.dylib 0x000000010ce4007d start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type
NSException
(lldb)
in the simulator when interacting with the map, for example when creating markers:
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: catlatlon[index][1], longitude: catlatlon[index][2])
marker.title = "Муляж Камеры | ID: \(Int(catlatlon[index][3]))"
marker.snippet = "Дата: \(catstring[index])"
marker.icon = self.imageWithImage(image: #imageLiteral(resourceName: "ic_fake.png"), scaledToSize: CGSize(width: 28.0, height: 48.0)) // муляж камеры
marker.map = self.mMap
But on a real device everything works well.
I would leave it as it is. But I'm afraid when testing the application by moderators the AppStore, will show this error and they will not publish my application
I finished migrating my application to swift3 but this section keeps yielding is causing problems.
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: animated)
self.navigationItem.title = artworkTitle
let title = "<center><span style=\"font-size: 17px;font-weight:lighter;font-family:Avenir-Book;\">" + artworkCaption + "</span></center>"
artworkImageView.image = UIImage(named: artworkImagePath)
artworkCaptionView.attributedText = title.html2AttStr
}
Important Console Parts
-[_SwiftValue unsignedIntegerValue]: unrecognized selector sent to instance 0x608000243d50
terminating with uncaught exception of type NSException
(lldb)
extension String
{
var html2AttStr:NSAttributedString
{
let contents: NSMutableAttributedString?
do {
let attrTextStyle = NSMutableParagraphStyle()
attrTextStyle.alignment = NSTextAlignment.center
contents = try NSMutableAttributedString(data: data(using: String.Encoding.utf8)!, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8], documentAttributes: nil)
} catch _ {
contents = nil
}
Console
0 CoreFoundation 0x000000010b70934b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010ad7521e objc_exception_throw + 48
2 CoreFoundation 0x000000010b778f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010b68ec15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010b68e798 _CF_forwarding_prep_0 + 120
5 UIFoundation 0x0000000114565953 -[NSHTMLReader _loadUsingWebKit] + 1329
6 UIFoundation 0x0000000114566f15 -[NSHTMLReader attributedString] + 22
7 UIFoundation 0x00000001144fd45c _NSReadAttributedStringFromURLOrData + 5779
8 UIFoundation 0x00000001144fbd35 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 115
9 pg 0x000000010a39fe1d _TTOFCSo25NSMutableAttributedStringcfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S_ + 173
10 pg 0x000000010a39fba4 _TFCSo25NSMutableAttributedStringCfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S_ + 100
11 pg 0x000000010a39f96a _TFE2pgSSg11html2AttStrCSo18NSAttributedString + 458
12 pg 0x000000010a3a901d _TFC2pg21ViewControllerArtwork14viewWillAppearfSbT_ + 1197
13 pg 0x000000010a3a90b1 _TToFC2pg21ViewControllerArtwork14viewWillAppearfSbT_ + 49
14 UIKit 0x000000010c642de3 -[UIViewController _setViewAppearState:isAnimating:] + 692
15 UIKit 0x000000010c6434f3 -[UIViewController __viewWillAppear:] + 147
16 UIKit 0x000000010c67e1a3 -[UINavigationController _startTransition:fromViewController:toViewController:] + 890
17 UIKit 0x000000010c67f0b9 -[UINavigationController _startDeferredTransitionIfNeeded:] + 874
18 UIKit 0x000000010c68019b -[UINavigationController __viewWillLayoutSubviews] + 58
19 UIKit 0x000000010c8771b7 -[UILayoutContainerView layoutSubviews] + 223
20 UIKit 0x000000010c560344 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
21 QuartzCore 0x000000010c312cdc -[CALayer layoutSublayers] + 146
22 QuartzCore 0x000000010c3067a0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
23 QuartzCore 0x000000010c30661e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
24 QuartzCore 0x000000010c29462c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
25 QuartzCore 0x000000010c2c1713 _ZN2CA11Transaction6commitEv + 475
26 UIKit 0x000000010c495067 _UIApplicationFlushRunLoopCATransactionIfTooLate + 206
27 UIKit 0x000000010cca4b30 __handleEventQueue + 5672
28 CoreFoundation 0x000000010b6ae311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
29 CoreFoundation 0x000000010b69359c __CFRunLoopDoSources0 + 556
30 CoreFoundation 0x000000010b692a86 __CFRunLoopRun + 918
31 CoreFoundation 0x000000010b692494 CFRunLoopRunSpecific + 420
32 GraphicsServices 0x0000000111084a6f GSEventRunModal + 161
33 UIKit 0x000000010c49bf34 UIApplicationMain + 159
34 pg 0x000000010a3acaaf main + 111
35 libdyld.dylib 0x000000011233668d start + 1
36 ??? 0x0000000000000001 0x0 + 1
libc++abi.dylib: terminating with uncaught exception of type NSException
I remember reading on Apple's Swift blog that if you get unrecognized selector errors, it means that the auto-wrapping of Swift structs are causing issues. Most likely it is wrapping String.Encoding instead of converting it to an NSNumber (what the Objective-C code behind NSMutableAttributedString is expecting).
Try replacing NSCharacterEncodingDocumentAttribute: String.Encoding.utf8 with NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue
My problem is the following: I want to generate a data matrix with ZXingObjC and show it.
Currently i'm writing an application with XCode 7.3 and Swift 2.have to generate a data matrix with a String value. As the ZXingObjC written in Objective C, i tried to convert it myself according to this example:
NSError *error = nil;
ZXMultiFormatWriter *writer = [ZXMultiFormatWriter writer];
ZXBitMatrix* result = [writer encode:#"A string to encode"
format:kBarcodeFormatQRCode
width:500
height:500
error:&error];
if (result) {
CGImageRef image = [[ZXImage imageWithMatrix:result] cgimage];
} else {
NSString *errorMessage = [error localizedDescription];
}
The problem occurs when i try to encode my String with writer.encode(...) and i think it's good to precise that i tried with longer and smaller string but the result still the same.
do {
let writer = ZXMultiFormatWriter()
let hints = ZXEncodeHints() as ZXEncodeHints
let result = try writer.encode("foo", format: kBarcodeFormatDataMatrix, width: 300, height: 300, hints: hints)
let imageRef = ZXImage.init(matrix: result)
picture.image = UIImage(CGImage: imageRef.cgimage)
}
catch {
print(error)
}
And finally the app crash with this exception :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't find a symbol arrangement that matches the message. Data codewords: 17'
*** First throw call stack:
(
0 CoreFoundation 0x00000001081b7d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010854cdeb objc_exception_throw + 48
2 CoreFoundation 0x00000001081b7cbd +[NSException raise:format:] + 205
3 ZXingObjC 0x0000000107eb320a +[ZXDataMatrixSymbolInfo lookup:shape:minSize:maxSize:fail:] + 1178
4 ZXingObjC 0x0000000107ead4bb -[ZXDataMatrixEncoderContext updateSymbolInfoWithLength:] + 379
5 ZXingObjC 0x0000000107ea2866 -[ZXDataMatrixC40Encoder encode:] + 342
6 ZXingObjC 0x0000000107eaf032 +[ZXDataMatrixHighLevelEncoder encodeHighLevel:shape:minSize:maxSize:] + 1330
7 ZXingObjC 0x0000000107eb75b0 -[ZXDataMatrixWriter encode:format:width:height:hints:error:] + 672
8 ZXingObjC 0x0000000107ee246c -[ZXMultiFormatWriter encode:format:width:height:hints:error:] + 1100
9 DemoAppZXing 0x0000000103f54d98 _TFC4DemoAppZXing27VSMatrixOrderViewController11viewDidLoadfT_T_ + 8472
10 DemoAppZXing 0x0000000103f58002 _TToFC4DemoAppZXing27VSMatrixOrderViewController11viewDidLoadfT_T_ + 34
11 UIKit 0x0000000106a95984 -[UIViewController loadViewIfRequired] + 1198
12 UIKit 0x0000000106a9b93b -[UIViewController __viewWillAppear:] + 120
13 UIKit 0x0000000106acb750 -[UINavigationController _startCustomTransition:] + 1203
14 UIKit 0x0000000106adbb9b -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
15 UIKit 0x0000000106adcd0b -[UINavigationController __viewWillLayoutSubviews] + 57
16 UIKit 0x0000000106c8b503 -[UILayoutContainerView layoutSubviews] + 248
17 UIKit 0x00000001069b5980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
18 QuartzCore 0x000000010a2bfc00 -[CALayer layoutSublayers] + 146
19 QuartzCore 0x000000010a2b408e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
20 QuartzCore 0x000000010a2b3f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
21 QuartzCore 0x000000010a2a83c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
22 QuartzCore 0x000000010a2d6086 _ZN2CA11Transaction6commitEv + 486
23 UIKit 0x00000001068f572e _UIApplicationHandleEventQueue + 7135
24 CoreFoundation 0x00000001080dd301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
25 CoreFoundation 0x00000001080d322c __CFRunLoopDoSources0 + 556
26 CoreFoundation 0x00000001080d26e3 __CFRunLoopRun + 867
27 CoreFoundation 0x00000001080d20f8 CFRunLoopRunSpecific + 488
28 GraphicsServices 0x000000010a8a1ad2 GSEventRunModal + 161
29 UIKit 0x00000001068faf09 UIApplicationMain + 171
30 DemoAppZXing 0x0000000103f60ec2 main + 114
31 libdyld.dylib 0x000000010905492d start + 1
)
libc++abi
.dylib: terminating with uncaught exception of type NSException
Edit :
To solve this problem, i just need to set the minSize and the maxSize.
let hints = ZXEncodeHints() as ZXEncodeHints
hints.maxSize = ZXDimension.init(width: 1000, height: 1000)
hints.minSize = ZXDimension.init(width: 1, height: 1)
let result = try writer.encode(generatedStr[0], format: kBarcodeFormatDataMatrix, width: 500, height: 500, hints: hints)
The method for returning the UIImage in the final form you need:
func generateDataMatrixQRCode(from string: String) -> UIImage? {
do {
let writer = ZXMultiFormatWriter()
let hints = ZXEncodeHints() as ZXEncodeHints
let result = try writer.encode(string, format: kBarcodeFormatDataMatrix, width: 1000, height: 1000, hints: hints)
if let imageRef = ZXImage.init(matrix: result) {
if let image = imageRef.cgimage {
return UIImage.init(cgImage: image)
}
}
}
catch {
print(error)
}
return nil
}
I think thats a "generic error" not tied to Swift but rather Zebra Crossing/ZXing. Try making the rect bigger, might help.
let result = try writer.encode("foo", format: kBarcodeFormatDataMatrix, width: 1000, height: 1000, hints: hints)
I have some problems with adding an audio player to a node. For some reason, I get an exception and my application stops. Here is how my code looks like
let node = scene.rootNode.childNodeWithName("box", recursively: true)!
let source = SCNAudioSource(fileNamed: "test.mp3")
source.loops = true
source.volume = 2
source.positional = true
source.shouldStream = true
source.load()
let player = SCNAudioPlayer(source: source)
node.addAudioPlayer(player)
Can anybody help me find out what is the problem?
Edit: Exception:
2015-06-12 10:44:29.202 asd[10480:2157476] 10:44:29.202 ERROR: AVAudioNodeImpl.h:39: AVAE_CheckNodeHasEngine: required condition is false: _engine != nil
2015-06-12 10:44:29.208 asd[10480:2157476] * Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine != nil'
* First throw call stack:
(
0 CoreFoundation 0x000000010ca18885 exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010e9afdf1 objc_exception_throw + 48
2 CoreFoundation 0x000000010ca186ea +[NSException raise:format:arguments:] + 106
3 libAVFAudio.dylib 0x0000000115549efe libAVFAudio.dylib + 98046
4 libAVFAudio.dylib 0x000000011558b4fd libAVFAudio.dylib + 365821
5 libAVFAudio.dylib 0x000000011558aaa5 libAVFAudio.dylib + 363173
6 SceneKit 0x000000010d3695eb C3DTransactionFlush + 1967
7 SceneKit 0x000000010d3699e9 C3DTransactionCommit + 218
8 SceneKit 0x000000010d2f7f6e -[SCNRenderer setPointOfView:] + 4677
9 SceneKit 0x000000010d2f8c05 -[SCNRenderer setScene:completionHandler:] + 213
10 SceneKit 0x000000010d354920 -[SCNView setScene:] + 319
11 asd 0x000000010c8338b2 _TFC3asd18GameViewController11viewDidLoadfS0_FT_T_ + 2866
12 asd 0x000000010c833ba2 _TToFC3asd18GameViewController11viewDidLoadfS0_FT_T_ + 34
13 UIKit 0x000000010d7bbd65 -[UIViewController loadViewIfRequired] + 860
14 UIKit 0x000000010d7bc0b4 -[UIViewController view] + 27
15 UIKit 0x000000010d69f3d4 -[UIWindow addRootViewControllerViewIfPossible] + 61
16 UIKit 0x000000010d69fad1 -[UIWindow _setHidden:forced:] + 302
17 UIKit 0x000000011c867717 UIKit + 247575
18 UIKit 0x000000010d6b0ff8 -[UIWindow makeKeyAndVisible] + 43
19 UIKit 0x000000010d63302b -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3545
20 UIKit 0x000000010d638ef0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1755
21 UIKit 0x000000010d63673f -[UIApplication workspaceDidEndTransaction:] + 188
22 FrontBoardServices 0x0000000116052d7b FrontBoardServices + 163195
23 FrontBoardServices 0x0000000116053118 FrontBoardServices + 164120
24 CoreFoundation 0x000000010c9430f1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
25 CoreFoundation 0x000000010c938eac __CFRunLoopDoSources0 + 556
26 CoreFoundation 0x000000010c938363 __CFRunLoopRun + 867
27 CoreFoundation 0x000000010c937d78 CFRunLoopRunSpecific + 488
28 UIKit 0x000000010d636091 -[UIApplication _run] + 402
29 UIKit 0x000000010d63a79b UIApplicationMain + 171
30 asd 0x000000010c83624d main + 109
31 libdyld.dylib 0x000000010f3a0a05 libdyld.dylib + 10757
32 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Try using SCNAction. Or making sure the audio file name is correct.
let source = SCNAudioSource(fileNamed: "SoundFile.mp3")
let action = SCNAction.playAudio(source!, waitForCompletion: true)
node.runAction(action)