[syphon-implementations] r224 committed - partial fix for beta 4.2 bug - it is now unsafe to marshall mono metho...

5 views
Skip to first unread message

syphon-impl...@googlecode.com

unread,
Jul 13, 2013, 8:26:39 PM7/13/13
to syphon-de...@googlegroups.com
Revision: 224
Author: connec...@gmail.com
Date: Sat Jul 13 17:26:24 2013
Log: partial fix for beta 4.2 bug - it is now unsafe to marshall mono
methods via cached function pointers from GL thread - need to
dispatch_async(dispatch_get_main_queue()). More fix WIP
http://code.google.com/p/syphon-implementations/source/detail?r=224

Modified:
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/SyphonServerAndClient.unity
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/ServerWatcherUtility.mm
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonClientUnity.m
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonUnity.mm
/trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonUnityPlugin.xcodeproj/project.pbxproj

=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/SyphonServerAndClient.unity
Sat Jul 13 14:04:46 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/SyphonServerAndClient.unity
Sat Jul 13 17:26:24 2013
Binary file, no diff available.
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/ServerWatcherUtility.mm
Sat Jul 13 14:04:46 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/ServerWatcherUtility.mm
Sat Jul 13 17:26:24 2013
@@ -100,6 +100,7 @@

- (void)handleServerRetire:(NSNotification *)notification
{
+ dispatch_async(dispatch_get_main_queue(), ^(){

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

@@ -119,6 +120,7 @@
OnRetireServerDelegate(param1, param2, param3);

[pool drain];
+ });

}

@@ -151,15 +153,16 @@
[pool drain];

}
-

- (void)handleServerAnnounce:(NSNotification *)notification
-{
+{
+ dispatch_async(dispatch_get_main_queue(), ^(){
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);
+ NSLog(@"announceing server! %s %s %s", param2, param1, param3);

int serverPtr = 0;
NSArray* serversArray = [[SyphonServerDirectory sharedDirectory]
servers];
@@ -177,9 +180,10 @@
// param1 = NULL;
// param2 = NULL;
// param3 = NULL;
+
OnAnnounceServerDelegate(param1, param2, param3, serverPtr);
-
[pool drain];
+ });
}


@@ -196,8 +200,7 @@
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;
@@ -208,9 +211,10 @@
void handleTextureSizeChanged(SyphonCacheData* ptr){
// void *args[] = { &ptr, &(ptr->textureWidth),
&(ptr->textureHeight) };
// mono_runtime_invoke(textureSizeChanged, NULL, args, NULL);
- //
- NSLog(@"changing texture size: %i/%i",ptr->textureWidth,
ptr->textureHeight);
- OnTextureSizeChangedDelegate((int)ptr, ptr->textureWidth,
ptr->textureHeight);
+ dispatch_async(dispatch_get_main_queue(), ^(){
+ int intptr = (int)ptr;
+ OnTextureSizeChangedDelegate(intptr, ptr->textureWidth,
ptr->textureHeight);
+ });
}

// void monoMethods(){
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonClientUnity.m
Sat Jul 13 14:04:46 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonClientUnity.m
Sat Jul 13 17:26:24 2013
@@ -101,10 +101,9 @@
// CGLUnlockContext(cachedContext);
[pool drain];
return;
- }
+ }

-
- //setup state to how it 'should' be?
+ //setup state to how it 'should' be?
glDisable (GL_CULL_FACE);
glDisable (GL_LIGHTING);
glDisable (GL_BLEND);
@@ -112,12 +111,25 @@
glDepthFunc (GL_LEQUAL);
glEnable (GL_DEPTH_TEST);
glDepthMask (GL_FALSE);
+

//get image!
SyphonImage* image = [ptr->syphonClient
newFrameImageForContext:cachedContext];

-
+ if(!image){
+ NSLog(@"nil image.");
+ glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, previousDrawFBO);
+ glBindFramebufferEXT(GL_READ_FRAMEBUFFER, previousReadFBO);
+ glBindFramebufferEXT(GL_FRAMEBUFFER, previousFBO);
+ glPopClientAttrib();
+ glPopAttrib();
+ // CGLUnlockContext(cachedContext);
+ [pool drain];
+ return;
+ }

