手机数码

IPad Crashes when iPhone 3G and iPhone4 does not work

微信扫一扫,分享到朋友圈

IPad Crashes when iPhone 3G and iPhone4 does not work
0

I think this is a memory issue, but i’m unsure on what to do here.

My issue:

I’ve nearly finished a game using cocos2d for the iphone, with retina gfx, I’ve made the app universal, and have done adjustments to make it run correctly on the iPad, mostly I use the retina spritesheets on the ipad, with a few additional images (contained inside the -hd spritesheets) to cover the edges of the screen etc.

Everything is working fine, the iPad, when in the game runs at 60fps, like on the iphone4 (i usually get about 40-50fps on iphone3g), however, occasionally, after 5 minutes or so of moving between menus on the iPad (generally, but not always, after unloading the game engine and moving back to the menus), the game falls over.

In the debugger, i get ‘Received memory warning.’, shortly after (not immediately), when a new spritesheet or graphic is loaded (not creation of a sprite, but the actually loading of a new texture into memory), the app closes and all that I get in the console is ‘(gdb)’ with no stacktrace.

I’m struggling to find a solution, when moving from my game engine to my menus, I have a loading screen, which is mostly created using 1 full screen image, and some text, all other textures, spriteframes and preloaded soundfx are then purged from memory before anything new is loaded in.

I’ve attempted to run the ipad with leaks and allocations on in instruments, but as soon as the app loads, instruments crashes every time.

Does anyone happen to know what the max memory space is for an ipad app before it closes (i thought i’d atleast get 3 warnings, not 1), and how many 2048 x 2048 sheets does that equate too?

EDIT: (New cause of irrational memory disappearance discovered!)

So, weeks later, I stumble onto this post on the cocos2d forums.

http://www.cocos2d-iphone.org/forum/topic/31092

This bug in iOS5 is likely to be the main cause of my troubles, all advice and suggestions have helped, in my opinion, to tighten up my app as a whole.

For consuming less memory. Use the CCTextureCache. Remember that Cocos2D always saves images with a width/height being a power of 2. So if your image is 513 pixels it’ll use an image with 1024 pixels.

CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:@"randomImage.png"];
CCSprite *randomImage = [CCSprite spriteWithTexture:texture];

For saving even more memory you can look into using Texture Atlases. Whenever you switch to a menu or game you can call removeUnusedTextures (or when outofmemory get called).

[[CCTextureCache sharedTextureCache] removeUnusedTextures];

You can also use images in a lower quality to save memory.

[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA4444];

Whenever you need to load higher quality images or gradients you can put it back.

[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

阅读原文...


微信扫一扫,分享到朋友圈

IPad Crashes when iPhone 3G and iPhone4 does not work
0

Hello, buddy!

SWF in WPF control WebBrowser - Accepts automatic access camera / microphone?

上一篇

New APT Could Signal Reemergence of Notorious Comment Crew

下一篇

评论已经被关闭。

插入图片

热门分类

IPad Crashes when iPhone 3G and iPhone4 does not work

长按储存图像,分享给朋友