Log in or register to post comments

Loading many different Object3D objects prompts memory warning and crash

May 28, 2012 - 3:20am #1

Hi there,

I have created an app based on the image targets sample that has 60+ models. The user chooses the model to display by rotating a picker on an overlay view controller.

If I load all the objects when I launch the AR environment, the app gives a memory warning and crashes. Ideally I'd only load up the object the picker selects and a couple more on either side ready for when the selection changes. To keep the app stable I need to be able to flush the unused models. What is the best way of doing this selective loading and unloading of model objects in memory? Help!

In this case the geometry of each model is the same and only the texture changes, so a method of loading and unloading textures as the user makes selections would work also.

Thanks in advance!

Carl.

Re: Loading many different Object3D objects prompts memory warni

May 29, 2012 - 2:38am #3

Hi, thanks for your message. I have almost no experience with OpenGL so vertex arrays and buffer objects would be hard for me to figure out. I'd like to explore your first suggestion though.

In the initWithFrame method in EAGLView I set up my textureList (basically a list of file names from the app bundle) and the loadTextures method in ARViewController goes off and loads up the textures etc. I can restrict the number of textures loaded by only putting a few items into the textureList array and it works well for those objects. When I am ready to add new textures (and have their objects) how do I do that? I can add the new texture names to the textureList array, but then I need to kick off the object creation process again. I tried calling [self loadTextures:arView.textureList], but it doesn't seem to create them properly.

Thanks!

Re: Loading many different Object3D objects prompts memory warni

May 28, 2012 - 4:42am #2

Hi Carl

This is a little outside the scope of this forum, but I will try to help.

Regarding your first point if you have to have 60 models in there and they are all different you could try having a cache of say 5 objects that gets updated when the user reaches the end of a the current cache - this is a bit like the scrolling in UITableView where Apple advises not to load everything in one go.

However you mention that the geometry is the same and that just the textures vary, so it should be pretty straightforward to set up either a vertex array (OpenGL 1) or a vertex buffer object (OpenGL 2) and then bind the appropriate texture when the user changes their selection.

The Apple programming guide on OGLES is really helpful and the link below shows specifically some tips on optimizations:

http://developer.apple.com/library/ios/#documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html#//apple_ref/doc/uid/TP40008793-CH107-SW1

HTH

N

Log in or register to post comments