tags:

views:

366

answers:

2

I am not sure what the problem is. My app is running fine on the simulator but when I try to run it on the iPhone it crashes during debugging or without debugging with signal "0". I am using the Texture2D.m and OpenGLES2DView.m from the examples provided by Apple. I profiled the app on the iPhone with Instruments using the Memory tracer from the Library and when the app died the final memory consumed was about 60Mb real and 90+Mb virtual. Is there some other problem or is the iPhone just killing the application because it has consumed too much memory? If you need any information please state it and I will try to provide it. I am creating thousands of textures at load time which is why the memory consumption is so high. Really cant do anything about reducing the number of pics being loaded. I was running before on just UIImage but it was giving me really low frame rates. I read on this site that I should use OpenGLES for higher frame rates.

Also sub question is there any way not to use UIImage to load the png file and then use the Texture class provided to create the texture for OpenGLES functions to use it for drawing? Is there some function in OpenGLES which will create a texture straight from a png file?

A: 

thousands of textures? really? how many of them are on the screen at one time? perhaps you can only load some of them at a time, or if they're small, you should combine them into fewer larger textures.

the general guideline I've heard is that you are limited to 24MB of texture memory.

there's nothing built into OpenGLES that loads from disk, but you can use a file parser like stb_image to do it yourself.

David Maymudes
Well there are thousands of images loaded but only a few are being displayed at a time approx 10-50.
CustomAppsMan
The images are around 128x128 pixels each.
CustomAppsMan
I just downloaded the stb_image.c file and compiled it into my project and am using it to load an OpenGLES texture as follows briefly:int x, y, comp;void *data = (void *) stbi_load(fileName, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);The result is the whole screen goes blank white. The png's were working fine under alternate means of loading with UIImage.As I am writing this I just remembered that apple iPhone mangles .png files before bundling them. So I will go try with the solution to that problem.
CustomAppsMan
No dice this fix is for the iPhone itself. Its showing a blank white screen on the simulator which doesnt run the optimizing of png files script. So no idea why stb_image.c is not working with these png files. Any ideas?
CustomAppsMan
I have tried another code snippet called LodePNG which works on some of the png's which display and others dont get loaded properly and display a blank white square. Not sure whats up with the pngs that arent loading.
CustomAppsMan
I just converted from LodePNG to libPng and the same problem some of the pngs are displaying and the others are just displaying a black white rectangle. Why would some pngs work and others dont?
CustomAppsMan
when I did this in my app I renamed my PNG files to have an XNG extension to keep the auto-mangling from happening. (there's probably some way to turn it off in XCode but this seemed easier at the time.)
David Maymudes
Yes I renamed my png files extension as well and its working. The images that were coming blank were due to the fact that I had preprocessed them in .NET C# app on windows and as usual MS does not comply the png standard or any standard for the matter well so libpng was screwing up reading the files and hence blank white squares. Btw with libpng its working fine now.
CustomAppsMan
The program is working but still memory consumtion is 3 times as high as when I orignally started with using UIImage/drawAtPoint. Why are textures so memory intensive?
CustomAppsMan
A: 

I tried load as ten texture pieces of 2048x2048 pixels. Texture memory exceed 24MB, but iPhone3GS is able to loaded and rendered it.

I also recommend stb_image or SOIL texture loader. (stb_image library is used SOIL library.)

Shiva