[syphon-implementations] r217 committed - fix for crash bug when client exits. thanks for bug report Alejandro.

17 views
Skip to first unread message

syphon-impl...@googlecode.com

unread,
Jul 2, 2013, 10:22:53 PM7/2/13
to syphon-de...@googlegroups.com
Revision: 217
Author: connec...@gmail.com
Date: Tue Jul 2 19:22:30 2013
Log: fix for crash bug when client exits. thanks for bug report
Alejandro.
http://code.google.com/p/syphon-implementations/source/detail?r=217

Deleted:
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Resources/syphonSupportedShader.mat
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Resources/syphonSupportedShaderCloth.mat
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/SyphonServerAndClient.unity
Modified:
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/Syphon.cs
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/SyphonObject/SyphonClientObject.cs
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/SyphonTexture/SyphonClientTexture.cs
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/SyphonTexture/SyphonServerTexture.cs
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/ServerWatcherUtility.mm
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonCacheData.h
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonCacheData.mm
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonClientUnity.m
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonServerUnity.mm
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonUnity.mm

=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Resources/syphonSupportedShader.mat
Fri Feb 22 17:19:10 2013
+++ /dev/null
Binary file, no diff available.
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Resources/syphonSupportedShaderCloth.mat
Mon Feb 25 12:46:36 2013
+++ /dev/null
Binary file, no diff available.
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/SyphonServerAndClient.unity
Mon Feb 25 13:48:21 2013
+++ /dev/null
Binary file, no diff available.
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/Syphon.cs
Mon Feb 25 12:46:36 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/Syphon.cs
Tue Jul 2 19:22:30 2013
@@ -49,8 +49,6 @@
public static extern int CreateServerTexture(string serverName);
[DllImport ("SyphonUnityPlugin")]
public static extern bool CacheServerTextureValues(int textureId, int
width, int height, int syphonServerTextureInstance);
- [DllImport ("SyphonUnityPlugin")]
- public static extern void KillServerTexture(int killMe);

//client related
[DllImport ("SyphonUnityPlugin")]
@@ -58,7 +56,7 @@
[DllImport ("SyphonUnityPlugin")]
public static extern bool CacheClientTextureValues(int textureId, int
width, int height, int syphonClientTextureInstance);
[DllImport ("SyphonUnityPlugin")]
- public static extern void KillClientTexture(int killMe);
+ public static extern void QueueToKillTexture(int killMe);
[DllImport ("SyphonUnityPlugin")]
public static extern void UpdateTextureSizes();

@@ -69,12 +67,7 @@
private static extern int SyServerCount();
[DllImport ("SyphonUnityPlugin")]
private static extern int SyServerAtIndex(int counter, StringBuilder
myAppName, StringBuilder myName, StringBuilder myUuId);
- [DllImport ("SyphonUnityPlugin")]
- private static extern void InitServerPlugin();

-
-
-

[SerializeField]
public Dictionary<string, Dictionary<string, SyphonServerObject>> servers
= new Dictionary<string, Dictionary<string, SyphonServerObject>>();
@@ -181,6 +174,25 @@
public delegate void RepaintServerListGUIHandler();
public event RepaintServerListGUIHandler RepaintServerListGUI;

+
+
+
+ [AttributeUsage (AttributeTargets.Method)]
+ public sealed class MonoPInvokeCallbackAttribute : Attribute {
+ public MonoPInvokeCallbackAttribute (Type t) {}
+ }
+
+ private delegate void OnTextureSizeChangedDelegate(int ptr, int width,
int height);
+ private delegate void OnAnnounceServerDelegate(string appName, string
name, string uuid, int serverPtr);
+ private delegate void OnRetireServerDelegate(string appName, string
name, string uuid);
+ private delegate void OnUpdateServerDelegate(string appName, string name,
string uuid, int serverPtr);
+
+
+
+ [DllImport ("SyphonUnityPlugin")]
+ private static extern void
InitDelegateCallbacks(OnTextureSizeChangedDelegate texSize,
OnAnnounceServerDelegate announceServer, OnRetireServerDelegate
retireServer, OnUpdateServerDelegate updateServer);
+
+
//these are used to tell the associated client texture gameobject script
to announce/etc a server
public delegate void AnnounceServerHandler(string appName, string name);
public static event AnnounceServerHandler AnnounceServer;
@@ -195,8 +207,8 @@


