Gyro not working in Cocos2D enviroment - iphone

I've got a really strange problem. I have an AR app built on the cocos2D library. Recently when I first fire up xcode for the day, the gyro is not working i.e. the yaw and roll is being measured as 0 no matter how the device is oriented. It SHOULD be working based on the check I am performing in the code:
// Initialize Gyro
self.motionManager = [[[CMMotionManager alloc] init] autorelease];
motionManager.deviceMotionUpdateInterval = (1.0/60.0);
if (motionManager.isDeviceMotionAvailable) {
NSLog(#"motion available");
[motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical];
}
I've fixed this issue the past few days by commenting out some lines of stuff I am no longer using or changing something related to sprite animation on screen. The bizarre thing is I'll get it working fine for the rest of my coding session, close xcode, and the next day when I open up xcode and my project again, the gyro is once again broken.
Does anyone with more experience with cocos2d or the gyro know what could possibly be causing this?
Thanks.
UPDATE
I commented out the line
[mySprite runAction:[CCMoveTo actionWithDuration:refreshRate position:ccp(newX, newY)]];
and ran the app and the gyro worked again. What's strange though is when I uncommented that same line and ran the app again, the gyro still worked. What gives?

Just a hunch … is motionManager a retaining property?
Because if not, motionManager will be autoreleased:
self.motionManager = [[[CMMotionManager alloc] init] autorelease];

Related

UIImagePickerController CameraDevice picks wrong device every other time (using ARC)

My app takes a video (using a custom overlay, in case that's relevant) where I have the cameraDevice set to front facing camera. 3 videos need to be taken, though the cameraDevice alternates between front and rear each time the UIImpagePickerController is called to take the video. On each occasion the
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
is used within the code, though as mentioned the app ignores this command every other time.
I see this problem has been asked before, though I am using ARC so the previously suggested solutions of releasing the UIImagePickerController is not an option for me.
Thanks in advance, Jim.
You cannot release the picker in ARC but you can still create a brand new one like this:
picker = nil;
picker = [[UIImagePickerController alloc] init];
// configure picker
Notice that in Apple's sample code "Using UIImagePickerController to Select Pictures and Take Photos" they call a method each time which does exactly this.

iPod Touch iOS 5.1.1 Not calling viewDidDisappear:animated

I've posted this question elsewhere, but as SO is such a great community I'm doing so here as well.
First up, I'm using Cocos2D 2.0-gles20 to put a multiplayer/team oriented game together.
I've been integrating GameKitHelper into the app. To date it's been working just fine on my iPhone4 and iPad2 and in the Simulator, but now when I try to use it on an iPod Touch 4th I'm getting assertions in [CCDirectorIOS startAnimation] because the app is getting a viewWillAppear when it shouldn't and no call to viewDidDisappear when it should.
The reason this matters is that these methods on the CCDirectorIOS class cause Cocos2D to start/stop animation whilst another UIKit view is in front. This is something that I've managed myself with Cocos2D-0.99 but with 2.0 it is handled nicely within the director so that each app doesn't have to handle it specifically.
The GameKitHelper class has the following methods for pushing a GKMatchmakerViewController onto the screen:
-(void) showMatchmakerWithInvite:(GKInvite*)invite
{
GKMatchmakerViewController* inviteVC = [[[GKMatchmakerViewController alloc] initWithInvite:invite] autorelease];
if (inviteVC != nil)
{
inviteVC.matchmakerDelegate = self;
[self presentViewController:inviteVC];
}
}
-(UIViewController*) getRootViewController
{
return [CCDirector sharedDirector];
}
-(void) presentViewController:(UIViewController*)vc
{
UIViewController* rootVC = [self getRootViewController];
[rootVC presentModalViewController:vc animated:YES];
}
-(void) dismissModalViewController
{
UIViewController* rootVC = [self getRootViewController];
[rootVC dismissModalViewControllerAnimated:YES];
}
When I call showMatchmakerWithInvite, on the iPhone4, etc I see a call to viewDidDisappear: on the CCDirectorIOS object which stops animation. This is fine. When the GK view is gone, I see a call to viewWillAppear which restarts the animation. Sweet.
On the iPod Touch however, running exactly the same project, the call to viewDidDisappear is not made, but a call to viewWillAppear is, before the GK view has gone.
I can't fathom why there would be a difference. All devices are running iOS 5.1.1.
It's almost as if the behaviour of UIKit is different on the iPod Touch, but I find that hard to believe. My other thought was that I was looking at a timing issue, but I put some code in to allow the app to keep running even with the problem, but the call to viewDidDisappear never happened.
I can work around this I think by managing the start/stop of animation myself, but I would have preferred not to customise the Cocos2D code.
Does anyone have any ideas?
Thanks
Well, being the impatient person I am, rather than leave it to others and work on something else, I nutted it out.
I turns out that the iPod Touch devices in question had multi player games disabled in the restrictions app. This seems to cause the GK view to not show "properly" and as a result the events like viewDidDisappear: and viewWillAppear: don't occur the way I was expecting.
So I've been able to revert all of my tweaks and instrumentation in the Cocos2D code, and simply apply a correction to the GameKitHelper class to ensure that if features such as multi-player are disabled, the player isn't able to request them.

MPMoviePlayer standard interface play/pause status reflection issue

One of my components makes heavy use of MPMoviePlayerController and recently showed a weird bug; when using the standard user interface (e.g. MPMoviePlayerController.controlStyle = MPMovieControlStyleFullscreen;) the player never changes the state of the play/pause button (that thingy in the middle of my screenshot).
The functionality stays intact but the player state is not reflected by the UI.
When bringing up the controls by tapping on the screen while a movie is playing, I see a play-symbol. What I expect would be a pause-symbol as the player is currently playing. When tapping onto the play-symbol, the player goes into pause-mode. The symbol however does not change. When tapping again onto that play symbol, the player continues the playback, just as expected.
The problem has been introduced with iOS5 and did not occur on previous iOS versions.
For validating an iOS5 issues, I created a minimalistic player that is not using my own framework and sure enough the problem did not occur, hence it must be my code triggering this quirk. Unfortunately, my code is pretty damn large (about 3k lines) so I can not post it here.
I know chances of someone being able to answer this question without source code are pretty slim as it seems to be directly connected to my code. Being desperate as I am by now, I just took the chances and hope for a little wonder, somebody actually had such issue and knows how to trigger / remove it.
Well, it seems I found the answer (and what I would call an iOS5 bug)...
The reason for MPMoviePlayerController getting irritate on the status of the play button simply was the order of my initializing code.
For triggering this issue, all you have to do is run this code;
moviePlayer = [[MPMoviePlayerController alloc] init];
moviePlayer.shouldAutoplay = YES;
moviePlayer.fullscreen = NO;
moviePlayer.view.frame = self.view.bounds;
moviePlayer.currentPlaybackTime = 0.0;
moviePlayer.initialPlaybackTime = 0.0;
[moviePlayer setContentURL:[NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
[self.view addSubview:moviePlayer.view];
You will see a player UI which does not change its Pay/Pause state.
For getting things to work properly again, you have to move the setContentURL call before setting the playback-time.
moviePlayer = [[MPMoviePlayerController alloc] init];
moviePlayer.shouldAutoplay = YES;
moviePlayer.fullscreen = NO;
moviePlayer.view.frame = self.view.bounds;
[moviePlayer setContentURL:[NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]];
moviePlayer.currentPlaybackTime = 0.0;
moviePlayer.initialPlaybackTime = 0.0;
[self.view addSubview:moviePlayer.view];
I did submit a bug at Apple (Radar Bug ID# 10484668) - will keep you posted on their answer.
OpenRadar Bug Report
I also was frequently seeing this behavior, but unfortunately simply switching the order of calls to setContentURL and setting initial and playback times made no difference.
I discovered what I was doing wrong though. I was setting the playback times to -1 to indicate start of the stream when I should have been specifying zero. Changing this fixed the problem for me.

Strange EXC_BAD_INSTRUCTION using route-me on iPod

I'm getting some really strange EXC_BAD_INSTRUCTION only on iPod Touches using route-me. route-me is a library that's in my project.
Here are the details. I'm initWithFrame a Mapview.
mapView = [[RMMapView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
I get an EXC_BAD_INSTRUCTION inside initWithFrame for RMMapView:
- (id)initWithFrame:(CGRect)frame
{ //DEBUGGER STOPS HERE FOR SOME REASON
LogMethod();
if (self = [super initWithFrame:frame]) {
[self performInitialSetup];
}
return self;
}
The debugger just stops on the first {. What's even more strange is that when I view the contents of "frame" instead of being 0,0 for x,and y they are: x = 4.65449901e-10 and y = 3.5698779e-40.
What is going on here? This works fine on any other device.
Anyone have any ideas what could be going on here? I have a feeling it's some project setting that's causing me this. I don't see how the code can be an issue here.
thanks!
I figured it out. Hopefully this is helpful to others:
As I suspected the route-me project settings were incorrect. First I had to change the project to use the same iOS SDK as my main project. I also had to tell it to build ARM6 ARM7 (Standard). It was building only ARM7 (Optimized).

MPMoviePlayer crashes in device but works fine in simulator

In my app i am playing a video using the following code.
NSURL *myURL = [[NSURL alloc] initWithString:downloadURL];
mMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:myURL];
if (mMoviePlayer) {
[self initMoviePlayer];
[mMoviePlayer play];
}
This code is working fine in simulator, but when i test it in device it is giving "BAD_ACCESS" error. Device is not at all sending the request to video.
Can some one help me with this..
Thanks...
There's nothing wrong with this code. The bug is somewhere else.
BAD_ACCESS generally points to memory management issues: you're trying to access an object that has been deallocated. If you're sure that the crash is happening on the above line, double check that safeURL exists at that point. If it does, you're going to have to post more code for us to give you any pointers.