I am working on a sort of big project. And I have been facing a fatal problem at the end of the day of the project. I guess it might be from memory leak, anyways please listen to my voice.
The first time I launch the program, it works fine. and I play it for about an hour, then when it moves to next scene (this means destroy all things from the memory and load new things on the memory).
I got a error log saying
HeapPool:Init() : can't allocate 33554448 bytes"
Can't Create 2048x2048 texture..
something like that.
After the message, textures are gone. I mean the world (in the game) is black. No textures.
Is this problem related to video memory card? physical memory? or virtual memory? I am not an expert about it.
Anyone can give me an hint? Please, I need anything. Thanks.
It seems you are out of memory, most modern graphics cards can support a 2048 x 2048 texture, anyway, you can check it in DirectX Caps Viewer.
Related
I've been trying to find out for the last 2 days why even after I tell cocos2d to remove textureatlas
it keeps holding memory.
I have no leeks on intruments, I'm debbuging inside CCTextureCache class and it removes just time
I've tried all the obvious ways to remove texture atlas from cache ex: [[CCDirector sharedDirector] purgeCachedData]; with no success
I'm very hopeless, any help?
Edit:
I'm having the same problem than this guy LINK , my game has 1 texture atlas for each level and I repeat the player sprites each image texture atlas files which works great.
my idea was having about up to 30 levels in the game, where it would cost disk space and Assuming I was able to free the memory from the previous texture atlas belonging to the previous level, it would work just fine.
but because I can't find a way to free the memory, the game consumes lots of memory in the 5th level.... it is very frustrating.
any tips are appreciated, thanks
Edit:
I found out what is going on, I have some animations that executed a selector at the end of it. I can't remove those selectors, or if I do, I will have to work a lot. I'm pretty upset because the removeallselectors method just doesnt work
I need a help or an advice with SprikeKit. My app/game passed Apple review, but later I got some complaints regarding graphics (big red X). I am using spriteNodeWithImageNamed for loading pictures. Is it any way to find out if the picture was loaded? I'm sure that the picture does exist. Probably, the problem is related to a memory or something else. If I put the wrong picture name in Xcode I see error output and red x but how can I catch the error - #try/#catch does not help in this case. Any inputs, hints are very appreciated.
xcode 5, iPad air
Are you trying to load any very large textures? The max texture size for different models of iDevices vary - perhaps that's what you're running into. If you try to load a texture that's too large for a particular device, it might fall back to that X graphic.
As far as detecting whether the texture didn't load, I don't know a way to do that, but you might be able to ensure that it loads by using SKTexture's preloadWithCompletionHandler: method to make sure it's loaded.
Also, Apple recommends not loading textures on the fly, especially if you're loading many of them in a short time span, and carefully managing texture memory by discarding SKTextures that you no longer need. Do some preloading, and check that you're not keeping textures around that you don't need, and see if the X icons go away.
I'm having a performance issue regarding Apple Spritekit Framework.
I use the method preloadTextureAtlases:withCompletionHandler: of SKTextureAtlas to make sure all my textures are loaded before the game really starts.
Yet when the first texture of this atlas (whatever it is) is added to the scene as a child I got a small lag, like if the texture wasn't loaded. It only happens the first time.
I tried real hard to debug this and to find the reason but I couldn't find it. Looking with Instrument and the Time Profiler I got this
Which seems strange since my texture atlas contains all the allocated textures (and they are still allocated). Why does it call a load method ? Maybe it's something related to OpenGL like the texture binding.
I'm sure this correspond to the frame where my object is allocated (see the spike on the right). Nothing else is allocated or in motion here.
I'm really stuck on this and any help would be deeply appreciated.
Thanks for your time.
I have an iOS opengl es 2.0 app that needs to use a TON of large textures. Ideally 4096x4096. I have a struct array that contains all the info about the texture, and as I need to use each one I glGenTextures a new texture id and load the image there, free up the uiimage, etc. That all works great.
My app uses a bunch of textures for UI, image processing, etc. About 4-5 of the 15 I'm using for all of that are 4k x 4k. Rest are smaller. And then these load-as-needed textures are also 4k.
On loading about the 4th-5th of those the app crashes HARD. No console or debug. Just quits to the springboard in the middle of trying to load the next texture.
I don't have a memory leak - I ran instruments. I'm using ARC. I can post the crash report from the Organizer but it doesn't have much info. Just that my app's rpages was 170504.
I could post the image load code but its the same code I've used on all my apps for years. The new thing is pushing the system that hard and trying to load that many large textures.
Q1: Anyone have experience with using a ton of large textures?
So I resolved to the fact that I'll have to do preview res stuff at 1024x1024 and then final res stuff at 4096. The 1k images are now loading as needed and staying loaded. The 4k images will all be loaded one at a time into the same texture to be used and then move on to the next.
I wrote into my image loader a preview parameter and when set it shrinks the image to fit in 1024 during the load. Now Instead of crashing on the 4th or 5th I can add textures 'all day'. My GUESS is that I could do 16x as many as before. But I only need like 20-30 at a time. (only!) So far I've tried 20 with no memory warnings or crashes.
However.. if the app keeps running, because my textures are loaded at unique texture ids, at some point I would hit that spot where I need to unload one that's no longer needed to load the next one. This is probably very simple, but....
Q2: How do I free up a texture that's at an texture id when I no longer need it?
Q3: Will a memory warning tell me that I need to free up an open gl texture?
Q4: Aren't textures loaded on the PVR chip? Are they or how are they even taking up the phone's memory?
Thanks!
Removing Texture:
You have to use this GL call from the main thread.
glDeleteTextures(1, &_texture);
Memory warning is a general call to the application. It will not give you specific information. It is always better to remove unwanted textures from the memory if they are not needed anymore. Eg: We usually remove textures used in menu when the user moves to the In-Game screens, they are reloaded again when the user navigates back. This is much easier to manage memory than waiting for the system to call memory warning.
When you load PNG image, the data is decompressed and stored raw as array of colors per pixel. A 1K texture will use 4 mb despite of content/colors in the image. PVR is a hardware decompression chip which will decompress realtime when the image is used by the GPU, and the image file size you see is what memory it uses.
Currently I am working on an Air app for iOS and Android. Air 3.5 is targeted.
Performance on iPhone 4 / 4s has been acceptable overall, after a lot of optimising: gpu rendering, StageQuality.LOW, avoiding vectors as much as possible etc. I really put a lot of effort in boosting performance.
Still, every once in a while, the app becomes very slow. There is no precise point in time or action or combination of actions after which this occurs. Sometimes, it doesn't occur for days. But when it occurs, only killing the app and launching it again helps, because the app stays slow after that. So I am not talking about minor hiccups that
The problem occurs only on (some) iPhones 4 and 4s. Not on iPad 3,4, iPhone 5, any Android device...
Has anyone had similar experiences and pointers as to where a solution might be found?
What happens when gpu memory fills up? Or device memory? Could this be involved?
Please don't expect Adobe Air to have performance as Native Apps. I am developing App with Adobe Air as well.
By the sound of your development experience. I think it's to do with memory issue, because the performance is not too bad at the begging stage, but it gets bad overtime (so u have to kill the app). I suggest you looking into memory leaking issue.
Hopefully my experience can help you.
I had a similar problem where sometime during gameplay the framerate would drop from 30fps to an unrecoverable 12fps. At first I thought I was running out of GPU memory and it was falling back on rendering with CPU.
Using Adobe Scout I found that when this occurred, the rendering time was ridiculousness high.
Updating to Air 3.8, I fixed the problem by limiting the amount of bitmaps that were being rendered and in memory at once. I would only create new instances of backgrounds for appropriate levels, and then flagging them for garbage collection when the level ended, waiting a few seconds and then moving to the next level.
What might solve your problem is if you reduce the amount of textures you have in memory at one time, only showing the ones you need to. If you want to swap out active textures for new ones, set all the objects with that texture data to null:
testMovieClip = null;
and remove all listeners from it so that garbage collection will pick it up.
Next, you can force garbage collection with AIR:
System.gc();
Instantiate the new texture you want to render a few frames after calling gc. Monitor resources with Scout and the iOS companion app to confirm that it's working.
You could also try to detect when the framerate drops, and set some objects to null then force garbage collection. In my case, if I moved my game to an empty frame for a few seconds with garbage collection, the framerate would recover and the game would resume rendering with GPU.
Hope this helps!