Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Blanche018 · Feb 05, 2021 at 01:48 AM · error-handling

Connection is no longer valid. Calling auto disconnect. Error

Hi, Im getting the following errors. its a coroutine basically what it does is, it downloads a bunch of image from the server and it will first check if that file name already exists in the storage in the persistentDataPath then if not it will download and store it there, it works fine with my other android devices, but other tablet it does not work, I tried development build, but it doesnt return any error other than what I mention in the title, I also tried looking at the adb logcat it still the same as the title says, heres the code for reference

IEnumerator DownloadSlidesCurrent() {

     int _cnt = GetComponent<db_materials>().material_count - 1;
     if (current_lesson <= _cnt)
     {
         num_threads += 1;

         string[] slide_link = model_mat[current_lesson].slides.Split(',');
         string img_name = model_mat[current_lesson].disp_name + "_" + (current_slides + 1);
         if (File.Exists(_path + img_name + ".png"))
         {
             sec_towait = 0.03f;
             yield return new WaitForSeconds(sec_towait);

             //check if the current slides has reached the max slide number
             //if it does it will reset the current_slides to 0 and +1 to current lessons
             if (current_slides == slide_link.Length)
             {
                 PlayerPrefs.SetInt(model_mat[current_lesson].disp_name + "_FileCount", downloaded_img);
                 current_slides = 0;
                 current_lesson += 1;
                 downloaded_img = 0;
                 
                 //then it will check if the current lessons is still less than the total lesson (for index error)
                 if (current_lesson <= GetComponent<db_materials>().material_count - 1)
                 {
                     slide_link = model_mat[current_lesson].slides.Split(',');
                     img_name = model_mat[current_lesson].disp_name + "_" + (current_slides + 1);
                 }
                 

             }

             if (current_lesson <= _cnt)
             {
                 byte[] byteArray = File.ReadAllBytes(_path + img_name + ".png");
                 Texture2D texture = new Texture2D(8, 8);
                 texture.LoadImage(byteArray);
                 Debug.Log("already exist: " + img_name);

                 downloaded_img += 1; // this will count slides then will save it for future reference
                 
                 num_threads -= 1;
                 current_slides += 1;
                 total_file_download += 1;

                 ShowLoading("(" + current_slides + "/" + (slide_link.Length - 1) + ") Downloading " + model_mat[current_lesson].subject + " resources...");
                 yield return CoroutineUtils.Try(DownloadSlidesCurrent());
                 
             }
             else
             {
                 StartCoroutine(FinishSetup("Setup Complete!"));
             }
         }
         else
         {
             sec_towait = 0.03f;
             yield return new WaitForSeconds(sec_towait);

             //check if the current slides has reached the max slide number
             //if it does it will reset the current_slides to 0 and +1 to current lessons
             if (current_slides == slide_link.Length -1)
             {
                 PlayerPrefs.SetInt(model_mat[current_lesson].disp_name + "_FileCount", downloaded_img);
                 current_slides = 0;
                 current_lesson += 1;
                 downloaded_img = 0;
                 //then it will check if the current lessons is still less than the total lesson (for index error)

                 if (current_lesson <= GetComponent<db_materials>().material_count - 1)
                 {
                     slide_link = model_mat[current_lesson].slides.Split(',');
                     img_name = model_mat[current_lesson].disp_name + "_" + (current_slides + 1);
                 }
             }

            
             if (current_lesson <= _cnt)
             {
                 WWW www = new WWW(slide_link[current_slides]);
                 yield return www;
                 Texture2D texture = www.texture;
                 byte[] bytes = texture.EncodeToPNG();
                 File.WriteAllBytes(_path + img_name + ".png", bytes);
                 Debug.Log("downloaded: " + img_name);

                 downloaded_img += 1; // this will count slides then will save it for future reference

                 num_threads -= 1;
                 current_slides += 1;
                 total_file_download += 1;

                 ShowLoading("(" + current_slides + "/" + (slide_link.Length - 1) + ") Downloading " + model_mat[current_lesson].subject + " resources...");
                 yield return CoroutineUtils.Try(DownloadSlidesCurrent());
                 
             }
             else
             {
                 yield return CoroutineUtils.Try(FinishSetup("Setup Complete!"));
                 //StartCoroutine(FinishSetup("Setup Complete!"));
             }
         }

     }

 }

capture.png (22.7 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Blanche018 · Feb 05, 2021 at 01:50 AM

  • oh and 1 more thing..

  • it just suddenly close not showing any messages in my android devices saying it crashes or something.. while in the middle of downloading the file

Comment
Add comment · Share
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
0

Answer by Renald_Pogi · Feb 16, 2021 at 11:40 AM

nvm, after weeks of debugging, I have found that the memory leak is what causing the app to crash. the code "Texture2D texture = www.texture; " - this create to many instances of that object after each image is downloaded, so by adding, UnityEngine.Object.Destroy(texture) below, it solves the problem.,nvm. after weeks of debugging, I have found that crashes is occurring because of memory leak. I identify that the objects I initialized (Texture2D texture = www.texture;) needs to be destroyed after use, because it creates many instances of that texture. by adding UnityEngine.Object.Destroy(texture) below solves the problem.

Comment
Add comment · Share
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

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.

Follow this Question

Answers Answers and Comments

110 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to sove this script error? 0 Answers

How to resolve this- Error CS0246: The type or namespace name 'DefaultTrackableEventHandler' could not be found (are you missing a using directive or an assembly reference?)? 1 Answer

melee script help 1 Answer

Unity wont enter play mode - compiler errors? 0 Answers

Beginners question with Unity and App42 - Struggling with handling call back on exception 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