1111import java .util .ArrayList ;
1212import java .util .List ;
1313
14+ import martin .tempest .core .exceptions .TSDRAlreadyRunningException ;
1415import martin .tempest .core .exceptions .TSDRException ;
1516import martin .tempest .core .exceptions .TSDRLibraryNotCompatible ;
1617import martin .tempest .sources .TSDRSource ;
@@ -29,6 +30,8 @@ public class TSDRLibrary {
2930 private int width ;
3031 private int height ;
3132
33+ volatile private boolean nativerunning = false ;
34+
3235 // If the binaries weren't loaded, this will go off
3336 private static TSDRLibraryNotCompatible m_e = null ;
3437 private final List <FrameReadyCallback > callbacks = new ArrayList <FrameReadyCallback >();
@@ -143,13 +146,15 @@ public TSDRLibrary() throws TSDRException {
143146 public native void setResolution (int width , int height , double refreshrate ) throws TSDRException ;
144147
145148 public void startAsync (final TSDRSource plugin , int width , int height , double refreshrate ) throws TSDRException {
149+ if (nativerunning ) throw new TSDRAlreadyRunningException ("" );
150+
146151 final String absolute_path = plugin .absolute ? plugin .libname : (extractLibrary (plugin .libname ).getAbsolutePath ());
147152
148153 setResolution (width , height , refreshrate );
149154
150155 new Thread () {
151156 public void run () {
152-
157+ nativerunning = true ;
153158 Runtime .getRuntime ().addShutdownHook (unloaderhook );
154159 try {
155160 nativeStart (absolute_path , plugin .getParams ());
@@ -161,6 +166,7 @@ public void run() {
161166 } catch (Throwable e ) {};
162167 }
163168 for (final FrameReadyCallback callback : callbacks ) callback .onClosed (TSDRLibrary .this );
169+ nativerunning = false ;
164170 };
165171 }.start ();
166172
0 commit comments