I am working on an application that need to load thousands of small textures (256x256 pixel) in runtime (aka map engine :p). I found that each time, I loaded the texture around 5849 times or near, the system will stop and crash ! Anyone have an idea of that ?
following is the dummy script for that issue.
(WARNING: This script may crash the OS too. Remember QUIT Unity immediately when its stopped !!!)
var g:GameObject;
var frame:int = 0;
var busy:String = "loaded";
var time_to_dead:int = 0; // Magic Number 5849 !?!?!
function Start ()
{
g = new GameObject.CreatePrimitive(PrimitiveType.Plane);
}
function Update ()
{
if (busy == "loaded") { busy = "loading"; test(); time_to_dead++; }
}
function test()
{
var www: WWW;
var _temp:Texture;
www = new WWW("http://127.0.0.1/~antonioh/loading_jpg/"+frame+".jpg");
yield www;
_temp = g.renderer.material.GetTexture("_MainTex");
g.renderer.material.mainTexture = [url]www.texture;[/url]
yield WaitForSeconds(0.025);
if(_temp) { Destroy(_temp); }
www.Dispose();
www = null;
frame = (frame+1)%1024;
busy = "loaded";
}
I tried, using with/without “Destroy()”, the issue is the same, except, its got faster to crash when not using Destroy. The “WaitForSeconds()” make no different. I also, run that on other machine with less memory installed and got 6100+ ??!?!
I hesitate to say that this is a WWW problem, but rather related to the thousands of textures you’re trying to load in, and perhaps your method of storing/deleting them.
In the real application, I built some arrays with time-stamp… buffers… etc to hold the reference of textures. The loading and killing cycle are work fine for few hours until its reach that amount of textures.
is that at the beginning?
Or after you let it run for over an hour to achieve the 5xxx loads? (the runtime is the important thing here because otherwise the issue might not be the WWW class but that you flood the server and it decides that you shall go to hell with your flood )
The mac version of WebPlayer with Safari 4 can handle around 50,000+ calls, until in cause memory overflow at 2GB. The pc version of WebPlayer are still running beyond 100,000+ calls now
Since the application will be used for web mainly, I guess, I can handle the rest of issue.
Many Thanks to All
Antonio Hui
PS. The memory usage with FireFox(Mac/PC) did not raised up too