简体   繁体   中英

Getting 'Attemped to add a SKNode which already has a parent' only on physical device, no error in code, works fine on simulator

Running my app on a simulator works fine, however, running it on a physical device gives this error. I understand what this error means but my code seems fine, in fact, if I get rid of the trouble code (in this case the camera) another part of the code receives the same error.

I am targeting iOS 10.3 and running on a iOS 10.3 device, it works fine on iOS 11.0 simulator

code:

class GameScene: SKScene {

    var lastUpdateTime: TimeInterval = 0
    let pigeonCam: SKCameraNode = SKCameraNode()
    let pigeon: Pigeon = Pigeon()
    var dt = 0.0
    let ground: SKSpriteNode = SKSpriteNode(imageNamed: "Road")//crashes if camera and pigeon do not exist

    override func sceneDidLoad() {
        addChild(pigeonCam)//crashes
        camera = pigeonCam
        addChild(pigeon.pigeon)//crashes if camera code does not exist
        createGround()
        scene?.scaleMode = .resizeFill
    }

I have tried restarting the device unit/reinstalling the app but it appears to not help, aside from a few lines of code in 'pigeon' this is the entirety of my code in the app. I'm sure it's got to do with deployment settings or something of the like but I'm stumped

I have done some research, and it is quite possible the reason this is happening is because I don't have a provisioning profile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM