- Home /
The question is answered, right answer was accepted
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.
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.
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 ?
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$$.
Follow this Question
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