+
+
//SAVE MATRIX STATE CODE
glActiveTexture(GL_TEXTURE0);
glMatrixMode(GL_TEXTURE);
@@ -143,10 +155,10 @@
//perform callback to unity here because the w/h changed
ptr->textureWidth = (int)surfaceSize.width;
ptr->textureHeight = (int)surfaceSize.height;
- GLint texcount = 0;
- glGetIntegerv(GL_TEXTURE_STACK_DEPTH, &texcount);
+// GLint texcount = 0;
+// glGetIntegerv(GL_TEXTURE_STACK_DEPTH, &texcount);

- NSLog(@"w/h: %i, %i, count: %i", ptr->textureWidth,
ptr->textureHeight, texcount);
+ NSLog(@"w/h: %i, %i", ptr->textureWidth, ptr->textureHeight
/*, texcount*/ );
// ptr->updateTextureSizeFlag = true;
handleTextureSizeChanged(ptr);

@@ -163,19 +175,21 @@
glMatrixMode(GL_TEXTURE);
glPopMatrix();

- glPopClientAttrib();
- glPopAttrib();
-
glBindFramebufferEXT(GL_FRAMEBUFFER, previousFBO);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER, previousReadFBO);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, previousDrawFBO);

+ glPopClientAttrib();
+ glPopAttrib();
+
if(image)
[image release];
+
return;
}

}
+// NSLog(@"DRAWING THE SHIT");

//okay, draw the shit
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonUnity.mm Sat
Jul 13 14:04:46 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonUnity.mm Sat
Jul 13 17:26:24 2013
@@ -78,7 +78,7 @@
{
// NSLog(@"shutdown graphics device");
//if you are quitting the app, kill all callbacks.
- unregisterCallbacks();
+ unregisterCallbacks();
break;
}
default:
@@ -196,14 +196,29 @@
}
}
}
-
+
+// void resetContext(){
+// NSLog(@"YO WTF! RESETTING");
+// if(cachedContext != CGLGetCurrentContext()){
+// NSLog(@"for real YO WTF! RESETTING");
+// cachedContext = CGLGetCurrentContext();
+// if(syphonFBO){
+// NSLog(@"CACHING CONTEXT + DELETING FBO at RESOURCE ID: %i",
syphonFBO);
+// glDeleteFramebuffersEXT(1, &syphonFBO);
+// glGenFramebuffersEXT(1, &syphonFBO);
+// syphonFBO = nil;
+// }
+// }
+// }
+
void cacheGraphicsContext(){
if(cachedContext != CGLGetCurrentContext()){
cachedContext = CGLGetCurrentContext();
if(syphonFBO){
-// NSLog(@"CACHING CONTEXT + DELETING FBO at RESOURCE ID: %i",
syphonFBO);
+ NSLog(@"CACHING CONTEXT + DELETING FBO at RESOURCE ID: %i",
syphonFBO);
glDeleteFramebuffersEXT(1, &syphonFBO);
glGenFramebuffersEXT(1, &syphonFBO);
+ syphonFBO = nil;
}

for(std::list<SyphonCacheData*>::iterator list_iter
=syphonServers.begin();
@@ -226,10 +241,12 @@
void UnityRenderEvent(SyphonCacheData* ptr)
{
if((int)ptr == 1){
+// NSLog(@"WE GOOD?!");
cacheGraphicsContext();
}
else if(ptr != nil){

+// NSLog(@"this shouldnt even be happening.");
if(ptr->pluginType != PLUGIN_SYPHON)
return;

=======================================
--- /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonUnityPlugin.xcodeproj/project.pbxproj
Sat Jul 13 14:04:46 2013
+++ /trunk/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityPlugin/SyphonUnityPlugin.xcodeproj/project.pbxproj
Sat Jul 13 17:26:24 2013
@@ -249,7 +249,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "\n#rm -r -f
\"/Users/bc/syphon-implementations-proper/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/$PRODUCT_NAME.bundle\"\n#cp
-r -f \"$TARGET_BUILD_DIR/$PRODUCT_NAME.bundle\"
\"/Users/bc/syphon-implementations-proper/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/$PRODUCT_NAME.bundle\"\n";
+ shellScript = "\nrm -r -f
\"/Users/bc/syphon-implementations-proper/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/$PRODUCT_NAME.bundle\"\ncp
-r -f \"$TARGET_BUILD_DIR/$PRODUCT_NAME.bundle\"
\"/Users/bc/syphon-implementations-proper/Syphon
Implementations/Unity3D/Unity3D-3_5/SyphonUnityExample/Assets/Plugins/$PRODUCT_NAME.bundle\"\n";
};
BD48069C1239AFCA00DFB19E /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
Reply all
Reply to author
Forward
0 new messages