Skip to content

Commit e1267be

Browse files
committed
a10: fixed a bug with OnRetireServer crashing with OpenFrameworks servers exiting.
1 parent f9e13f7 commit e1267be

File tree

16 files changed

+83
-60
lines changed

16 files changed

+83
-60
lines changed

Syphon Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/Syphon.cs

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ public static void OnTextureSizeChanged(int ptr, int width, int height){
356356
public static void OnAnnounceServer(string appName, string name, string uuid, IntPtr serverPtr){
357357
// UnityEngine.Debug.Log("Announcing the server with the appName: "
358358
// + appName + ", name: " + name + ", uuid: " + uuid + " server Pointer: "+ (int)serverPtr);
359-
360-
359+
361360
//if we don't yet have a key for that app, create a new dictionary entry.
362361
if(!Syphon.Servers.ContainsKey(appName)){
363362
Syphon.Servers.Add(appName, new Dictionary<string, SyphonServerObject>());
@@ -372,8 +371,7 @@ public static void OnAnnounceServer(string appName, string name, string uuid, In
372371
//if it's not empty, just create a normal entry and SyphonServerObject.
373372
else if(!Syphon.Servers[appName].ContainsKey(name)){
374373
Syphon.Servers[appName].Add(name, new SyphonServerObject(appName, name, uuid, serverPtr));
375-
}
376-
374+
}
377375
//TODO: this is dumb, remove this.
378376
Instance.UpdateServerNames();
379377

@@ -401,38 +399,43 @@ public static void OnUpdateServer(string appName, string name, string uuid, IntP
401399

402400
[MonoPInvokeCallback (typeof (OnRetireServerDelegate))]
403401
public static void OnRetireServer(string appName, string name, string uuid){
404-
// UnityEngine.Debug.Log(appName + " "+ name + " " + uuid + " are leaving now.");
402+
string realAppName = "";
403+
string realName = "";
405404

406405
//if there are any ACTIVE client singleton objects in use,
407406
//destroy them immediately.
408407
//destroy their texture and destroy the pointer to them, and remove them from the SyphonClients list.
409-
SyphonClientObject result = Syphon.GetSyphonClient(appName, name);
408+
SyphonClientObject result = Syphon.GetSyphonClient(uuid);
410409
if(result){
410+
//because the Syphon callback may not have a valid appName and name key in the OnServerRetire Syphon callback,
411+
//we need to ensure we get the extract those cached names from the uuid/instance.
412+
realAppName = result.BoundAppName;
413+
realName = result.BoundName;
414+
411415
DestroyClient (result);
412-
}
413-
//-----------------------------
414-
415-
//now remove the server name
416-
//if it doesn't contain the appName key, you shouldn't have to do anything.
417-
if(Syphon.Servers.ContainsKey(appName)){
418-
if(name == ""){
416+
}
417+
418+
// //now remove the server name
419+
// //if it doesn't contain the appName key, you shouldn't have to do anything.
420+
if(Syphon.Servers.ContainsKey(realAppName)){
421+
if(realName == ""){
419422
//if the name is UNNAMED_STRING and it contains the unnamed string, remove the server from the list.
420-
if(Syphon.Servers[appName].ContainsKey(Syphon.UNNAMED_STRING)){
421-
Syphon.Servers[appName].Remove(Syphon.UNNAMED_STRING);
423+
if(Syphon.Servers[realAppName].ContainsKey(Syphon.UNNAMED_STRING)){
424+
Syphon.Servers[realAppName].Remove(Syphon.UNNAMED_STRING);
422425

423426
//if there are no more objects in the dictionary list for that app, remove the associated appName entry
424-
if(Syphon.Servers[appName].Count == 0){
425-
Syphon.Servers.Remove(appName);
427+
if(Syphon.Servers[realAppName].Count == 0){
428+
Syphon.Servers.Remove(realAppName);
426429
}
427430
}
428431
}
429432
//if the name is valid and the server's app dictionary contains the name string, remove the server from the list.
430-
else if(Syphon.Servers[appName].ContainsKey(name)){
431-
Syphon.Servers[appName].Remove(name);
433+
else if(Syphon.Servers[realAppName].ContainsKey(realName)){
434+
Syphon.Servers[realAppName].Remove(realName);
432435

433436
//if there are no more entries in the dictionary list for that app, remove the associated appName entry
434-
if(Syphon.Servers[appName].Count == 0){
435-
Syphon.Servers.Remove(appName);
437+
if(Syphon.Servers[realAppName].Count == 0){
438+
Syphon.Servers.Remove(realAppName);
436439
}
437440
}
438441

@@ -441,9 +444,9 @@ public static void OnRetireServer(string appName, string name, string uuid){
441444
}
442445

443446
if(RetireServer != null)
444-
RetireServer(appName, name);
447+
RetireServer(realAppName, realName);
448+
445449

446-
447450
}
448451

449452
public void UpdateServerNames(){
@@ -478,7 +481,12 @@ public static SyphonClientObject GetSyphonClient(string appName, string name){
478481
return Syphon.SyphonClients.Find( delegate (SyphonClientObject obj) {
479482
return obj.MatchesDescription(appName, name);
480483
});
481-
484+
}
485+
486+
public static SyphonClientObject GetSyphonClient(string uuid){
487+
return Syphon.SyphonClients.Find( delegate (SyphonClientObject obj) {
488+
return obj.MatchesDescription(uuid);
489+
});
482490
}
483491

484492
public static SyphonServerObject GetSyphonServer(string appName, string name){
@@ -499,22 +507,17 @@ public static SyphonServerObject GetSyphonServer(string appName, string name){
499507
public static SyphonClientObject AddClientToSyphonClientsList(string appName, string name, SyphonServerObject server){
500508
SyphonClientObject result = GetSyphonClient(appName, name);
501509
// Debug.Log(result.BoundAppName + " " + result.BoundName + " was the result");
502-
//if it doesn't exist, create an instance of a SyphonClientObject, and init it.
503-
//when we init it, we tell all our other syphonclienttextures that have registered to
504510
if(result == null){
505511
// UnityEngine.Debug.Log("DIDNT EXIST: " + appName + "/" +name);
506512
//if it was null when trying to add a new client, just add a new one and init.
507513
result = ScriptableObject.CreateInstance<SyphonClientObject>();
508514
result.DefineSyphonClient(server);
509515
Syphon.SyphonClients.Add(result);
510516
}
511-
else{
512-
517+
else{
513518
// UnityEngine.Debug.Log("EXISTED: " + appName + "/" +name + ". doing nothing.");
514-
// result.DestroySyphonClient();
515-
// result.DefineSyphonClient(server);
516-
// result.InitSyphonClient();
517519
}
520+
518521
return result;
519522
}
520523

Syphon Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/SyphonObject/SyphonClientObject.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ public bool MatchesDescription(string appName, string name){
175175
return false;
176176
}
177177

178+
public bool MatchesDescription(string uuid){
179+
if(uuid == attachedServer.SyphonServerDescriptionUUID){
180+
return true;
181+
}
182+
return false;
183+
}
178184

179185
public void UpdateServer(string appName, string name){
180186
if(MatchesDescription(appName, name)){

Syphon Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Read Me.rtf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
\f0\fs36 \cf0 Syphon for Unity Pro 4.0 \
88
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural
99

10-
\fs20 \cf0 1.0 Public Beta 2 a9
10+
\fs20 \cf0 1.0 Public Beta 2 a10
1111
\fs36 \
1212
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural
1313

1414
\fs24 \cf0 \
1515
This is an ongoing work. Please report any and all crashes/freezes, preferably including crash logs\
1616
\
17-
{\field{\*\fldinst{HYPERLINK "http://code.google.com/p/syphon-implementations/issues"}}{\fldrslt http://code.google.com/p/syphon-implementations/issues}}\
18-
\
17+
{\field{\*\fldinst{HYPERLINK "https://github.com/Syphon/Unity3D/issues"}}{\fldrslt https://github.com/Syphon/Unity3D/issues\
18+
}}\
1919
If Unity freezes, see {\field{\*\fldinst{HYPERLINK "http://www.thexlab.com/faqs/activitymonitor.html"}}{\fldrslt http://www.thexlab.com/faqs/activitymonitor.html}} the section entitled 'sampling a process' and send us that log.\
2020
\
2121
If Unity crashes, see {\field{\*\fldinst{HYPERLINK "http://echoone.com/bugreports/console.html"}}{\fldrslt http://echoone.com/bugreports/console.html}} and send the relevant log.\
@@ -52,5 +52,6 @@ Syphon for Unity3D - Brian Chasalow (Unity 3D integration and scripting), Tom Bu
5252

5353
\b \cf0 Release Notes:
5454
\b0 \
55+
a10: fixed a bug with OnRetireServer crashing with OpenFrameworks servers exiting.\
5556
a9: fixed some Unity 4.2 texture creation and 64 bit issues. uses custom Syphon framework with multithreading changes.\
5657
}

Syphon Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Resources/syphonSupportedShader 1.mat.meta

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Syphon Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/SyphonUnityExample-csharp.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Global
2323
GlobalSection(SolutionProperties) = preSolution
2424
HideSolutionNode = FALSE
2525
EndGlobalSection
26-
GlobalSection(MonoDevelopProperties) = preSolution
26+
GlobalSection(MonoDevelopProperties) = preSolution
2727
StartupItem = Assembly-CSharp.csproj
2828
Policies = $0
2929
$0.TextStylePolicy = $1

Syphon Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/SyphonUnityExample.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Global
2929
GlobalSection(SolutionProperties) = preSolution
3030
HideSolutionNode = FALSE
3131
EndGlobalSection
32-
GlobalSection(MonoDevelopProperties) = preSolution
32+
GlobalSection(MonoDevelopProperties) = preSolution
3333
StartupItem = Assembly-CSharp.csproj
3434
Policies = $0
3535
$0.TextStylePolicy = $1

Syphon Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/SyphonUnityExample.userprefs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<Properties>
22
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
3-
<MonoDevelop.Ide.Workbench />
3+
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/Plugins/Syphon.cs">
4+
<Files>
5+
<File FileName="Assets/Plugins/Syphon.cs" Line="403" Column="18" />
6+
<File FileName="Assets/Plugins/SyphonObject/SyphonClientObject.cs" Line="93" Column="24" />
7+
<File FileName="Assets/Plugins/SyphonTexture/SyphonClientTexture.cs" Line="1" Column="1" />
8+
<File FileName="Assets/Plugins/SyphonObject/SyphonServerObject.cs" Line="1" Column="1" />
9+
</Files>
10+
</MonoDevelop.Ide.Workbench>
411
<MonoDevelop.Ide.DebuggingService.Breakpoints>
512
<BreakpointStore />
613
</MonoDevelop.Ide.DebuggingService.Breakpoints>

Syphon Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/ServerWatcherUtility.mm

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,27 +100,26 @@ @implementation ServerWatcherUtility
100100

101101
- (void)handleServerRetire:(NSNotification *)notification
102102
{
103-
// dispatch_async(dispatch_get_main_queue(), ^(){
104103

105104
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
106105

107-
const char* param2 = [[[notification object] objectForKey:SyphonServerDescriptionNameKey] UTF8String];
108106
const char* param1 = [[[notification object] objectForKey:SyphonServerDescriptionAppNameKey] UTF8String];
109-
const char* param3 = [[[notification object] objectForKey:SyphonServerDescriptionUUIDKey] UTF8String];
110-
111-
// MonoString* myString = mono_string_new(domain, param1);
112-
// MonoString* myString2 = mono_string_new(domain, param2);
113-
// MonoString* myString3 = mono_string_new(domain, param3);
114-
// void *args[] = { myString, myString2, myString3 };
115-
// mono_runtime_invoke(retireServer, NULL, args, NULL);
116-
// param1 = NULL;
117-
// param2 = NULL;
118-
// param3 = NULL;
107+
const char* param2 = [[[notification object] objectForKey:SyphonServerDescriptionNameKey] UTF8String];
108+
const char* param3 = [[[[notification object] objectForKey:SyphonServerDescriptionUUIDKey] copy]UTF8String];
109+
110+
// NSLog(@"retiring: %s, %s, %s", param1, param2, param3);
111+
if([[notification object] objectForKey:SyphonServerDescriptionNameKey] == nil){
112+
//just ensure we don't send invalid strings...
113+
param2 = param3;
114+
}
115+
if([[notification object] objectForKey:SyphonServerDescriptionAppNameKey] == nil){
116+
//just ensure we don't send invalid strings...
117+
param1 = param3;
118+
}
119119

120120
OnRetireServerDelegate(param1, param2, param3);
121121

122122
[pool drain];
123-
// });
124123

125124
}
126125

@@ -134,11 +133,11 @@ - (void)handleServerUpdate:(NSNotification *)notification
134133
const char* param3 = [[[notification object] objectForKey:SyphonServerDescriptionUUIDKey] UTF8String];
135134

136135

137-
NSUInteger serverPtr = 0;
136+
void* serverPtr = 0;
138137
NSArray* serversArray = [[SyphonServerDirectory sharedDirectory] servers];
139138
for(NSDictionary* dict in serversArray){
140139
if([[notification object] objectForKey:SyphonServerDescriptionUUIDKey] == [dict objectForKey:SyphonServerDescriptionUUIDKey]){
141-
serverPtr = (NSUInteger)dict;
140+
serverPtr = dict;
142141
}
143142
}
144143

@@ -167,15 +166,17 @@ - (void)handleServerAnnounce:(NSNotification *)notification
167166
const char* param3 = [[[notification object] objectForKey:SyphonServerDescriptionUUIDKey] UTF8String];
168167
//NSLog(@"announceing server! %s %s %s", param2, param1, param3);
169168

170-
NSUInteger serverPtr = 0;
169+
void* serverPtr = 0;
171170
NSArray* serversArray = [[SyphonServerDirectory sharedDirectory] servers];
172171
for(NSDictionary* dict in serversArray){
173172
if([[notification object] objectForKey:SyphonServerDescriptionUUIDKey] == [dict objectForKey:SyphonServerDescriptionUUIDKey]){
174-
serverPtr = (NSUInteger)dict;
173+
serverPtr = dict;
175174
}
176175
}
177-
178-
// MonoString* myString = mono_string_new(domain, param1);
176+
177+
178+
// NSLog(@"announcing uuid %s, ptr is %li", param3, (unsigned long)serverPtr);
179+
// MonoString* myString = mono_string_new(domain, param1);
179180
// MonoString* myString2 = mono_string_new(domain, param2);
180181
// MonoString* myString3 = mono_string_new(domain, param3);
181182
// void *args[] = { myString, myString2, myString3, &serverPtr };

Syphon Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonUnity.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ void UnitySetGraphicsDevice (void* device, int deviceType, int eventType){
9494

9595

9696
void* CreateClientTexture(NSDictionary* serverPtr){
97+
// NSLog(@"CREATED CLIENT TEXTURE AT %li, and added it to the list. count is now xx", ( long)serverPtr );
9798
SyphonCacheData* clientPtr = new SyphonCacheData(serverPtr);
9899
//add it to a list
99100
syphonClients.push_back(clientPtr);
100-
// NSLog(@"CREATED CLIENT TEXTURE AT %li, and added it to the list. count is now %i", (unsigned long)clientPtr, (int)syphonClients.size());
101+
101102
return clientPtr;
102103
}
103104

@@ -126,7 +127,7 @@ void KillClientTexture(SyphonCacheData* killMe){
126127
// NSLog(@"removed one, count is now %i", (int)syphonClients.size());
127128
}
128129
//delete the cache data associated with it
129-
NSLog(@"DESTROYED A CLIENT TEXTURE AT %li, count is now %i", (unsigned long)killMe, (int)syphonClients.size());
130+
// NSLog(@"DESTROYED A CLIENT TEXTURE AT %li, count is now %i", (unsigned long)killMe, (int)syphonClients.size());
130131

131132
delete killMe;
132133
killMe->destroyMe = NO;
@@ -140,7 +141,7 @@ void KillClientTexture(SyphonCacheData* killMe){
140141
SyphonCacheData* ptr = new SyphonCacheData();
141142
ptr->serverName = [[NSString alloc] initWithUTF8String:serverName];
142143

143-
NSLog(@"CREATIN SERVER TEXTURE AT: %li", (unsigned long)ptr);
144+
// NSLog(@"CREATIN SERVER TEXTURE AT: %li", (unsigned long)ptr);
144145
//add it to a list
145146
syphonServers.push_back(ptr);
146147
return ptr;
@@ -172,7 +173,7 @@ void UpdateTextureSizes(){
172173
list_iter != syphonClients.end(); list_iter++){
173174

174175
if((*list_iter)->updateTextureSizeFlag){
175-
NSLog(@"SOMETHING CHANGED");
176+
// NSLog(@"SOMETHING CHANGED");
176177
handleTextureSizeChanged(*list_iter);
177178
(*list_iter)->updateTextureSizeFlag = false;
178179
}

0 commit comments

Comments
 (0)