public void initSyphonServers(){
- // StackTrace stackTrace = new StackTrace();
- // UnityEngine.Debug.Log("init'd syphon servers "+
stackTrace.GetFrame(1).GetMethod().Name);
+// StackTrace stackTrace = new StackTrace();
+// UnityEngine.Debug.Log("init'd syphon servers "+
stackTrace.GetFrame(1).GetMethod().Name);

//clear the servers array
servers.Clear();
@@ -230,7 +242,7 @@

public static void cacheAssembly(){
updatedAssembly = true;
- InitServerPlugin();
+ InitDelegateCallbacks(OnTextureSizeChanged, OnAnnounceServer,
OnRetireServer, OnUpdateServer);
}

public static bool assemblyIsUpdated(){
@@ -279,6 +291,7 @@
initialized = true;
}

+ [MonoPInvokeCallback (typeof (OnTextureSizeChangedDelegate))]
public static void OnTextureSizeChanged(int ptr, int width, int height){
// Debug.Log("Syphon Texture size changed! ptr: " + ptr + " w/h: " +
width + " " + height);

@@ -289,9 +302,10 @@
}
}

+ [MonoPInvokeCallback (typeof (OnAnnounceServerDelegate))]
public static void OnAnnounceServer(string appName, string name, string
uuid, int serverPtr){
- // UnityEngine.Debug.Log("Announcing the server with the appName: "
- // + appName + ", name: " + name + ", uuid: " + uuid + " server
Pointer: "+ (int)serverPtr);
+// UnityEngine.Debug.Log("Announcing the server with the appName: "
+// + appName + ", name: " + name + ", uuid: " + uuid + " server
Pointer: "+ (int)serverPtr);

if(!Syphon.Servers.ContainsKey(appName)){
Syphon.Servers.Add(appName, new Dictionary<string,
SyphonServerObject>());
@@ -311,7 +325,8 @@
AnnounceServer(appName, name);
}

- public static void OnUpdateServer(string appName, string name, string
uuid, int serverPtr){
+ [MonoPInvokeCallback (typeof (OnUpdateServerDelegate))]
+ public static void OnUpdateServer(string appName, string name, string
uuid, int serverPtr){
// UnityEngine.Debug.Log("Updating the server with the appName: " +
appName + ", name: " + name + ", uuid: " + uuid);

// for(int i = 0; i < myself.myClientObjects.Count; i++){
@@ -324,7 +339,9 @@
UpdateServer(appName, name);
}

+ [MonoPInvokeCallback (typeof (OnRetireServerDelegate))]
public static void OnRetireServer(string appName, string name, string
uuid){
+// UnityEngine.Debug.Log(appName + " "+ name + " " + uuid + " are leaving
now.");
if(Syphon.Servers.ContainsKey(appName)){
if(name == ""){
if(Syphon.Servers[appName].ContainsKey(Syphon.UNNAMED_STRING)){
@@ -350,6 +367,7 @@

if(RetireServer != null)
RetireServer(appName, name);
+
}

public void UpdateServerNames(){
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/SyphonObject/SyphonClientObject.cs
Mon Feb 25 12:46:36 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/SyphonObject/SyphonClientObject.cs
Tue Jul 2 19:22:30 2013
@@ -190,7 +190,7 @@
public void RetireServer(string appName, string name){
if(initialized && MatchesDescription(appName, name)){
retireServerQueue = true;
- // DestroySyphonClient();
+// DestroySyphonClient();
// Debug.Log("retired app:" + appName + " name: " + name );
}
}
@@ -203,8 +203,9 @@


public void DestroySyphonClient(){
- //Debug.Log("destroying syphon client");
+// UnityEngine.Debug.Log("destroying syphon client");
if(attachedTexture != null){
+ RenderTexture.active = null;
attachedTexture.Release();
//RenderTexture.active = null;
UnityEngine.Object.DestroyImmediate(attachedTexture);
@@ -212,8 +213,12 @@
}

if(syphonClientPointer != 0 && initialized){
- // Debug.Log("DESTROY plugin syphon client destroy method...");
- Syphon.KillClientTexture(syphonClientPointer);
+
+// StackTrace stackTrace = new StackTrace();
+// UnityEngine.Debug.Log("DESTROY plugin syphon client destroy method,
from : " + stackTrace.GetFrame(1).GetMethod().Name);
+
+ Syphon.QueueToKillTexture(syphonClientPointer);
+ GL.IssuePluginEvent(syphonClientPointer);
syphonClientPointer = 0;
initialized = false;
if(RetireClient != null){
@@ -235,23 +240,12 @@
}

public void Render(){
-
-
- if(syphonClientPointer != 0 && initialized){
-
- //you only need to render once per frame for each texture.
-// if(lastTime != Time.time){
-
+ if(syphonClientPointer != 0 && initialized){
+ //you need to render once per frame for each texture.
Syphon.SafeMaterial.SetPass(0);
RenderTexture.active = attachedTexture;
GL.IssuePluginEvent(syphonClientPointer);
// RenderTexture.active = null;
-
-// }
-// else{
-// UnityEngine.Debug.Log("BANG! " + Time.time);
-// }
-// lastTime = Time.time;
}
}

@@ -263,8 +257,7 @@
DefineSyphonClient(announceServerQueueServer);
InitSyphonClient();
// StackTrace stackTrace = new StackTrace();
- // UnityEngine.Debug.Log("init'd syphon client " + boundAppName + " "
+ boundName + stackTrace.GetFrame(1).GetMethod().Name);
-
+ // UnityEngine.Debug.Log("init'd syphon client " + boundAppName + " "
+ boundName + stackTrace.GetFrame(1).GetMethod().Name);
// Debug.Log("announced app:" +
announceServerQueueServer.SyphonServerDescriptionAppName + " name: " +
announceServerQueueServer.SyphonServerDescriptionName );
announceServerQueue = false;
announceServerQueueServer = null;
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/SyphonTexture/SyphonClientTexture.cs
Mon Feb 25 12:46:36 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/SyphonTexture/SyphonClientTexture.cs
Tue Jul 2 19:22:30 2013
@@ -36,7 +36,7 @@
public string clientName = "";
private SyphonClientObject clientObject;
void Start () {
- clientObject = Syphon.GetSyphonClient(clientAppName, clientName);
+ clientObject = Syphon.GetSyphonClient(clientAppName, clientName);
//if the client object exists,
if(clientObject != null){
//if the texture has been initialized, apply its texture to something.
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/SyphonTexture/SyphonServerTexture.cs
Mon Feb 25 12:46:36 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/SyphonTexture/SyphonServerTexture.cs
Tue Jul 2 19:22:30 2013
@@ -57,8 +57,10 @@
}

public void OnDestroy() {
- if(syphonServerTextureInstance != 0)
- Syphon.KillServerTexture(syphonServerTextureInstance);
+ if(syphonServerTextureInstance != 0){
+ Syphon.QueueToKillTexture(syphonServerTextureInstance);
+ GL.IssuePluginEvent(syphonServerTextureInstance);
+ }
syphonServerTextureInstance = 0;
syphonServerTextureValuesCached = false;
srcTex = null;
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/ServerWatcherUtility.mm
Sun Mar 25 09:27:44 2012
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/ServerWatcherUtility.mm
Tue Jul 2 19:22:30 2013
@@ -33,50 +33,50 @@
#import <OpenGL/OpenGL.h>
#import <string.h>
#import "SyphonCacheData.h"
-#ifdef __cplusplus
-
-extern "C" {
- typedef void* MonoDomain;
- typedef void* MonoAssembly;
- typedef void* MonoImage;
- typedef void* MonoClass;
- typedef void* MonoObject;
- typedef void* MonoMethodDesc;
- typedef void* MonoMethod;
- typedef void* MonoString;
- typedef int gboolean;
- typedef void* gpointer;
+//#ifdef __cplusplus
+//
+//extern "C" {
+// typedef void* MonoDomain;
+// typedef void* MonoAssembly;
+// typedef void* MonoImage;
+// typedef void* MonoClass;
+// typedef void* MonoObject;
+// typedef void* MonoMethodDesc;
+// typedef void* MonoMethod;
+// typedef void* MonoString;
+// typedef int gboolean;
+// typedef void* gpointer;

- MonoDomain *mono_domain_get();
- MonoAssembly *mono_domain_assembly_open(MonoDomain *domain, const char
*assemblyName);
- MonoImage *mono_assembly_get_image(MonoAssembly *assembly);
- void mono_assembly_close (MonoAssembly *assembly);
- MonoMethodDesc *mono_method_desc_new(const char *methodString, gboolean
useNamespace);
- MonoMethodDesc *mono_method_desc_free(MonoMethodDesc *desc);
- MonoMethod *mono_method_desc_search_in_image(MonoMethodDesc *methodDesc,
MonoImage *image);
- MonoObject *mono_runtime_invoke(MonoMethod *method, void *obj, void
**params, MonoObject **exc);
- MonoClass *mono_class_from_name(MonoImage *image, const char
*namespaceString, const char *classnameString);
- MonoMethod *mono_class_get_methods(MonoClass*, gpointer* iter);
- MonoString *mono_string_new(MonoDomain *domain, const char *text);
-
- char* mono_method_get_name (MonoMethod *method);
-}
-MonoDomain *domain;
-NSString *assemblyPath;
-MonoAssembly *monoAssembly;
-MonoImage *monoImage;
-
-MonoMethodDesc *updateServerDesc;
-MonoMethod *updateServer;
-MonoMethodDesc *announceServerDesc;
-MonoMethod *announceServer;
-MonoMethodDesc *retireServerDesc;
-MonoMethod *retireServer;
-
-MonoMethodDesc *textureSizeChangedDesc;
-MonoMethod *textureSizeChanged;
-
-#endif
+// MonoDomain *mono_domain_get();
+// MonoAssembly *mono_domain_assembly_open(MonoDomain *domain, const char
*assemblyName);
+// MonoImage *mono_assembly_get_image(MonoAssembly *assembly);
+// void mono_assembly_close (MonoAssembly *assembly);
+// MonoMethodDesc *mono_method_desc_new(const char *methodString,
gboolean useNamespace);
+// MonoMethodDesc *mono_method_desc_free(MonoMethodDesc *desc);
+// MonoMethod *mono_method_desc_search_in_image(MonoMethodDesc
*methodDesc, MonoImage *image);
+// MonoObject *mono_runtime_invoke(MonoMethod *method, void *obj, void
**params, MonoObject **exc);
+// MonoClass *mono_class_from_name(MonoImage *image, const char
*namespaceString, const char *classnameString);
+// MonoMethod *mono_class_get_methods(MonoClass*, gpointer* iter);
+// MonoString *mono_string_new(MonoDomain *domain, const char *text);
+//
+// char* mono_method_get_name (MonoMethod *method);
+//}
+//MonoDomain *domain;
+//NSString *assemblyPath;
+//MonoAssembly *monoAssembly;
+//MonoImage *monoImage;
+//
+//MonoMethodDesc *updateServerDesc;
+//MonoMethod *updateServer;
+//MonoMethodDesc *announceServerDesc;
+//MonoMethod *announceServer;
+//MonoMethodDesc *retireServerDesc;
+//MonoMethod *retireServer;
+//
+//MonoMethodDesc *textureSizeChangedDesc;
+//MonoMethod *textureSizeChanged;
+//
+//#endif

@interface ServerWatcherUtility : NSObject
{
@@ -86,6 +86,12 @@
}

@end
+
+static void (*OnTextureSizeChangedDelegate)(int, int, int);
+static void (*OnAnnounceServerDelegate)(const char*,const char*,const
char*,int);
+static void (*OnUpdateServerDelegate)(const char*,const char*,const
char*,int);
+static void (*OnRetireServerDelegate)(const char*,const char*,const char*);
+
static NSString* pathToBundle = nil;

static ServerWatcherUtility* watcherUtility;
@@ -96,17 +102,22 @@
{

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
const char* param2 = [[[notification object]
objectForKey:SyphonServerDescriptionNameKey] UTF8String];
const char* param1 = [[[notification object]
objectForKey:SyphonServerDescriptionAppNameKey] UTF8String];
const char* param3 = [[[notification object]
objectForKey:SyphonServerDescriptionUUIDKey] UTF8String];
- //NSLog(@"announceing server! %s %s %s", param2, param1, param3);
-
-
- MonoString* myString = mono_string_new(domain, param1);
- MonoString* myString2 = mono_string_new(domain, param2);
- MonoString* myString3 = mono_string_new(domain, param3);
- void *args[] = { myString, myString2, myString3 };
- mono_runtime_invoke(retireServer, NULL, args, NULL);
+
+// MonoString* myString = mono_string_new(domain, param1);
+// MonoString* myString2 = mono_string_new(domain, param2);
+// MonoString* myString3 = mono_string_new(domain, param3);
+// void *args[] = { myString, myString2, myString3 };
+// mono_runtime_invoke(retireServer, NULL, args, NULL);
+// param1 = NULL;
+// param2 = NULL;
+// param3 = NULL;
+
+ OnRetireServerDelegate(param1, param2, param3);
+
[pool drain];

}
@@ -127,11 +138,15 @@
}
}

