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 eeytan · Dec 30, 2014 at 03:57 AM · crashplugin

My plugin runs once but not twice

I have a plugin that calls C++ code. When the game starts, it calls this extern C++ function:

 void startPlugin() {
   MyClass::instance = new MyClass();
   MyClass::instance->process();
 }

The process method runs an infinite loop that processes data and goes on, as long at the keepRunning member is true. Because it runs an infinite loop and blocks, this method is called within its own thread.

When the game ends I run this extern method from C#:

 void stopPlugin() {
   MyClass::instance->keepRunning = false;
   sleep(1); // Make sure the process loop is done. It should take less than one frame, but just to be sure...
   MyClass::cleanup();
 }

Which refers to this method:

 void MyClass::cleanup() {
   delete instance;
   instance = NULL;
 }

Based on what the console says, these methods are indeed run.

On Mac, this works the first time. I can start the game in the editor and stop it in the editor and everything works fine. But if I try to run it a second time without restarting the Unity editor, the whole editor freezes. Sometimes it takes three times instead of two, but invariably the second or third attempt to play freezes Unity completely. The cursor changes to the spinning pinwheel.

The log says:

 Starting.
 
 (Filename: /Applications/buildAgent/work/d63dfc6385190b60/artifacts/MacEditorGenerated/UnityEngineDebug.cpp Line: 49)

 Receiving unhandled NULL exception
 Launching bug reporter
 Obtained 37 stack frames.
 #0  0x00000090019390 in _platform_memmove$VARIANT$sse42

And then the stack trace brings up the function that calls the extern function.

Trying to join the thread that was running startPlugin freezes the editor on stop. I don't think it should do that. After all, at that stage, the loop is over and the instance cleaned. This is not guesswork, there are visible side effects: ending the loop turns off the computer's camera and I can see the light of the camera go off. Also a debug message is sent in C# after the call to startPlugin returns. So there is no doubt that the loop is over.

Am I doing something obviously wrong?

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
0

Answer by eeytan · Dec 31, 2014 at 03:01 AM

I found my answer.

Even though no thread is called inside of the C++, I still need call pthread_exit(this) at the end of the process method. This is not necessary on Windows, but it is on Mac. After that, all works.

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

2 People are following this question.

avatar image avatar image

Related Questions

Firefox 18 and Unity don´t work anymore... 2 Answers

android plugin app crashing 0 Answers

Using Ad plugins on Android leads to extra crashes 0 Answers

OSX 10.10.3 Unity 5.0.2f1 Personal Crash on start 1 Answer

Access violation in plugin: 'GetThreadedGfxDevice(...) returned nullptr.' 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