- Home /
loading a texture every frame
Can someone please show me how to load a texture every frame in Update(), before or after but not during any rendering, and further how to make sure that any memory from the previous loading of a texture is released. Psuedocode:
Update function called Load image into texture Set texture Release memory for any previous texture, and any temporary memory buffers allocated. Update function exits
Note: I've tried forcing GC to no avail. And this is not for a game, but rather a special type of simulation so doing it every frame is what I want.
Thanks.
The textures will be 2048 X 2048. I've tried different ways but for example:
//within Update() txtr = new Texture2D(2048,2048);
FileStream fs = new FileStream("C:\Users\User\Pictures\$$anonymous$$actexture.png", File$$anonymous$$ode.Open, FileAccess.Read);
byte[] imageData = new byte[fs.Length];
fs.Read(imageData, 0, (int) fs.Length);
txtr.LoadImage(imageData);
renderer.material.mainTexture = txtr;
fs.Dispose();//doesn't help with memory not being released System.GC.Collect();//doesn't help with memory not being released System.GC.WaitForPendingFinalizers();//doesn't help with memory not being released
I've had success for an iPad app using Resources.Load(). Resources.UnloadAsset(), but you are going to have a low frame rate if you are doing this each frame.
Your answer
Follow this Question
Related Questions
Load a transparent texture by script 1 Answer
Is Awake() called before texture loading? 2 Answers
How do I fix textures? 0 Answers
Loading assetbundle from usb storage on android 0 Answers
Scene transfer splash screen not working 0 Answers