- MonoString* myString = mono_string_new(domain, param1);
- MonoString* myString2 = mono_string_new(domain, param2);
- MonoString* myString3 = mono_string_new(domain, param3);
- void *args[] = { myString, myString2, myString3, &serverPtr };
- mono_runtime_invoke(updateServer, NULL, args, NULL);
+// MonoString* myString = mono_string_new(domain, param1);
+// MonoString* myString2 = mono_string_new(domain, param2);
+// MonoString* myString3 = mono_string_new(domain, param3);
+// void *args[] = { myString, myString2, myString3, &serverPtr };
+// mono_runtime_invoke(updateServer, NULL, args, NULL);
+// param1 = NULL;
+// param2 = NULL;
+// param3 = NULL;
+ OnUpdateServerDelegate(param1, param2, param3, serverPtr);

[pool drain];

@@ -141,7 +156,7 @@
- (void)handleServerAnnounce:(NSNotification *)notification
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- const char* param2 = [[[notification object]
objectForKey:SyphonServerDescriptionNameKey] UTF8String];
+ const char* param2 = [[[notification object]
objectForKey:SyphonServerDescriptionNameKey] UTF8String];
const char* param1 = [[[notification object]
objectForKey:SyphonServerDescriptionAppNameKey] UTF8String];
const char* param3 = [[[notification object]
objectForKey:SyphonServerDescriptionUUIDKey] UTF8String];
// NSLog(@"announceing server! %s %s %s", param2, param1, param3);
@@ -154,11 +169,16 @@
}
}

- MonoString* myString = mono_string_new(domain, param1);
- MonoString* myString2 = mono_string_new(domain, param2);
- MonoString* myString3 = mono_string_new(domain, param3);
- void *args[] = { myString, myString2, myString3, &serverPtr };
- mono_runtime_invoke(announceServer, NULL, args, NULL);
+// MonoString* myString = mono_string_new(domain, param1);
+// MonoString* myString2 = mono_string_new(domain, param2);
+// MonoString* myString3 = mono_string_new(domain, param3);
+// void *args[] = { myString, myString2, myString3, &serverPtr };
+// mono_runtime_invoke(announceServer, NULL, args, NULL);
+// param1 = NULL;
+// param2 = NULL;
+// param3 = NULL;
+ OnAnnounceServerDelegate(param1, param2, param3, serverPtr);
+
[pool drain];
}

@@ -171,34 +191,46 @@

#ifdef __cplusplus
extern "C" {
+
+ void InitDelegateCallbacks(void (*texSize)(int, int, int),
+ void (*announceServer)(const char*,const char*,const char*,int),
+ void (*retireServer)(const char*,const char*,const char*),
+ void (*updateServer)(const char*,const char*,const char*,int)
+ ){
+
+ OnTextureSizeChangedDelegate = *texSize;
+ OnAnnounceServerDelegate = *announceServer;
+ OnRetireServerDelegate = *retireServer;
+ OnUpdateServerDelegate = *updateServer;
+ }


void handleTextureSizeChanged(SyphonCacheData* ptr){
- void *args[] = { &ptr, &(ptr->textureWidth), &(ptr->textureHeight)
};
- mono_runtime_invoke(textureSizeChanged, NULL, args, NULL);
-
+// void *args[] = { &ptr, &(ptr->textureWidth),
&(ptr->textureHeight) };
+// mono_runtime_invoke(textureSizeChanged, NULL, args, NULL);
+ OnTextureSizeChangedDelegate((int)ptr, ptr->textureWidth,
ptr->textureHeight);
}

