Updated LibPdInstance.cs.
This commit is contained in:
parent
4c17055789
commit
1b3c08893a
1 changed files with 33 additions and 23 deletions
|
|
@ -437,12 +437,15 @@ public class LibPdInstance : MonoBehaviour
|
||||||
|
|
||||||
/// We use this to ensure libpd -> Unity events get sent to all LibPdInstances.
|
/// We use this to ensure libpd -> Unity events get sent to all LibPdInstances.
|
||||||
/*!
|
/*!
|
||||||
It's also used to ensure libpd_queued_release() only gets called once
|
IMPORTANT: Bear in mind that C#'s List is not thread-safe. That's not a
|
||||||
all LibPdInstances have been destroyed.
|
problem for the way we're using it at the time of writing, because
|
||||||
|
activeInstances only gets accessed from the main thread in OnEnable,
|
||||||
|
OnDisable and the various BangOutput, FloatOutput, etc. delegates that
|
||||||
|
themselves get called from Update.
|
||||||
|
|
||||||
|
activeInstances should *NEVER* be accessed from the audio thread though.
|
||||||
*/
|
*/
|
||||||
private static List<LibPdInstance> activeInstances = new List<LibPdInstance>();
|
private static List<LibPdInstance> activeInstances = new List<LibPdInstance>();
|
||||||
/// The WeakReference pointing to ourselves in activeInstances.
|
|
||||||
//private WeakReference instanceReference;
|
|
||||||
|
|
||||||
/// True if we were unable to intialise Pd's audio processing.
|
/// True if we were unable to intialise Pd's audio processing.
|
||||||
private bool pdFail = false;
|
private bool pdFail = false;
|
||||||
|
|
@ -451,8 +454,10 @@ public class LibPdInstance : MonoBehaviour
|
||||||
/// True if we have successfully loaded our patch.
|
/// True if we have successfully loaded our patch.
|
||||||
private bool loaded = false;
|
private bool loaded = false;
|
||||||
|
|
||||||
/// Global variable used to ensure we don't initialise LibPd more than once.
|
/// Global variable used to ensure we don't initialise libpd more than once.
|
||||||
private static bool pdInitialised = false;
|
private static bool pdInitialised = false;
|
||||||
|
/// Global reference count used to determine when to un-initialise libpd.
|
||||||
|
private static int numInstances = 0;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region events
|
#region events
|
||||||
|
|
@ -617,7 +622,10 @@ public class LibPdInstance : MonoBehaviour
|
||||||
libpd_finish_message("pd", "dsp");
|
libpd_finish_message("pd", "dsp");
|
||||||
|
|
||||||
if(!patchFail)
|
if(!patchFail)
|
||||||
|
{
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
++numInstances;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -658,8 +666,10 @@ public class LibPdInstance : MonoBehaviour
|
||||||
libpd_free_instance(instance);
|
libpd_free_instance(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--numInstances;
|
||||||
|
|
||||||
//If we're the last instance left, release libpd's ringbuffer.
|
//If we're the last instance left, release libpd's ringbuffer.
|
||||||
if(pdInitialised && (activeInstances.Count < 1))
|
if(pdInitialised && (numInstances < 1))
|
||||||
{
|
{
|
||||||
if(printHook != null)
|
if(printHook != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue