<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
<div>I think I know where the problem is:</div><div><br></div><div>(In RtAudio.cpp file)</div><div><br></div><div>In&nbsp;void RtApiDs :: stopStream(), in line 4485, there is this:</div><div><br></div><div>.....</div><div><div>if ( handle-&gt;drainCounter == 0 ) {</div><div>&nbsp; &nbsp; &nbsp; handle-&gt;drainCounter = 2;</div></div><div>...</div><div>&nbsp;WaitForSingleObject( handle-&gt;condition, INFINITE ); &nbsp;// block until signaled</div><div>...</div><div>}</div><div>.....</div><div><br></div><div>Then, in line 4639 ( void RtApiDs :: callbackEvent() ) there is this:</div><div><br></div><div><div>if ( handle-&gt;drainCounter == 2 ) {</div><div>&nbsp; &nbsp; &nbsp; // &nbsp; &nbsp; &nbsp;MUTEX_UNLOCK( &amp;stream_.mutex );</div><div>&nbsp; &nbsp; &nbsp; abortStream();</div><div>&nbsp; &nbsp; &nbsp; return;</div><div>&nbsp; &nbsp; }</div></div><div>....</div><div><br></div><div>So stopStream() sets drainCounter to 2, and waits until signaled (&nbsp;<span style="font-size: 10pt; ">WaitForSingleObject(...) ).</span>
callbackEvent()&nbsp;<span style="font-size: 10pt; ">&nbsp;then checks if drainCounter == 2 and if thatīs the case, it aborts the stream. BUT, just before 4639, there is this:</span></div><div><span style="font-size: 10pt; "><br></span></div><div><span style="font-size: 10pt; "><div>handle-&gt;drainCounter = callback( stream_.userBuffer[0], stream_.userBuffer[1],</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;stream_.bufferSize, streamTime, status, info-&gt;userData );</div><div><br></div><div>And my callback always returns 0. So if stopStream() sets drainCounter to 2 and the user callback returns (resetting drainCounter to 0) before callbackEvent() has the oportunity to notice that drainCounter had been set to 2, the stream will be never aborted (because it will be only if drainCounter == 2).</div><div><br></div><div>Hope this makes sense.</div><div><br></div><div>Carlos</div></span></div><div><br></div><div><br></div>                                               </div></body>
</html>