- void monoMethods(){
- announceServerDesc =
mono_method_desc_new("Syphon:OnAnnounceServer", FALSE);
- announceServer = mono_method_desc_search_in_image(announceServerDesc,
monoImage);
-
- retireServerDesc = mono_method_desc_new("Syphon:OnRetireServer", FALSE);
- retireServer = mono_method_desc_search_in_image(retireServerDesc,
monoImage);
-
- updateServerDesc = mono_method_desc_new("Syphon:OnUpdateServer", FALSE);
- updateServer = mono_method_desc_search_in_image(updateServerDesc,
monoImage);
-
- textureSizeChangedDesc =
mono_method_desc_new("Syphon:OnTextureSizeChanged", FALSE);
- textureSizeChanged =
mono_method_desc_search_in_image(textureSizeChangedDesc, monoImage);
-
-
- mono_method_desc_free(announceServerDesc);
- mono_method_desc_free(retireServerDesc);
- mono_method_desc_free(updateServerDesc);
- mono_method_desc_free(textureSizeChangedDesc);
-
- }
+// void monoMethods(){
+// announceServerDesc =
mono_method_desc_new("Syphon:OnAnnounceServer", FALSE);
+// announceServer = mono_method_desc_search_in_image(announceServerDesc,
monoImage);
+//
+// retireServerDesc = mono_method_desc_new("Syphon:OnRetireServer",
FALSE);
+// retireServer = mono_method_desc_search_in_image(retireServerDesc,
monoImage);
+//
+// updateServerDesc = mono_method_desc_new("Syphon:OnUpdateServer",
FALSE);
+// updateServer = mono_method_desc_search_in_image(updateServerDesc,
monoImage);
+//
+// textureSizeChangedDesc =
mono_method_desc_new("Syphon:OnTextureSizeChanged", FALSE);
+// textureSizeChanged =
mono_method_desc_search_in_image(textureSizeChangedDesc, monoImage);
+//
+//
+// mono_method_desc_free(announceServerDesc);
+// mono_method_desc_free(retireServerDesc);
+// mono_method_desc_free(updateServerDesc);
+// mono_method_desc_free(textureSizeChangedDesc);
+//
+// }

