1

Im currently working on a SceneKit app and I've recently ran into a problem while testing it on my iPhone 5s.

I write the code below to have a block move left and right repeatedly, everything works fine.

SCNAction *mn1 = [SCNAction moveByX:-2.2 y:0 z:0 duration:1];
SCNAction *mn2 = [SCNAction moveByX:2.2 y:0 z:0 duration:1];
SCNAction *mn3 = [SCNAction waitForDuration:0.5];
SCNAction *mns = [SCNAction repeatActionForever:[SCNAction sequence:@[mn3,mn1,mn3,mn2]]];
[self.blueNode1 runAction:mns];

and in The AppDelegate.m

- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for          
certain types of temporary interruptions (such as an incoming phone call or SMS message) or when   
the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame   
rates. Games should use this method to pause the game.

SCNView *view = (SCNView *)self.window.rootViewController.view;
view.scene.paused = YES;

}

- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive.             
If the application was previously in the background, optionally refresh the user interface.

SCNView *view = (SCNView *)self.window.rootViewController.view;
view.scene.paused = NO;

}

When I enter "background/inactive mode" via the Home Button and return to my app, everything still runs smooth.

when I enter the "background" via the Power Button and wait a few seconds and return to my app. The blueNode1 will repeatedly run the action at a very fast speed for a period of time. The longer time that I spend off the app the longer the block moves at an extreme speed when I return to the App. Im not sure why this happens but its potentially a game-breaking bug.

I hope that I made my problem clear. Any help is appreciated.

EDIT: I just created a brand new test app to see if I could recreate the bug on a new project and I was able to. It didn't seem to happen while my iPhone was running the app through my Mac tho, however, As soon as I unplugged my iPhone and ran the test app through it, I was able to recreate it on the new project.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
nick
  • 101
  • 10
  • 1
    I'm not seeing this in my testing, but it's probably [a good bug to file](http://bugreport.apple.com) regardless. Possible workaround: instead of just pausing the scene, remove the action from the node when going inactive and re-add it when coming back. (That won't work so well for `moveBy` actions because you won't know where they left off when removed, but you can accomplish the same effect with `moveTo` actions instead.) – rickster Sep 12 '14 at 17:41
  • I see it every time I test for it. I considered trying to do MoveBy instead however I noticed that I have a sequence that repeats forever involving "waitforduration" and "run block" and the same issue happens with it (fires the run block code repeatedly on return to the app). However, this bug does not affect nodes that have a rotation SCNAction attached to them. I'll report the bug, just hoping that someone else would have seen it and could give me some insight. – nick Sep 13 '14 at 14:22
  • I see what you mean about removing the action and re-adding it when coming back, however my App has around 15 levels with many Nodes that have repeating actions. I suppose it could be done, but it seems very impractical to have to manage all of the Nodes that Im using in this way. – nick Sep 13 '14 at 16:49
  • Bug workarounds tend not to be well-designed solutions. – rickster Sep 13 '14 at 19:23

1 Answers1

0

Try using the paused property on SCNScene

https://developer.apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SCNScene_Class/index.html#//apple_ref/occ/instp/SCNScene/paused

It seems to actually have an effect on SCNActions unlike the pause()/play() methods on SCNView.

If you can't use that I would suggest attempting to change the speed property on all of your SCNActions, but I have not tried this.

Marc Etcheverry
  • 1,010
  • 1
  • 10
  • 15