I am having a very large problem with the Ipad and LoadImageIntoTexture.
Does LoadImageIntoTexture fail if the mimetype of the downloaded image is incorrect?
texture = www.texture; this works fine, except the Ipads memory runs out after about 20-30 images.(1024x768px)
If this is the case and the mimetype is the issue (an issue we have no direct control over) is there a method I could use to free up the memory of the previous images that were downloaded.
I only ever need the latest image.
I have used, Destroy and Dispose, but no luck.
Is there an alternative to using www on the Ipad (IOS) to download the image?
Any help/suggestions welcome.
Matt.
No the device just runs out of memory. 20-30* 3mb >>> than you have at hand.
Application border on ipads with their 256mb ram is somewhere between 100 and 140mb for RAM + VRAM together and the loaded images there already on the vram side fill 120mb and worse.
aside of that externally loaded textures have a memory overhead (independent on if you use WWW or something else as the overhead comes from loading the texture which internally is always happens, be it www.texture or loadtexture / loadtextureintoimage), so their ram + vram need is more in the range of 7mb
As such you can decide to either use less pictures or make them smaller, it will not work out if you load that many.
your console in xcode - debug execution - should be flooded with “memory warnings”
what I have tried and didn’t work
1: multiple Destroy calls and garbage collector calls
if (texture != null)
GameObject.Destroy(texture);
texture = null;
if (wwwLoader != null)
wwwLoader.Dispose();
wwwLoader = null;
int gen = System.GC.GetGeneration(texture);
GameObject.Destroy(texture);
System.GC.ReRegisterForFinalize(texture);
System.GC.Collect(System.GC.MaxGeneration, System.GCCollectionMode.Forced);
System.GC.WaitForPendingFinalizers();
System.GC.Collect(gen, System.GCCollectionMode.Forced);
System.GC.WaitForPendingFinalizers();
2: get the texture from OpenGLES and kill it there
(this “works”, the texture of my plane turns black)
//get the texture index from the native render system
renderer.material.mainTexture.GetNativeTextureID();
//on Xcode create a method that calls
glDeleteTexture(1, textureID);
currently I’m trying to implement my own .PNG loader in c# (all images are .PNG) and having a hell of a time with the file structure specification
I couldn’t get to use the usual loaders in c# because WPF is not on iPad. so System.Drawing.Bitmap is not available
I’ve done it on Xcode but couldn’t figure out how to pass a structure in objective c to c# on Unity
after that doesn’t work (I’m that optimistic) I’m gonna try to really load on objective c overwriting the current texture, thus using a constant ammount of textures
if you didn’t get by now, I’m running out of ideas
- Won’t help what you do there. The overhead comes from Texture2D.LoadTexture which is used in any case be it WWW or something else.
Also Unity objects (textures, game object etc) are not managed by the .NET GC at all, the only thing you have is the UnloadUnusedAssets
So you won’t get lower that way.
What you though can do is use the LoadImageFromBytes function on the already existing texture to replace its content with a new one (read either on www.bytes or read directly through System.IO binary readers) so you don’t generate a new texture. I personally would go with the binary reader to not trigger the internal texture loader on WWW
- Its a good way there but restricts portability and makes it dependent on things not changing in future iOS and Unity versions at worst (though the part used there should be considered infinite stable)
As for the loader: I would actually load and fill the texture straight on the native side.
And as for WPF: Its not available in unity / mono at all, nothing to do with ipad. WPF is MS.NET only.
does this problem happens on iPhone 3GS too?
like on iPad?
from what object can I call this LoadImageFromBytes method?
I’m in C#