//[[SyphonServerDirectory sharedDirectory] addObserver:watcherUtility
forKeyPath:@"servers" options:0 context:nil];

@@ -244,19 +276,21 @@
// monoMethods();
//}

-
-void InitServerPlugin(){
- assemblyPath = pathToBundle;
- // NSLog(@"SYPHON PLUGIN INIT -BUILT: %@", assemblyPath); //check if
this is the right path
- // [assemblyPath retain];
- domain = mono_domain_get();
- monoAssembly = mono_domain_assembly_open(domain,
assemblyPath.UTF8String);
- if(!monoAssembly){
- NSLog(@"ERROR OPENING THE MONO ASSEMBLY. this means that there was a
problem in the path to your Assembly. Probably means your Syphon
plugin .bundle or Syphon.cs script is not in the .Plugins folder");
- }
- monoImage = mono_assembly_get_image(monoAssembly);
- monoMethods();
-}
+
+
+
+//void InitServerPlugin(){
+// assemblyPath = pathToBundle;
+// // NSLog(@"SYPHON PLUGIN INIT -BUILT: %@", assemblyPath); //check if
this is the right path
+// // [assemblyPath retain];
+// domain = mono_domain_get();
+// monoAssembly = mono_domain_assembly_open(domain,
assemblyPath.UTF8String);
+// if(!monoAssembly){
+// NSLog(@"ERROR OPENING THE MONO ASSEMBLY. this means that there was
a problem in the path to your Assembly. Probably means your Syphon
plugin .bundle or Syphon.cs script is not in the .Plugins folder");
+// }
+// monoImage = mono_assembly_get_image(monoAssembly);
+// monoMethods();
+//}



