- Home /
Loading big panos >10M (8k) without freeze on the main thread
Hi, We have a simple app that loads panoramas from external sources (not prepared by unity and no way to change that). And while loading a new pano (next one in line) we fade out to black and then once it's loaded fade into the new pano. Unfortunately the main thread freezes while the image is being loaded (presumably while it's being decompressed and loaded into memory). Is there a way to work around this? So we don't get the main scene frozen? Or can we at least give an animated indicator (rounding circle or something similar) that would give the user a feedback that we are working on it rather than giving the idea that the app crashed by the blackout?
Thanks, Dominik
Well, the first question that comes to $$anonymous$$d is why you can't do this in a separate thread?
The first question that comes to my $$anonymous$$d is: How do you actually load it at the moment? ^^ You should include the code that you're using. You also did not specify what format this image has (format, not resolution)
Answer by Bunny83 · Aug 23, 2016 at 10:34 AM
Depending on the format of your image you can use some thirdparty library to load and decode the image on a seperate thread, Once you have the pixel data, make sure to convert it into a Color32 array. Finally you will use Texture2D.SetPixels32 on the main thread to actually create the texture and apply the data. If this is still too heavy, you might want to break down the big array into smaller rectangular chunks (8kx8k might by split into 64 x 1k x 1k) and use the second overload of SetPixels32 which allows you to just set a portion of the texture at a time. Of course this might be done in a corouine where you can display the progress after each 1k chunk.
Keep in mind that a 8kx8k image requires at least 256 MB in memory. As Color array (instead of Color32) it would even take 1 GB.
Your answer