• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by reverse · Dec 04, 2013 at 12:21 PM · iostexturecoroutinewww.texture

iOS Unity randomly hangs on yield return www

I'm developing an iOS app with Unity where I load textures at runtime from the file system. I only have one scene. The piece of code I use to load the textures is shown below. This is called several times during runtime if the user wishes to change these so called 'backTextures'.

In my tests I call this several times in a row. Everything goes well and afaik there is no sign of memory leaks. But after executing this several random times (say as little as 2 times or even as much as 13 times for example) Unity hangs.

According to the Xcode console, the last print I read is the 'Just created the www' so I am assuming the script is hanging waiting for the 'yield return _www;'. This happens always on the first iteration of the for loop (i=0), but as I said before, after calling this piece of code several times.

Can anyone help me out with this? I have no idea why yield return www would hang...

EDIT I did some more testing: This code is running on a coroutine. I added a print to the Update() and it keeps being called. So the Unity engine is not completely dead. It really seems that it is the www that is not returning....

 //some code before
 
                        if(backTextures != null && backTextures.Length != 0){
                             Debug.Log("Cleaning the vector!!!!");
                             for(int i = 0; i < backTextures.Length; i++){
                                 Destroy(backTextures[i]);
                                 backTextures[i] = null;
                             }
                             
                         }

 //Some more code here
 
 Debug.Log("Will load " + picsize + " textures");
             //load textures to memory
             for(int i=0; i<picsize; i++){
                     Debug.Log("Let's read the texture " + i);
                     string _textureURL = "file://" + Application.dataPath + "/../../Documents/current/" + imageNames[i];
                     Debug.Log("The path is " + _textureURL);
                     WWW _www = new WWW(_textureURL);
                     Debug.Log("Just created the www");
 
                     yield return _www;
                      Debug.Log("Returned from yield return");
                     if (_www.error != null)
                     {
                        Debug.LogError("WWW Error: "+ _www.error);
                         i--;
                         _www.Dispose();
                         _www = null;
                         continue;
                     }else{
                         Debug.Log("There was no error!!!!!");
                     }
                     Debug.Log("Will assign textures");
                     backTextures[i] = _www.texture;
                     Debug.Log("Will dispose textures");
                     _www.Dispose();
                     _www = null;
             }
 
 // some code after
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cheaster · Apr 24, 2014 at 01:42 AM 0
Share

How can you solve it ? I have met the same problem as you

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

Adding gravity and texture to newly added game objects 1 Answer

Texture atlases on iphone 3 Answers

Can I load textures at runtime with a smaller memory footprint? 1 Answer

Unity iOS forced 1kx1k 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges