# Issue with StopThread

**URL:** <https://forum.juce.com/t/issue-with-stopthread/15675>\
**Category:** General JUCE discussion\
**Created:** [October 8, 2015, 9:06pm UTC](https://forum.juce.com/t/issue-with-stopthread/15675 "2015-10-08T21:06:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![darrenw2112](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@darrenw2112](https://forum.juce.com/u/darrenw2112)\
**Post date:** [October 8, 2015, 9:06pm UTC](https://forum.juce.com/t/issue-with-stopthread/15675/1 "2015-10-08T21:06:34Z")

</div>

I have been using Juce on a project for over a year&nbsp;and I updated and it just starting EXC\_BAD\_ACCESS when I call stopThread(). &nbsp;Before I call stop thread() I am setting a variable which should exit the loop anyway (and this is working - I have always also called stopThread(1000) after just to make sure). &nbsp;The issue is in Thread::closeThreadHandle() threadId. &nbsp;threadId at this point points to 0x0. &nbsp;Although, sometimes the error is in Thread::threadEntryPoint()&nbsp;&nbsp;

currentThreadHolder-\>value.releaseCurrentThreadStorage();

The issue seems to be that it is stopping from natural causes and by me calling stopTread(1000) (both of which are cleaning up at the same time). &nbsp;I have never had an issue with this before and I did not see any changes in the Juce code tree that were made that could affect this.

If I do not call stopThread(withsomewait), it is not always finished in time and I get an assertion error (bad karma) occsasionally.

Any Ideas?

Thanks,  
Darren&nbsp;

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 9, 2015, 9:04am UTC](https://forum.juce.com/t/issue-with-stopthread/15675/2 "2015-10-09T09:04:22Z")

</div>

This isn't anything that's wrong or changed in the library, you just need to make sure you handle your object lifetimes correctly and don't go calling methods on a null pointer!

Very hard to give more specific advice - it's up to you to figure out what's the most&nbsp;appropriate way to handle objects based on what you're trying to do.

---

<div class="post-metadata">

**Author:** ![darrenw2112](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@darrenw2112](https://forum.juce.com/u/darrenw2112)\
**Post date:** [October 9, 2015, 3:20pm UTC](https://forum.juce.com/t/issue-with-stopthread/15675/3 "2015-10-09T15:20:50Z")

</div>

Jules,

My bad, the issue is with an ffmpeg library underneath (this should be fun to find). &nbsp; Anyway, &nbsp;this gave me an excuse to clean up my code a bit.

As always, thanks for being so responsive.

Darren

​
