SpriteKit library BUG: battery drain (Energy Impact is High / Very High) [WORKAROUND]










1















I understand that stackoverflow is rather a question-answer informational resource, but I also believe its core idea is solution sharing in the first place. And, as I found a tricky bug in Apple's SpriteKit library, and a workaround for that bug, I share the solution with you.



Also, I filed a bug report to Apple via https://bugreport.apple.com/, but the 1-trillion company seem not to care much - it's been almost two weeks since the report, and the bug is still open, and not a single comment / update was given from the Apple crew.



TLDR;



SpriteKit goes into enormous energy consumption if your game supports landscape mode only, and the order of UISupportedInterfaceOrientations landscape values in your Info.plist file is 'wrong' (!). If UIInterfaceOrientationLandscapeRight goes first and UIInterfaceOrientationLandscapeLeft goes second - you are in trouble.



The workaround is:



  1. Select your Info.plist in the project navigator -> Open As -> Source Code. Find the key: UISupportedInterfaceOrientations


  2. Make sure the order of values is the following:


(LandscapeLeft goes FIRST)



<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>


That's it.



BUG REPRODUCE STEPS



(for those only who are curious and have some extra free time)




  1. Launch XCode, create a brand new project of type 'Game'



    • language: Swift

    • game technology: SpriteKit

    • uncheck Integrate GamePlayKit

    • uncheck Include Unit Tests

    • uncheck Include UI Tests



  2. In target general settings



    • uncheck Device Orientation: Portrait

    • check Requires full screen


  3. Remove files: GameScene.sks, Actions.sks (Move to trash)


  4. Replace the content of GameScene.swift with the following


code:



import SpriteKit

class GameScene: SKScene

fileprivate let nodeSizeUnit: CGFloat = 50

override func didMove(to view: SKView)
let layer = getLayer()
let nodeWithBody = getItemWithBody()

layer.addChild(nodeWithBody)
addChild(layer)


fileprivate func getLayer() -> SKNode
let layerSize = CGSize(width: nodeSizeUnit * 3, height: nodeSizeUnit * 3)
let layer = SKSpriteNode(texture: nil, color: UIColor.blue, size: layerSize)
layer.position = CGPoint(x: size.width / 2, y: size.height / 2)

return layer


fileprivate func getItemWithBody() -> SKNode
let bodySize = CGSize(width: nodeSizeUnit, height: nodeSizeUnit)
let body = SKPhysicsBody(rectangleOf: bodySize)

body.isDynamic = false
body.affectedByGravity = false
body.categoryBitMask = 0
body.collisionBitMask = 0
body.contactTestBitMask = 0

let item = SKSpriteNode(texture: nil,
color: SKColor.gray,
size: CGSize(width: nodeSizeUnit * 2, height: nodeSizeUnit * 2))
item.physicsBody = body

return item




  1. Replace the content of GameViewController with the following

code:



import SpriteKit

class GameViewController: UIViewController

override func viewDidLoad()
super.viewDidLoad()

if let view = self.view as! SKView?
let scene = GameScene()
scene.size = UIScreen.main.nativeBounds.size
scene.scaleMode = .aspectFill
view.presentScene(scene)

view.ignoresSiblingOrder = true

view.showsPhysics = true
view.showsFPS = true
view.showsNodeCount = true
view.showsDrawCount = true





  1. Connect a physical device available, run the build on that device. Make sure to set build's Deployment Target according to you device.

UPD: Make sure the device iOS is -below- 12.0, otherwise you'll get high energy impact regardless of UISupportedInterfaceOrientations parameters order. Looks like SpriteKit has even another, iOS-version-related, energy consumption bug.



  1. Go to the Debug Navigator (Cmd + 7), switch to the Energy Impact section. The average Energy Impact is low. Fine at this point.


  2. Stop the build, go to target settings. uncheck Device Orientation: Landscape Left. Aaaand check it again. Yes, you read it right: first uncheck, then check. Now, you are doomed.


  3. Run the build, go to the Debug Navigator (Cmd + 7), switch to the Energy Imact section. Now, it grows frorm 'Low' to 'High' in a blink of an eye, and ends up 'Very High'. How cool is that?


  4. Stop the build. Select your Info.plist in the project navigator -> Open As -> Source Code. Find the key: UISupportedInterfaceOrientations. You'll see the following:


