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 Milad · Jun 14, 2010 at 07:04 AM · socketthread

ThreadCheck error in socket programming and instantiate a object!!!

Hi,

i wrote a server/client program.i send some random numbers(x,y) via server to client and when i get this numbers in client(unity) i want instantiate a bullet in this numbers(x,y) that i get.i can do all of thats but when i instantiate the bullet the unity will crach and sometimes i get this error :

m_ThreadCheck && !Thread::Equals Current Thread ID(m_ThreadID)

in addition,when i build the program in unity i do not get the error but it is not run as like i want.

Project Link:http://www.multiupload.com/7EW8KQNJ3N

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by StephanK · Jun 14, 2010 at 07:18 AM

Unity is not Thread-safe. I guess you have a thread running, that checks for input from the socket and that instantiates the bullet. This won't work, as Unity can only instantiate objects during certain times in the game loop. You can't know when the message arrives and if it does during a time other than update time unity will probably crash. To fix this you have to put all code that may change unitys state (especially the renderstate) into one of the Update functions. So you will have to either check the socket from within the update function, or if you need to run it on its own thread don't interact with the engine directly, but rather take a note (set a bool) when a message arrived and deal with it on the next update.

void Update() { if (needsUpdate) { // instantiate/update objects here needsUpdate = false; }

void SocketThread() { string msg = socket.Read(); if (msg != "") needsUpdate = true; }

The part where the socket is read is pseudo-code and probably won't compile, but you should get the idea.

Comment
Add comment · Show 5 · 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 Milad · Jun 14, 2010 at 09:22 AM 0
Share

thanks my freind.i do it and give you the result.

avatar image Milad · Jun 14, 2010 at 09:23 AM 0
Share

by the way,did u see my file?

avatar image StephanK · Jun 14, 2010 at 09:27 AM 0
Share

I can see the link, but didn't open it.

avatar image Milad · Jun 14, 2010 at 07:10 PM 0
Share

if you can please run the my code,and help me more.so thanks.

avatar image StephanK · Jun 14, 2010 at 08:09 PM 0
Share

Do you get the same error? Did you change your code?

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

No one has followed this question yet.

Related Questions

Threaded Socket Client with Thread-Safe Queue for Unity 0 Answers

Thread pool or socket bug? please help,,, 0 Answers

Is it possible to query the Unity (3.0) transform tree from a secondary thread? 1 Answer

Socket continues to operate even after stopping the run 1 Answer

In edit mode SocketServer thread will be stopped when any asset change 1 Answer


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