[PD-dev] Pd external-window crash
nosehair911 at bellsouth.net
nosehair911 at bellsouth.net
Mon Jun 25 15:18:44 CEST 2007
> Well it looks like if I get a Gemwin opened first, then I can open an opencv window without a crash...
> > It seems like the window is made using Carbon. Is there any special way Pd handles Carbon
> > windows that would cause this stall?
This is my last hurdle. I have my externals working but in order to use the carbon window I have to
open a gemwin first(not very profecional). I am using an opencv function for windowing that looks
like this:
CV_IMPL int cvNamedWindow( const char* name, int flags )
{
int result = 0;
CV_FUNCNAME( "cvNamedWindow" );
if (!wasInitialized)
cvInitSystem(0, NULL);
// to be able to display a window, we need to be a 'faceful' application
// http://lists.apple.com/archives/carbon-dev/2005/Jun/msg01414.html
static bool switched_to_faceful = false;
if (! switched_to_faceful)
{
ProcessSerialNumber psn = { 0, kCurrentProcess };
OSStatus ret = TransformProcessType (&psn, kProcessTransformToForegroundApplication );
if (ret == noErr)
{
SetFrontProcess( &psn );
switched_to_faceful = true;
}
else
{
fprintf(stderr, "Failed to tranform process type: %d\n", (int) ret);
fflush (stderr);
}
}
__BEGIN__;
WindowRef outWindow = NULL;
OSStatus err = noErr;
Rect contentBounds = {100,100,320,440};
CvWindow* window;
UInt wAttributes = 0;
int len;
const EventTypeSpec genericWindowEventHandler[] = {
{ kEventClassMouse, kEventMouseMoved},
{ kEventClassMouse, kEventMouseUp},
{ kEventClassMouse, kEventMouseDown},
{ kEventClassWindow, kEventWindowClose },
{ kEventClassWindow, kEventWindowBoundsChanged }//FD
};
if( !name )
CV_ERROR( CV_StsNullPtr, "NULL name string" );
if( icvFindWindowByName( name ) != 0 ){
result = 1;
EXIT;
}
len = strlen(name);
CV_CALL( window = (CvWindow*)cvAlloc(sizeof(CvWindow) + len + 1));
memset( window, 0, sizeof(*window));
window->name = (char*)(window + 1);
memcpy( window->name, name, len + 1 );
window->flags = flags;
window->signature = CV_WINDOW_MAGIC_VAL;
window->image = 0;
window->last_key = 0;
window->on_mouse = 0;
window->on_mouse_param = 0;
window->next = hg_windows;
window->prev = 0;
if( hg_windows )
hg_windows->prev = window;
hg_windows = window;
wAttributes = kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute |
kWindowLiveResizeAttribute;
err = CreateNewWindow ( kDocumentWindowClass,wAttributes,&contentBounds,&outWindow);
if (err != noErr)
fprintf(stderr,"Error while creating the window\n");
SetWindowTitleWithCFString(outWindow,CFStringCreateWithCString
(NULL,name,kCFStringEncodingASCII));
if (err != noErr)
fprintf(stdout,"Error SetWindowTitleWithCFString\n");
window->window = outWindow;
err = InstallWindowEventHandler(outWindow, NewEventHandlerUPP(windowEventHandler),
GetEventTypeCount(genericWindowEventHandler), genericWindowEventHandler, outWindow,
NULL);
ShowWindow( outWindow );
result = 1;
__END__;
return result;
}
It seems to me that if this works outside of Pd then there must be something Pd needs in order to
display a carbon window properly. It seems that the "faceful" stuff was written in to prevent this from
happening but it doesnt work in Pd. I have been digging thru the Gem code to find out how it does it
but it is so intertwined with the openGL code that I cant seem to figure out how it displays a carbon
window corectly. Anyway if anyone has any ideas let me know. Until I figure this out I will be opening
up a gemwin along with my external:(.
Alain
More information about the Pd-dev
mailing list