=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonCacheData.h Fri
Feb 22 17:18:08 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonCacheData.h Tue
Jul 2 19:22:30 2013
@@ -57,4 +57,5 @@
//client related
SyphonClient* syphonClient;
bool updateTextureSizeFlag;
+ bool destroyMe;
};
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonCacheData.mm
Fri Feb 22 17:18:08 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonCacheData.mm
Tue Jul 2 19:22:30 2013
@@ -30,16 +30,19 @@
#include "SyphonCacheData.h"
SyphonCacheData::SyphonCacheData()
{
+ //used for initializing servers
syphonServer = nil;
serverName = nil;
initialized = false;
updateTextureSizeFlag = false;
pluginType = PLUGIN_SYPHON;
+ destroyMe = false;
}

SyphonCacheData::SyphonCacheData(NSDictionary* ptr)
{
- //deep copy constructor
+ //deep copy constructor. used for initializing clients with a server
description.
+ destroyMe = false;
syphonServer = nil;
serverName = nil;
initialized = false;
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonClientUnity.m
Tue Feb 26 08:50:06 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonClientUnity.m
Tue Jul 2 19:22:30 2013
@@ -37,27 +37,31 @@
//
void syphonClientDestroyResources(SyphonClient* client)
{
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- //
- // glDeleteFramebuffersEXT(1, &syphonFBO);
- // syphonFBO = 0;
- //
- // // lets create our client if we dont have it.
+// NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ //
+
+ if(syphonFBO){
+ glDeleteFramebuffersEXT(1, &syphonFBO);
+ syphonFBO = 0;
+ }
+
if(client)
{
[client stop];
[client release];
client = nil;

- //NSLog(@"destroyed Syphon Client");
+// NSLog(@"destroyed Syphon Client");
}
- [pool drain];
+// [pool drain];
}


void syphonClientPublishTexture(SyphonCacheData* ptr){
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- if(ptr->syphonClient && [ptr->syphonClient isValid]){
+// NSLog(@"PUBLISHIN SOMETHIN AT %i/ %@", (int)ptr, ptr->syphonClient);
+
+ if(ptr != NULL && ptr->syphonClient != nil && [ptr->syphonClient
isValid]){
// //should probably check if CGLGetCurrentContext() is ==
cachedContext

//lock
@@ -187,6 +191,9 @@
glPopClientAttrib();
glPopAttrib();

+
+ [image release];
+
glBindFramebufferEXT(GL_FRAMEBUFFER, previousFBO);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER, previousReadFBO);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, previousDrawFBO);
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonServerUnity.mm
Fri Feb 22 17:18:08 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonServerUnity.mm
Tue Jul 2 19:22:30 2013
@@ -69,7 +69,7 @@

void syphonServerDestroyResources(SyphonServer* server)
{
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+// NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

// lets create our client if we dont have it.
if(server != nil)
@@ -81,7 +81,7 @@
}


- [pool drain];
+// [pool drain];
}

//
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonUnity.mm Tue
Feb 26 08:50:06 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonUnity.mm Tue
Jul 2 19:22:30 2013
@@ -54,21 +54,23 @@
{
// NSLog(@"init graphics device");
cachedContext = CGLGetCurrentContext();
- NSString* bundlePath = [[[NSBundle mainBundle] bundlePath]
-
stringByAppendingPathComponent:@"Contents/Data/Managed/Assembly-CSharp-firstpass.dll"];
- if( [ [NSFileManager defaultManager]
fileExistsAtPath:bundlePath isDirectory:NO]){
- // NSLog(@"in the app!");
- pathToBundle = bundlePath;
- }
- else{
- // NSLog(@"in the editor");
- char *path = getcwd(NULL, 0);
- NSString* myString = [NSString stringWithUTF8String:
path];
- free(path);
- NSString* finalString = [myString
stringByAppendingPathComponent:@"/Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll"];
- pathToBundle = finalString;
- }
- [pathToBundle retain];
+// NSString* bundlePath = [[[NSBundle mainBundle]
bundlePath]
+//
stringByAppendingPathComponent:@"Contents/Data/Managed/Assembly-CSharp-firstpass.dll"];
+// if( [ [NSFileManager defaultManager]
fileExistsAtPath:bundlePath isDirectory:NO]){
+// // NSLog(@"in the app!");
+// pathToBundle = bundlePath;
+// }
+// else{
+// // NSLog(@"in the editor");
+// char *path=NULL;
+// size_t size;
+// path=getcwd(path,size);
+// NSString* myString = [NSString stringWithUTF8String:
path];
+// NSString* finalString = [myString
stringByAppendingPathComponent:@"/Library/ScriptAssemblies/Assembly-CSharp-firstpass.dll"];
+// pathToBundle = finalString;
+// }
+// [pathToBundle retain];
+
registerCallbacks();
break;
}
@@ -94,18 +96,24 @@
SyphonCacheData* clientPtr = new SyphonCacheData(serverPtr);
//add it to a list
syphonClients.push_back(clientPtr);
- NSLog(@"CREATED SOMETHIN AT %i, and added it to the list. count is
now %i", (int)clientPtr, (int)syphonClients.size());
+ NSLog(@"CREATED CLIENT TEXTURE AT %i, and added it to the list.
count is now %i", (int)clientPtr, (int)syphonClients.size());
return clientPtr;
}

-
+ void QueueToKillTexture(SyphonCacheData* killMe){
+ if(killMe != NULL && (int)killMe != 0){
+ killMe->destroyMe = true;
+ }
+ }
+
void KillClientTexture(SyphonCacheData* killMe){
- //NSLog(@"DESTROYED SOMETHIN AT %i", (int)killMe);
- if(killMe != nil && (int)killMe != 0){
+ NSLog(@"DESTROYED A CLIENT TEXTURE AT %i", (int)killMe);
+ if(killMe != NULL && (int)killMe != 0){
// //if the cache data says it's not a server, then
it's a client.
if(!killMe->isAServer && killMe->syphonClient != nil){
syphonClientDestroyResources(killMe->syphonClient);
- // NSLog(@"destroyed one");
+ killMe->syphonClient = nil;
+// NSLog(@"destroyed one");
}
//
//remove the selected syphonServer from the list
@@ -113,11 +121,13 @@
syphonClients.end())
{
syphonClients.remove(killMe);
- NSLog(@"removed one, count is now %i",
(int)syphonClients.size());
+// NSLog(@"removed one, count is now %i",
(int)syphonClients.size());
}
//delete the cache data associated with it
delete killMe;
- }
+ killMe->destroyMe = false;
+ killMe = NULL;
+ }
}


