iPhone showing Different to the Simulator - iphone

.
Hello,
First of all, this question may seem similar to my last, but it isn't. For reference if you must compare it is here Previous Question
Now I have developed an app and it runs perfectly on the iPhone Simulator. It does not use anything the Simulator cannot handle.
I have a button, generated in code and it appears on my mac in the simulator, but not on the 2 tested devices. 1) iPhone4 and the 2) iPod Touch 4th Gen.
How is that possible?
-(void)popUpMenu
{
UIImage *image = [UIImage imageNamed:#"Menu01#2x.png"];
UIImage *selectedImage = [UIImage imageNamed:#"Menu02#2x.png"];
UIImage *toggledImage = [UIImage imageNamed:#"Done01#2x.png"];
UIImage *toggledSelectedImage = [UIImage imageNamed:#"Done02#2x.png"];
NSArray *buttons = [NSArray arrayWithObjects:b1, b2, b3, b4, b5, nil];
RNExpandingButtonBar *bar = [[RNExpandingButtonBar alloc] initWithImage:image selectedImage:selectedImage toggledImage:toggledImage toggledSelectedImage:toggledSelectedImage buttons:buttons center:center];
// RNExpandingButtonBar *bar = [[UIButton buttonWithType:UIButtonTypeRoundedRect] initWithArray:buttons];
[bar setHorizontal:NO];
[bar setExplode:NO];
[self.view addSubview:bar];
[self setBar:bar];
}
The array is a set of buttons that appear from this. The link to the Github is:
Github - RNExpandingButtonBar
Then I use this code in viewDidLoad method to display the button
[self popUpMenu];
Cheers Jeff

Check the case of the image names in your code and in your workspace, the device is case sensitive and OSX by default is not. Thats why it is working in your simulator and not on your device.

Related

Image Saving to Albums working fine in Simulator but gives EXC_BAD_EXCESS on device

I want to save an image into albums.
I am doing it using UIImageWriteToSavedPhotosAlbum API.
Its working perfectly fine on Simulator, but crashes on Device giving EXC_BAD_EXCESS.
I have enables NSZombi.. argument, but it shows no log of any deallocated memory reused.
- (IBAction)saveImageOnHDButtonPressed:(id)sender{
NSArray *subviews = [scroll subviews];
UIImage *img = [[subviews objectAtIndex:0] image];
UIImageWriteToSavedPhotosAlbum(img, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
}
Please help..
Thanks
Try retaining the image before you save it.

CCMenu doesnt work in iPad

I'm creating an universal application and my CCMenu appears just fine on both iPhone, iPhone 4 and iPad. However the buttons do nothing when touched on the iPad.
I have no specific iPad code other than modifying the contentScaling property so that the iPad uses the same images as the iPhone 4. This means that the same images work on iPhone 4 but not on the iPad.
I am using cocos2d 0.99.rc0 and the iOS 4.1 SDK. I don't even know where to start troubleshooting this.
The only oddity i noticed recently is that the iPad seems to draw the menu scene once, then quickly redraws it for some reason, moving everything one pixel or something. My menu class is very simple and has no "refreshing" code or anything that is supposed to move. This doesnt happen on either low or high res iPhones.
Here is my code, sloppy but yet very simple.
MainMenu.m:
CCMenuItemImage * playItem = [self makeMenuButtonWithSprite:#"Play.png" withSelector:#selector(play:)];
CCMenuItemImage * resumeItem = [self makeMenuButtonWithSprite:#"Resume.png" withSelector:#selector(resume:)];
CCMenuItemImage * optionsItem = [self makeMenuButtonWithSprite:#"Options.png" withSelector:#selector(options:)];
CCMenuItemImage * helpItem = [self makeMenuButtonWithSprite:#"Help.png" withSelector:#selector(help:)];
CCMenu *myMenu;
// Check if there is a valid savegame by comparing versions.
if ([[uD stringForKey:#"CFBundleVersion"] isEqualToString:[[NSBundle mainBundle] objectForInfoDictionaryKey:#"CFBundleVersion"]] ) {
myMenu = [CCMenu menuWithItems:playItem, resumeItem, optionsItem, helpItem, nil];
} else {
myMenu = [CCMenu menuWithItems:playItem, optionsItem, helpItem, nil];
}
// Arrange the menu items vertically
[myMenu alignItemsVerticallyWithPadding:0.0f];
myMenu.position = ccp(dB.wWidth/2,dB.wHeight/2);
// add the menu to your scene
[self addChild:myMenu z:100];
And the CCMenuItemImage factory:
- (CCMenuItemImage *)makeMenuButtonWithSprite:(NSString *)spriteFileName withSelector:(SEL)selector {
CCSprite *spriteForButton = [CCSprite spriteWithFile:spriteFileName];
spriteForButton.anchorPoint = ccp(0.5f,0.5f);
CCMenuItemImage * buttonImage =[CCMenuItemImage itemFromNormalImage:#"button.png"
selectedImage: #"button.png"
target:self
selector:selector];
[buttonImage addChild:spriteForButton z:100];
spriteForButton.position = ccp([buttonImage boundingBox].size.width/2,([buttonImage boundingBox].size.height/2)-5);
return buttonImage;
}
I don't think that any known bug exists for this issue. Not sure how to debug this without seeing any code, but, if it helps, here's some code of mine that successfully adds a menu using cocos2d 0.99.5, on iOS 4.0, 4.1 and 4.2 (no difference when I upgraded):
-(void) initBottomMenu {
CCMenuItem *aboutButton = [self gameButtonWithName:#"about" selector:#selector(onAbout:)];
CCMenuItem *settingsButton = [self gameButtonWithName:#"settings" selector:#selector(onSettings:)];
CCMenuItem *tutButton = [self gameButtonWithName:#"tutorial" selector:#selector(onTutorial:)];
CCMenu *menu = [CCMenu menuWithItems:aboutButton, settingsButton, tutButton, nil];
menu.position = ccp(xPos, yPos);
[menu alignItemsHorizontallyWithPadding:45.0];
[self addChild:menu];
}
The gameButtonWithName:selector: method looks like this:
-(CCMenuItem *) gameButtonWithName:(NSString *)name selector:(SEL)s {
NSString *iPadSuffix = #"IPad";
NSString *normal = [[NSString alloc] initWithFormat:#"%#Btn%#.png", name, iPadSuffix, nil] ;
NSString *selected = [[NSString alloc] initWithFormat:#"%#Btn%#.png", name, iPadSuffix, nil];
CCMenuItem *retButton = [CCMenuItemImage itemFromNormalImage:normal
selectedImage:selected
disabledImage:selected
target:self
selector:s];
[selected release];
[normal release];
return retButton;
}
sort of sloppy, but it works out well for adding a menu to my main scene.
Problem found. This was related to my custom hack to make the iPad load retina graphics. The problem was in my appDelegate where i set the contentScaleFactor which made ccDirector scale and UIScreen scale mismatch.
Problem boiled down to graphics being big but cocos2d thinking that coordinates are low res.

iPhone FBConnectDialog box disappears

So I've been trying to integrate FB with my iPhone application with FB connect. However, after using the tutorial (http://www.mobisoftinfotech.com/blog/iphone/iphone-fbconnect-facebook-connect-tutorial/), it seems when the FBDialog box is called, it pops onto the screen for a few seconds and then disappears. I'm not sure what is going, becuase IT WORKS in the Simulator perfectly. I have an iPhone 4 device. Here is my code below:
(void)viewDidLoad {
[super viewDidLoad];
session = [[FBSession sessionForApplication:#"MYAPIKEY" secret:#"MYSECRET" delegate:self] retain];
FBLoginButton *button = [[[FBLoginButton alloc] init] autorelease];
[button setFrame:CGRectMake(100, 100, 100, 50)];
[self.view addSubview:button];
}
Nevermind, I'm sorry for being a noob. Turns out my three hour struggle to figure this out was a complete waste. The problem -- my iPhone wasn't connected to Wifi/cell network.

Free memory after iphone animation

My app crashes due to memory building up after every animation.
Here is my sample code:
-(IBAction) shoot: (id)delegate{
[gun setImage:[UIImage imageNamed:#"animation_machin_guns_320x480_7.png"]];
UIImage *frame1 = [UIImage imageNamed:#"animation_machin_guns_320x480_1.png"];
UIImage *frame2 = [UIImage imageNamed:#"animation_machin_guns_320x480_2.png"];
UIImage *frame3 = [UIImage imageNamed:#"animation_machin_guns_320x480_3.png"];
UIImage *frame4 = [UIImage imageNamed:#"animation_machin_guns_320x480_4.png"];
UIImage *frame5 = [UIImage imageNamed:#"animation_machin_guns_320x480_5.png"];
UIImage *frame6 = [UIImage imageNamed:#"animation_machin_guns_320x480_6.png"];
UIImage *frame7 = [UIImage imageNamed:#"animation_machin_guns_320x480_7.png"];
gun.animationImages = [[NSArray alloc] initWithObjects:frame1, frame2, frame3, frame4, frame5, frame6, frame7,nil];
gun.animationDuration = 1;
gun.animationRepeatCount = 1;
[gun startAnimating];
[frame1 release];
[frame2 release];
[frame3 release];
[frame4 release];
[frame5 release];
[frame6 release];
[frame7 release];}
Releasing the frames doesn't seem to do the magic.
I tried using this http://kosmaczewski.net/projects/iphone-image-cache/ for image caching but i guess I don't know how to use it properly since the memory builds up faster than using imageNamed.
Replace [[NSArray alloc] initWithObjects:xxx]; with [NSArray arrayWithObjects:xxx];.
Currently, the array object is being retained twice (once effectively by alloc and once by gun.animationImages = xxx), but only released once (when the gun object is released, or the animationImages property is set to something new), meaning it will never be released.
The arrayWithObjects method returns an autoreleased object, meaning it doesn't need to be manually released by you.
If I were you I would think about only animating parts of the screen or perhaps compressing the images into low quality jpgs or something along those lines.

iPhone app memory leak with UIImage animation? Problem testing on device

I have an animation which works fine in the simulator but crashes on the device. I am getting the following error...
Program received signal: “0”.
The Debugger has exited due to signal 10 (SIGBUS)
A bit of investigating suggests that the UIImages are not getting released and I have a memory leak. I am new to this so can someone tell me if this is the likely cause? If you could also tell me how to solve it then that would be amazing.
The images are 480px x 480px and about 25kb each. My code is below...
NSArray *rainImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"rain-loop0001.png"],
[UIImage imageNamed:#"rain-loop0002.png"],
[UIImage imageNamed:#"rain-loop0003.png"],
[UIImage imageNamed:#"rain-loop0004.png"],
[UIImage imageNamed:#"rain-loop0005.png"],
[UIImage imageNamed:#"rain-loop0006.png"],
//more looping images
[UIImage imageNamed:#"rain-loop0045.png"],
[UIImage imageNamed:#"rain-loop0046.png"],
[UIImage imageNamed:#"rain-loop0047.png"],
[UIImage imageNamed:#"rain-loop0048.png"],
[UIImage imageNamed:#"rain-loop0049.png"],
[UIImage imageNamed:#"rain-loop0050.png"],
nil];
rainImage.animationImages = rainImages;
rainImage.animationDuration = 4.15/2;
rainImage.animationRepeatCount = 0;
[rainImage startAnimating];
[rainImage release];
Thanks
I'm pretty sure you're crashing because [NSArray arrayWithObjects:] returns an auto-released object which you're storing to rainImage. Then at the bottom you're releasing rainImage again, thus over releasing it.
The root of the problem is that you are running out of main memory because you have too many decompressed images in memory, see my answer to uiimage-animation-causing-app-to-crash-memory-leaks for the reason you should not be using UIImageView.animationImages.