(LandscapeLeft goes SECOND):



<array>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>


change it to:



<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>


(LandscapeLeft goes FIRST)



  1. Run the build, go to the Debug Navigator (Cmd + 7), switch to the Energy Impact section. The average Energy Impact is low. Yay.

You can play the UISupportedInterfaceOrientations key yourself, changing the order of params and watching the energy impact change accordingly.










share|improve this question


























    1















    I understand that stackoverflow is rather a question-answer informational resource, but I also believe its core idea is solution sharing in the first place. And, as I found a tricky bug in Apple's SpriteKit library, and a workaround for that bug, I share the solution with you.



    Also, I filed a bug report to Apple via https://bugreport.apple.com/, but the 1-trillion company seem not to care much - it's been almost two weeks since the report, and the bug is still open, and not a single comment / update was given from the Apple crew.



    TLDR;



    SpriteKit goes into enormous energy consumption if your game supports landscape mode only, and the order of UISupportedInterfaceOrientations landscape values in your Info.plist file is 'wrong' (!). If UIInterfaceOrientationLandscapeRight goes first and UIInterfaceOrientationLandscapeLeft goes second - you are in trouble.



    The workaround is:



    1. Select your Info.plist in the project navigator -> Open As -> Source Code. Find the key: UISupportedInterfaceOrientations


    2. Make sure the order of values is the following:


    (LandscapeLeft goes FIRST)



    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>


    That's it.



    BUG REPRODUCE STEPS



    (for those only who are curious and have some extra free time)




    1. Launch XCode, create a brand new project of type 'Game'



      • language: Swift

      • game technology: SpriteKit

      • uncheck Integrate GamePlayKit

      • uncheck Include Unit Tests

      • uncheck Include UI Tests



    2. In target general settings



      • uncheck Device Orientation: Portrait

      • check Requires full screen


    3. Remove files: GameScene.sks, Actions.sks (Move to trash)


    4. Replace the content of GameScene.swift with the following


    code:



    import SpriteKit

    class GameScene: SKScene

    fileprivate let nodeSizeUnit: CGFloat = 50

    override func didMove(to view: SKView)
    let layer = getLayer()
    let nodeWithBody = getItemWithBody()

    layer.addChild(nodeWithBody)
    addChild(layer)


    fileprivate func getLayer() -> SKNode
    let layerSize = CGSize(width: nodeSizeUnit * 3, height: nodeSizeUnit * 3)
    let layer = SKSpriteNode(texture: nil, color: UIColor.blue, size: layerSize)
    layer.position = CGPoint(x: size.width / 2, y: size.height / 2)

    return layer


    fileprivate func getItemWithBody() -> SKNode
    let bodySize = CGSize(width: nodeSizeUnit, height: nodeSizeUnit)
    let body = SKPhysicsBody(rectangleOf: bodySize)

    body.isDynamic = false
    body.affectedByGravity = false
    body.categoryBitMask = 0
    body.collisionBitMask = 0
    body.contactTestBitMask = 0

    let item = SKSpriteNode(texture: nil,
    color: SKColor.gray,
    size: CGSize(width: nodeSizeUnit * 2, height: nodeSizeUnit * 2))
    item.physicsBody = body

    return item




    1. Replace the content of GameViewController with the following

    code:



    import SpriteKit

    class GameViewController: UIViewController

    override func viewDidLoad()
    super.viewDidLoad()

    if let view = self.view as! SKView?
    let scene = GameScene()
    scene.size = UIScreen.main.nativeBounds.size
    scene.scaleMode = .aspectFill
    view.presentScene(scene)

    view.ignoresSiblingOrder = true

    view.showsPhysics = true
    view.showsFPS = true
    view.showsNodeCount = true
    view.showsDrawCount = true





    1. Connect a physical device available, run the build on that device. Make sure to set build's Deployment Target according to you device.

    UPD: Make sure the device iOS is -below- 12.0, otherwise you'll get high energy impact regardless of UISupportedInterfaceOrientations parameters order. Looks like SpriteKit has even another, iOS-version-related, energy consumption bug.



    1. Go to the Debug Navigator (Cmd + 7), switch to the Energy Impact section. The average Energy Impact is low. Fine at this point.


    2. Stop the build, go to target settings. uncheck Device Orientation: Landscape Left. Aaaand check it again. Yes, you read it right: first uncheck, then check. Now, you are doomed.


    3. Run the build, go to the Debug Navigator (Cmd + 7), switch to the Energy Imact section. Now, it grows frorm 'Low' to 'High' in a blink of an eye, and ends up 'Very High'. How cool is that?


    4. Stop the build. Select your Info.plist in the project navigator -> Open As -> Source Code. Find the key: UISupportedInterfaceOrientations. You'll see the following:


    (LandscapeLeft goes SECOND):



    <array>
    <string>UIInterfaceOrientationLandscapeRight</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    </array>


    change it to:



    <array>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
    </array>


    (LandscapeLeft goes FIRST)



    1. Run the build, go to the Debug Navigator (Cmd + 7), switch to the Energy Impact section. The average Energy Impact is low. Yay.

    You can play the UISupportedInterfaceOrientations key yourself, changing the order of params and watching the energy impact change accordingly.










    share|improve this question
























      1












      1








      1








      I understand that stackoverflow is rather a question-answer informational resource, but I also believe its core idea is solution sharing in the first place. And, as I found a tricky bug in Apple's SpriteKit library, and a workaround for that bug, I share the solution with you.



      Also, I filed a bug report to Apple via https://bugreport.apple.com/, but the 1-trillion company seem not to care much - it's been almost two weeks since the report, and the bug is still open, and not a single comment / update was given from the Apple crew.



      TLDR;



      SpriteKit goes into enormous energy consumption if your game supports landscape mode only, and the order of UISupportedInterfaceOrientations landscape values in your Info.plist file is 'wrong' (!). If UIInterfaceOrientationLandscapeRight goes first and UIInterfaceOrientationLandscapeLeft goes second - you are in trouble.



      The workaround is:



      1. Select your Info.plist in the project navigator -> Open As -> Source Code. Find the key: UISupportedInterfaceOrientations


      2. Make sure the order of values is the following:


      (LandscapeLeft goes FIRST)



      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationLandscapeRight</string>


      That's it.



      BUG REPRODUCE STEPS



      (for those only who are curious and have some extra free time)




      1. Launch XCode, create a brand new project of type 'Game'



        • language: Swift

        • game technology: SpriteKit

        • uncheck Integrate GamePlayKit

        • uncheck Include Unit Tests

        • uncheck Include UI Tests



      2. In target general settings



        • uncheck Device Orientation: Portrait

        • check Requires full screen


      3. Remove files: GameScene.sks, Actions.sks (Move to trash)


      4. Replace the content of GameScene.swift with the following


      code:



      import SpriteKit

      class GameScene: SKScene

      fileprivate let nodeSizeUnit: CGFloat = 50

      override func didMove(to view: SKView)
      let layer = getLayer()
      let nodeWithBody = getItemWithBody()

      layer.addChild(nodeWithBody)
      addChild(layer)


      fileprivate func getLayer() -> SKNode
      let layerSize = CGSize(width: nodeSizeUnit * 3, height: nodeSizeUnit * 3)
      let layer = SKSpriteNode(texture: nil, color: UIColor.blue, size: layerSize)
      layer.position = CGPoint(x: size.width / 2, y: size.height / 2)

      return layer


      fileprivate func getItemWithBody() -> SKNode
      let bodySize = CGSize(width: nodeSizeUnit, height: nodeSizeUnit)
      let body = SKPhysicsBody(rectangleOf: bodySize)

      body.isDynamic = false
      body.affectedByGravity = false
      body.categoryBitMask = 0
      body.collisionBitMask = 0
      body.contactTestBitMask = 0

      let item = SKSpriteNode(texture: nil,
      color: SKColor.gray,
      size: CGSize(width: nodeSizeUnit * 2, height: nodeSizeUnit * 2))
      item.physicsBody = body

      return item




      1. Replace the content of GameViewController with the following

      code:



      import SpriteKit

      class GameViewController: UIViewController

      override func viewDidLoad()
      super.viewDidLoad()

      if let view = self.view as! SKView?
      let scene = GameScene()
      scene.size = UIScreen.main.nativeBounds.size
      scene.scaleMode = .aspectFill
      view.presentScene(scene)

      view.ignoresSiblingOrder = true

      view.showsPhysics = true
      view.showsFPS = true
      view.showsNodeCount = true
      view.showsDrawCount = true





      1. Connect a physical device available, run the build on that device. Make sure to set build's Deployment Target according to you device.

      UPD: Make sure the device iOS is -below- 12.0, otherwise you'll get high energy impact regardless of UISupportedInterfaceOrientations parameters order. Looks like SpriteKit has even another, iOS-version-related, energy consumption bug.



      1. Go to the Debug Navigator (Cmd + 7), switch to the Energy Impact section. The average Energy Impact is low. Fine at this point.


      2. Stop the build, go to target settings. uncheck Device Orientation: Landscape Left. Aaaand check it again. Yes, you read it right: first uncheck, then check. Now, you are doomed.


      3. Run the build, go to the Debug Navigator (Cmd + 7), switch to the Energy Imact section. Now, it grows frorm 'Low' to 'High' in a blink of an eye, and ends up 'Very High'. How cool is that?


      4. Stop the build. Select your Info.plist in the project navigator -> Open As -> Source Code. Find the key: UISupportedInterfaceOrientations. You'll see the following:


      (LandscapeLeft goes SECOND):



      <array>
      <string>UIInterfaceOrientationLandscapeRight</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      </array>


      change it to:



      <array>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationLandscapeRight</string>
      </array>


      (LandscapeLeft goes FIRST)



      1. Run the build, go to the Debug Navigator (Cmd + 7), switch to the Energy Impact section. The average Energy Impact is low. Yay.

      You can play the UISupportedInterfaceOrientations key yourself, changing the order of params and watching the energy impact change accordingly.










      share|improve this question














      I understand that stackoverflow is rather a question-answer informational resource, but I also believe its core idea is solution sharing in the first place. And, as I found a tricky bug in Apple's SpriteKit library, and a workaround for that bug, I share the solution with you.



      Also, I filed a bug report to Apple via https://bugreport.apple.com/, but the 1-trillion company seem not to care much - it's been almost two weeks since the report, and the bug is still open, and not a single comment / update was given from the Apple crew.



      TLDR;



      SpriteKit goes into enormous energy consumption if your game supports landscape mode only, and the order of UISupportedInterfaceOrientations landscape values in your Info.plist file is 'wrong' (!). If UIInterfaceOrientationLandscapeRight goes first and UIInterfaceOrientationLandscapeLeft goes second - you are in trouble.



      The workaround is:



      1. Select your Info.plist in the project navigator -> Open As -> Source Code. Find the key: UISupportedInterfaceOrientations


      2. Make sure the order of values is the following:


      (LandscapeLeft goes FIRST)



      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationLandscapeRight</string>


      That's it.



      BUG REPRODUCE STEPS



      (for those only who are curious and have some extra free time)




      1. Launch XCode, create a brand new project of type 'Game'



        • language: Swift

        • game technology: SpriteKit

        • uncheck Integrate GamePlayKit

        • uncheck Include Unit Tests

        • uncheck Include UI Tests



      2. In target general settings



        • uncheck Device Orientation: Portrait

        • check Requires full screen


      3. Remove files: GameScene.sks, Actions.sks (Move to trash)


      4. Replace the content of GameScene.swift with the following


      code:



      import SpriteKit

      class GameScene: SKScene

      fileprivate let nodeSizeUnit: CGFloat = 50

      override func didMove(to view: SKView)
      let layer = getLayer()
      let nodeWithBody = getItemWithBody()

      layer.addChild(nodeWithBody)
      addChild(layer)


      fileprivate func getLayer() -> SKNode
      let layerSize = CGSize(width: nodeSizeUnit * 3, height: nodeSizeUnit * 3)
      let layer = SKSpriteNode(texture: nil, color: UIColor.blue, size: layerSize)
      layer.position = CGPoint(x: size.width / 2, y: size.height / 2)

      return layer


      fileprivate func getItemWithBody() -> SKNode
      let bodySize = CGSize(width: nodeSizeUnit, height: nodeSizeUnit)
      let body = SKPhysicsBody(rectangleOf: bodySize)

      body.isDynamic = false
      body.affectedByGravity = false
      body.categoryBitMask = 0
      body.collisionBitMask = 0
      body.contactTestBitMask = 0

      let item = SKSpriteNode(texture: nil,
      color: SKColor.gray,
      size: CGSize(width: nodeSizeUnit * 2, height: nodeSizeUnit * 2))
      item.physicsBody = body

      return item




      1. Replace the content of GameViewController with the following

      code:



      import SpriteKit

      class GameViewController: UIViewController

      override func viewDidLoad()
      super.viewDidLoad()

      if let view = self.view as! SKView?
      let scene = GameScene()
      scene.size = UIScreen.main.nativeBounds.size
      scene.scaleMode = .aspectFill
      view.presentScene(scene)

      view.ignoresSiblingOrder = true

      view.showsPhysics = true
      view.showsFPS = true
      view.showsNodeCount = true
      view.showsDrawCount = true





      1. Connect a physical device available, run the build on that device. Make sure to set build's Deployment Target according to you device.

      UPD: Make sure the device iOS is -below- 12.0, otherwise you'll get high energy impact regardless of UISupportedInterfaceOrientations parameters order. Looks like SpriteKit has even another, iOS-version-related, energy consumption bug.



      1. Go to the Debug Navigator (Cmd + 7), switch to the Energy Impact section. The average Energy Impact is low. Fine at this point.


      2. Stop the build, go to target settings. uncheck Device Orientation: Landscape Left. Aaaand check it again. Yes, you read it right: first uncheck, then check. Now, you are doomed.


      3. Run the build, go to the Debug Navigator (Cmd + 7), switch to the Energy Imact section. Now, it grows frorm 'Low' to 'High' in a blink of an eye, and ends up 'Very High'. How cool is that?


      4. Stop the build. Select your Info.plist in the project navigator -> Open As -> Source Code. Find the key: UISupportedInterfaceOrientations. You'll see the following:


      (LandscapeLeft goes SECOND):



      <array>
      <string>UIInterfaceOrientationLandscapeRight</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      </array>


      change it to:



      <array>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationLandscapeRight</string>
      </array>


      (LandscapeLeft goes FIRST)



      1. Run the build, go to the Debug Navigator (Cmd + 7), switch to the Energy Impact section. The average Energy Impact is low. Yay.

      You can play the UISupportedInterfaceOrientations key yourself, changing the order of params and watching the energy impact change accordingly.







      ios sprite-kit






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 12:26









      Yaroslav YaremenkoYaroslav Yaremenko

      142




      142






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280993%2fspritekit-library-bug-battery-drain-energy-impact-is-high-very-high-workar%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280993%2fspritekit-library-bug-battery-drain-energy-impact-is-high-very-high-workar%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党