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 drudiverse · Sep 16, 2014 at 04:00 AM · multithreading

MultiThreading Logic Error?

I have a function that isn't making sense with mutithreading, because it is writing results from a different gameobject than called by the function:

 function multicore_normals (go: GameObject ){
 
     yield WaitForSeconds(0.2);    
     //yield WaitForFixedUpdate;    
     var mesh : Mesh = go.GetComponent(MeshFilter).mesh;
     var indicies: int[] = mesh.triangles;
     var myvertices : Vector3[] = mesh.vertices;
     var mynormals: Vector3[] = mesh.normals;
     mynormals  = new Vector3[mesh.vertices.length];
 
 Loom.RunAsync(function() {//----=-=-=-=-multicore from unitygems
     for(var i :int= 0; i < indicies.Length; i += 3)
         {
             var v0: Vector3= myvertices[indicies[i]];
             var v1 :Vector3= myvertices[indicies[i+1]];
             var v2 :Vector3= myvertices[indicies[i+2]];
 
             var  normal : Vector3= Vector3.Normalize(Vector3.Cross(v1 - v0, v2 - v0));
 
             mynormals[indicies[i]] += normal;
             mynormals[indicies[i+1]] += normal;
             mynormals[indicies[i+2]] += normal;
                         
         }
 for(i = 0; i < myvertices.Length; i++)
     {
         mynormals[i] = Vector3.Normalize(mynormals[i]);
     }
 Loom.QueueOnMainThread(function() {//----=-=-=-=-
 
     //mesh.normals = mynormals ;    
 });});//----=-=-=-=-
 
     yield WaitForFixedUpdate;
     
      mesh.normals = mynormals ;    
 
 
 }


Result, every 1000 or so objects, i find a GameObject that has normals applied to it, that belong to a different GameObject, or that haven't been calculated at all for that object. how can it rewrite the vertices of the object, and then fail to write normals on it, or write normals from a different GameObject of unity?

To call the newnormals function, the code does:

get meshObject, rewrite vertices, newnormals(meshObject)

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 Bunny83 · Sep 16, 2014 at 04:06 AM 0
Share

You have some strange pseude code there... it's not clear on which data which thread is working and when you reassign the arrays to the mesh. How do you synchronise your worker thread with the main thread?

A little bit actual code would help to understand what you're actually doing since your pseudo code doesn't make any sense...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Sep 16, 2014 at 04:18 AM

You might want to take a look at the Loom class when it comes to threading.

Comment
Add comment · Show 1 · 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 drudiverse · Sep 20, 2014 at 01:11 AM 0
Share

hey bunny, it's using the loom class from unitygems. i've put the function that makes errors in the original post. the other day it ran for about 2k instances with no errors, i restarted my pc again and saw 5 errors in 400 instances of mesh.

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

24 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

Related Questions

MonoBehaviour.Invoke and Threading 2 Answers

multithreaded rendering on android breaks nativetexture update in plugin 0 Answers

EventHandler from external DLL not firing in MonoBehaviour C# script 0 Answers

> 0.9f progress of SceneManager.LoadSceneAsync isn't 0 Answers

How to stop waiting on Serial Output 2 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