Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
This question was closed Mar 22, 2016 at 08:23 AM by EricNumeri4D for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by EricNumeri4D · Mar 15, 2016 at 09:59 AM · androidwrite datazip

Is there a max file size to write on disk or is it a question of memory ?

Hi there,

I'm currently stuck with one big problem. I'm downloading a zip file from the server and while writing the zip file in persistent data path, my app crash with no log, no error, no exception. I searched everywhere but didn't find anything.

This is the code writing zip file :

Code (CSharp):

             Debug.Log("Start downloading ALL ZIP");
             downloadAllZip = new WWW(NetworkManager.Instance.ServerAddress + "/ws/file/index/");
             LoadingScreen.Instance.SetText ("Loading resources from internet, This may take several minutes... ");
            
             while (!downloadAllZip.isDone) {
 //                Debug.Log ("Progress " + downloadAllZip.progress);
                 yield return new WaitForEndOfFrame();
             }
             Debug.Log ("Zip downloaded");
             try {  
                 if(!string.IsNullOrEmpty(downloadAllZip.error)) {
                     Debug.LogError("Error in download all zip : " + downloadAllZip.error);
                 }
                 else
                 {
                     Debug.Log("End of download ALL ZIP");
                     LoadingScreen.Instance.SetText ("Saving resources ... ");
                     ResourcesPath =  ResourcesPath.Replace("\\","/");
        
                     Debug.Log ("Writing zip at : "+ResourcesPath + " - size : " + (downloadAllZip.size / 1000000f).ToString("F2") + "Mb");
                     DataManager.WriteFile(ResourcesPath, downloadAllZip.bytes);
     //                System.IO.File.WriteAllBytes(ResourcesPath,  downloadAllZip.bytes);
                     Debug.Log("Zip saved");

The last display is : "Writing zip at : /storage/sdcard0/Android/data/com.allucyne.colmarafdts/files/Data/Resources/resources.zip - size : 205.26Mb" And after it crashes.

Note that I have Unity 4.6.8f1, and the DataManager is used in other projects and is working. There is error management in DataManager, and no error is fired.

Just to show you the WriteFile method :

Code (CSharp):

         /// <summary>
         /// Writes a file with the datas
         /// </summary>
         /// <param name="_filePath">file path.</param>
         /// <param name="_data">data to write</param>
         public static void WriteFile(string _filePath, byte[] _data)
         {
             try
             {
                 _filePath = ConvertPath (_filePath);
                 if(_data != null)
                 {
     //                Debug.Log("Write file : " + _filePath + " - size : " + (_data.LongLength / 1000f).ToString("F3") + "Kb");
                     try
                     {
     #if UNITY_WP8 || NETFX_CORE
                         Debug.Log("Write file with unityengine windows method");
                         UnityEngine.Windows.File.WriteAllBytes (_filePath, _data);
     #else
                         Debug.Log("Write file with mscorlib method");
                         File.WriteAllBytes(_filePath, _data);
     #endif
                         Debug.Log("Write successful");
                     }
                     catch(Exception e)
                     {
                         Debug.LogError("Error writing file : " + _filePath + ", error : " + e.Message);
                     }
                 }
                 else
                 {
                     Debug.LogError("Error, data is null");
                 }
             }
             catch(Exception ex)
             {
                 Debug.LogError("[DataManager] Error while writing file " + _filePath + " : " + ex.Message);
             }
         }

I'm stuck since a lot of weeks with this...I don't know if the file is too big or anything else. I'm using Ionic.Zip for the ZipFile but here i'm just writing bytes, so Zip has nothing to do with the problem I think.

Thanks a lot.

Comment
Add comment · Show 3
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 Paul-Jan · Mar 15, 2016 at 06:08 PM 0
Share

The only line that is executed between that last log and the next one is ConvertPath... perhaps you could post the source to that method as well? The only explanation right now seems to be native exceptions that bypass the try..catch ... but I'd still expect an error log in that case.

avatar image elenzil · Mar 15, 2016 at 07:02 PM 0
Share

indeed - as Paul-Jan says, you could add more debug logging into the WriteFile() method. It seems like if ConvertPath() is working, we should expect to get logging from either line 17 or line 20.

also, have you confirmed that this code works with everything the same except a smaller .zip file ?

avatar image EricNumeri4D · Mar 16, 2016 at 08:20 AM 0
Share

Thanks for the answers.

ConvertPath works like a charm, it's only replacing ths "/" by "\" or inverse. After some investigation and profiling, it seems that it was due to the memory usage. The bytes array seems to go into cache and there's not enough memory in my devices.

I replaced the code by this and it's working better but I don't know if iOS will work with the WebClient from System.Net

             client = new WebClient();
             client.DownloadFileCompleted += new System.Component$$anonymous$$odel.AsyncCompletedEventHandler(DownloadFileCompleted);
             client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadFileProgress);
             client.DownloadFileAsync(new Uri(Network$$anonymous$$anager.Instance.ServerAddress + "/ws/file/index/"), allResourcesZipFilepath);


To answer elenzil, the code works with all files and formats except when they are too big. I didn't think before about RA$$anonymous$$.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Android 8 permission issue 1 Answer

Downloading file using web client not working in all servers 0 Answers

[Android] How to share a directory between two apps? 2 Answers

Write file with WWW on Android 0 Answers

Writing to SD card on Android 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges