Search Unity

Multiple External Files Problem

Discussion in 'Scripting' started by movix, Jul 14, 2009.

  1. movix

    movix

    Joined:
    Jul 9, 2009
    Posts:
    9
    I'm trying to bring in 3 external files :
    One png using WWW class
    One file containing a path as a string - either text using www in XML using XMLReader
    One XML document

    I can get them all in and working fine, but if I use the WWW or the XMLReader twice in a script, then the app crashes on application.quit - no problem at all when running.

    If I use one of each (1 WWW and 1 XMLReader) it quits cleanly and swiftly with no crash.
    I've tried Disposing the WWWs and Closing the XMLReaders and no joy - it's the last hurdle in the project and is very frustraiting!

    Is this a bug or a limitation?
    It seems like Unity (or me) is not releasing the resources if more than one of the classes is used
    It's all within one script on the Main Camera.

    Hope someone can help!

    Rob
     
  2. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    Im not really sure what you are doing, but Im useing multiple www's (a hell of a lot actually) and XmlNodeReader's (ye alot of them too) and Im not having any problems with crashes.

    maybe you can give a bit more info? i.e. a code snippet?

    Although we still have a crashbug in firefox we havnt found yet. Are you using firefox? win or osx?

    //perlohmann
     
  3. movix

    movix

    Joined:
    Jul 9, 2009
    Posts:
    9
    Extracts of the main script...
    In the Start function is this...

    Code (csharp):
    1.     var myDataURL = "file:config.txt"; 
    2.     var wwwXML = new WWW(myDataURL);
    3.     yield wwwXML;
    4.     XMLDataPath = wwwXML.data;
    5.     wwwXML.Dispose();
    6.  
    7.     myXmlReader = new XmlTextReader(XMLDataPath);
    8.     //Working Blow
    9.     var myURL = "file:schoolLogo.png"; 
    10.     var www = new WWW(myURL);
    11.     yield www;
    12.     schoolLogo = [url]www.texture;[/url]
    13.     www.Dispose();
    14.  
    then in the update is this...
    Code (csharp):
    1.  if (Input.anyKey) {   
    2.         myXmlReader.Close();    
    3.     Application.Quit();
    4.    }
    5.  
    It reads in a user definable path from the config.txt file which points the script to the XML file's URL and then displays a dynamic graph. The other WWW is just to load in an external logo.

    It's designed to have basic screensaver functionality - touch a key and it quits, but generally it's just a running app.

    This crash is in OSX - not in a browser.
    Thanks
    Rob
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    I think the file url is wrong.

    like http where the protocol is http://, the file protocol is file:// not file: as you used it there which potentially could lock the www and kill it if you try to get rid / reinit it.
     
  5. movix

    movix

    Joined:
    Jul 9, 2009
    Posts:
    9
    When Application.Quit is called I get...

    "The Application House Points Display quit unexpectedly"

    Console gives...

    15/07/2009 09:34:19 com.apple.launchd[425] ([0x0-0xb00b0].unity.Semantise.House Points Display[4666]) Exited abnormally: Abort trap
     
  6. movix

    movix

    Joined:
    Jul 9, 2009
    Posts:
    9
    I've changed the protocol now but it still crashes on quit.

    The app runs perfectly with the multiple calls to WWW or XML, it's only when quitting it crashes.

    Thanks for the help so far!...
    Rob
     
  7. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    well you could first of all use the
    Code (csharp):
    1. if (wwwXML.error == "")
    to verify that no error occured when downloading the file.
     
  8. movix

    movix

    Joined:
    Jul 9, 2009
    Posts:
    9
    Don't get any errors, but thanks for the suggestion!

    Seems like I've narrowed it down a dozen times to different things, but the current thing is making this change fixes it...

    myXmlReader = new XmlTextReader("http://localhost/testing/house_point_data.xml");

    changed to

    myXmlReader = new XmlTextReader("house_point_data.xml");

    There is the correct XML file in both locations but accessing it using http:// seems to break things,
    Rob
     
  9. movix

    movix

    Joined:
    Jul 9, 2009
    Posts:
    9
    wondering if it's a permissions thing...investigating...

    Nope not a permissions thing :(
     
  10. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    hmm java isnt my strongest side but you might wanna explicit declare the XMLDataPath as a TextAsset (var XMLDataPath : TextAsset = ...).

    and then use XMLDataPath.text to get the "string"

    this is a snippet of some code Ive used using assetbundles, XMLDocument and C#.

    Code (csharp):
    1.  
    2. TextAsset xmlFile = (TextAsset)bundle.mainAsset;
    3. string text = xmlFile.text;
    4. //for some reason the assetbundle has added an empty character at the beginning of the string.... so remove it
    5. if (text[0] != '<')
    6. {
    7.    //Debug.Log("first char not \"<\"");
    8.    text = text.Remove(0, 1);
    9. }
    10. try
    11. {
    12.    xmlDoc.LoadXml(text);
    13. }
    14. catch (XmlException xmlError)
    15. {
    16.    Debug.Log(xmlError.Message);
    17.    Debug.Log(xmlError.StackTrace);
    18. }
    19.  
    since www dosnt give any error I do not think the problem is that it cant find the file.

    Im not really sure the XMLTextReader can access a "web" related file but look it up on msdn to be sure.
     
  11. movix

    movix

    Joined:
    Jul 9, 2009
    Posts:
    9
    I've had a look at the msdn docs for XMLReader and the examples use things like this...

    reader = new XmlTextReader("http://localhost/baseuri.xml");

    I'm starting to think that it's a problem with my network/apache rather than Unity as both local and http://localhost... access both work fine and deliver the data from the XML file, it's just that somehow unity can't let go of the XML when it's quitting if the http is used.

    I've kicked it off to the clients to test on their network and we'll see if they have the same problems,
    Thanks all for your help!

    Rob