- Home /
Glitch when using WWW.LoadImageIntoTexture(...)
The Function WWW.LoadImageIntoTexture(Texure2D tex) causes a glitch in the application due to Texture.AwakeOnLoad() which can be seen in the profiler.
I have seen other people ask about this in the forums and also here on unity asnwers as well. I haven't seen any real solutions though. The ideal would be to do the LoadImageIntoTexture bit in another thread - however this is not possible because you can't use the Unity API in a separate thread.
My application requires loading a number of jpgs at run time - it is based on the context of where you are in the application and they can't be loaded ahead of time. Ie. they need to be able to be loaded at run time without causing a noticeable stall in the application.
I have currently been exploring how to implement my own AsyncOperation but it is not apparent if this is possible/will work from looking at the documentation and probing with System.Reflection. All I have seen is a comment that this is 'not a good idea' which just makes me want to do it all the more:)
I have seen a few mentions of using LoadLevelAdditiveAsync -> I think this would be a messy way to have to do it as I want to be able to load raw jpgs, ie. not have to do some postprocessing on them to give me something to load as a level (I have a lot of textures to load...).
The last thing I am thinking of is to save all the textures as saperate asset bundles however a texture saved as an asset bundle I'm pretty sure still calls Texture.Awakefromload when called out of the assetbundle.
So after all the Bla Bla Bla above the question is how can I load a texture at runtime without incurring a stall when it calls Texture.AwakeFromLoad()?
Answer by bompi88 · May 13, 2012 at 08:04 AM
Try the thread idea. Found something interesting here. Take a look at it. I haven't tried it, but looks awesome.
Hi that looks pretty useful - thanks. It doesn't solve the issue above because unity API calls can only happen in the main thread which would still cause a glitch. However I still can find lots of uses for what you have just pointed out so thanks again.
Ok, I thought you would do something like:
UnityThreadHelper.Dispatcher.Dispatch(() => Instantiate(Resources.Load(objectToInstantiate)));
I have poor knowledge about threading :S I have to get into it later on. O$$anonymous$$, I understand it now ;-) It will still happen in the main thread :S
Can you please tell why it still will happen in the main thread? It has method "UnityThreadHelper.CreateThread(DoThreadWork)" which will, I suppose, create a new thread? Am I wrong?
Answer by stijn · May 13, 2012 at 10:16 PM
The problem is it takes a long time (on the main thread) to load the image into video memory.
A second problem is that resizing the image is only possible after loading it into video memory (which is too late)
I'm dealing with this same problem, I wrote a working solution using FJCore, which is too slow so I made a feature request. Check out my question here:
http://answers.unity3d.com/questions/249993/typeloadexception-trying-to-use-fjcore-fluxjpeg.html
Your answer
Follow this Question
Related Questions
Image loaded with LoadImageIntoTexture gets inverted 0 Answers
Loading Images using WWW into a different texture format 2 Answers
LoadImageIntoTexture on iPhone from the device disk 1 Answer
Webplayer crash on LoadImageIntoTexture call 1 Answer
Is there a way to replace the question mark in the WWW.LoadImageIntoTexture? 2 Answers