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
-1
Question by RKSandswept · Jan 23, 2014 at 10:04 AM · proceduraltreesystemterrain-treestreeprototype

ANSWERED - Pure Virtual Function crash.

Our game is a infinite procedural world. On delete and regen of areas we often got a Pure Virtual Function crash.

It was caused by the Unity Tree system where we created a few zillion trees, then later deleted them all and created more trees on the same terrain instance, but after changing altitudes etc. to represent a new area of the game.

Our code was like: ...terrainData.treeInstances = new TreeInstance[0]; to clear the trees. Then lots of: myTerrain.AddTreeInstance(ti); The problem was that the time between the clearing of the terrain and the first tree add was several ticks. When the garbage collector kicks in it calls any needed destructors, and somewhere in the Tree system a virtual function call is tried in a destructor. (that is bad to do in C#)

The solution is the following class...

 public class TreeBugFix {
 
     static bool isCleared = true;
 
     public static void ClearTrees()
     {
         isCleared = true;
     }
 
     public static void AddTreeInstance(TreeInstance t)
     {
         if(isCleared)
         {
             isCleared = false;
             TheDeadLinger.tdl.globalTerrain.terrainData.treeInstances = new TreeInstance[0];
         }
 
         TheDeadLinger.tdl.globalTerrain.AddTreeInstance(t);
     }
 
 }

This makes the first tree get created before the garbage collector can kick in avoiding the crash.

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 Benproductions1 · Jan 23, 2014 at 10:35 AM 2
Share

To mark a question as answered so that people don't come here to answer it, either close the question or post an answer yourself and accept that answer. If you don't know how to use this website you should read the FAQ and watch the tutorial video on the right.

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.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

Accessing local system ( File Browser ) 2 Answers

Why is part of the tree billboard is cut off? 1 Answer

Unity 5 Terrain TreeInstance Scaling VS Colliders [Scripting] 0 Answers

Tree Creator Problems 1 Answer

How do I get a speedtree color? 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