@@ -131,11 +141,12 @@
}

void KillServerTexture(SyphonCacheData* killMe){
- if(killMe != nil){
+ if(killMe != NULL){
if(killMe->isAServer && killMe->syphonServer != nil){
//destroy the syphon server itself,
syphonServerDestroyResources(killMe->syphonServer);
- }
+ killMe->syphonServer = nil;
+ }

//remove the selected syphonServer from the list
if (std::find(syphonServers.begin(), syphonServers.end(),
killMe) !=
@@ -144,7 +155,9 @@

//delete the cache data associated with it
delete killMe;
- }
+ killMe->destroyMe = false;
+ killMe = NULL;
+ }
}

// void FlagServerToBeKilled(SyphonCacheData* ptr){
@@ -203,11 +216,19 @@
return;

//if it's a server
- if(ptr->isAServer && ptr->initialized && ptr->serverName !=
nil){
+ if(ptr != nil && ptr->isAServer && ptr->initialized &&
ptr->serverName != nil){
+ //serialize destruction to same thread as drawing
+ if(ptr->destroyMe)
+ KillServerTexture((SyphonCacheData*)ptr);
+ else
syphonServerPublishTexture((SyphonCacheData*)ptr);
}
//if it's a client
- if(!ptr->isAServer && ptr->initialized){
+ if(ptr != nil && !ptr->isAServer && ptr->initialized){
+ //serialize destruction to same thread as drawing
+ if(ptr->destroyMe)
+ KillClientTexture((SyphonCacheData*)ptr);
+ else
syphonClientPublishTexture((SyphonCacheData*)ptr);
}

Reply all
Reply to author
Forward
0 new messages