[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-dev] CocoaDialog again
Just trying to get back to solve this again.
sorry, but i'm really having a hard time dealing with the lang code.
here's my latest attempt.
it crashes when trying to run CocoaDialog-ok
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_INVALID_ADDRESS (0x0001) at 0x7ff90075
Thread 0 Crashed:
#0 0x00059944 in sendMessage(VMGlobals*, PyrSymbol*, long)
(PyrMessage.cpp:202)
#1 0x00041490 in initInterpreter(VMGlobals*, PyrSymbol*, int)
(PyrInterpreter3.cpp:361)
#2 0x00040c7c in runInterpreter (PyrInterpreter3.cpp:99)
#3 0x00096360 in -[SCDialog ok] (SCDialog.mm:51)
#4 0x00096650 in -[SCDialog getPaths] (SCDialog.mm:95)
CocoaDialog {
classvar returnSlot,ok,cancel;
*getPaths { arg okFunc,cancelFunc,
maxSize=20;
if(returnSlot.isNil,{
returnSlot = Array.new(maxSize);
ok = okFunc;
cancel = cancelFunc;
this.prGetPathsDialog(returnSlot);
},{
"A CocoaDialog is already in progress.".warn;
});
}
*prGetPathsDialog { arg returnSlot;
_Cocoa_GetPathsDialog
^this.primitiveFailed
}
*ok {
ok.value(returnSlot);
ok = cancel = returnSlot = nil;
}
*cancel {
cancel.value;
ok = cancel = returnSlot = nil;
}
}
int prGetPathsDialog(struct VMGlobals *g, int numArgsPushed);
int prGetPathsDialog(struct VMGlobals *g, int numArgsPushed)
{
if (!g->canCallOS) return errCantCallOS;
PyrSlot *receiver = g->sp - 1; // CocoaDialog class
PyrSlot *array = g->sp; // an array
SCDialog *dialog = [SCDialog receiver: receiver returnSlot: array];
NSInvocation *invocation = [NSInvocation
invocationWithMethodSignature:
[dialog
methodSignatureForSelector: @selector(getPaths)]];
[invocation setTarget:dialog];
[invocation setSelector: @selector(getPaths)];
[invocation retainArguments];
[[SCVirtualMachine sharedInstance] defer: invocation];
return errNone;
}
//
// SCDialogs.m
// SC3lang
//
// Created by cruxxial on Tue Dec 17 2002.
// Copyright (c) 2002 crucial-systems. All rights reserved.
//
#import "SCDialog.h"
#include "PyrPrimitive.h"
#include "PyrObject.h"
#include "PyrKernel.h"
#include "VMGlobals.h"
#include "SC_RGen.h"
#include "GC.h"
#include "PyrSched.h"
#include <pthread.h>
@implementation SCDialog
+(id)receiver:(PyrSlot*)receiver returnSlot:(PyrSlot*)returnSlot
{
return [[super alloc] initWithReceiver: receiver returnSlot:
returnSlot];
}
-(id)initWithReceiver:(PyrSlot*)argreceiver
returnSlot:(PyrSlot*)argreturnSlot
{
if(self == [super init]) {
receiver = argreceiver;
returnSlot = argreturnSlot;
}
return self;
}
-(void)ok
{
PyrSymbol *method = getsym("ok");
pthread_mutex_lock (&gLangMutex);
VMGlobals *g = gMainVMGlobals;
g->canCallOS = true;
++g->sp; SetObject(g->sp, receiver);
runInterpreter(g, method, 1);
g->canCallOS = false;
pthread_mutex_unlock (&gLangMutex);
}
-(void)cancel
{
PyrSymbol *method = getsym("cancel");
pthread_mutex_lock (&gLangMutex);
VMGlobals *g = gMainVMGlobals;
g->canCallOS = true;
++g->sp; SetObject(g->sp, receiver);
runInterpreter(g, method, 1);
g->canCallOS = false;
pthread_mutex_unlock (&gLangMutex);
}
-(void)getPaths
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDocumentController *docctl = [NSDocumentController
sharedDocumentController];
NSArray *urls = [docctl URLsFromRunningOpenPanel];
if(urls) {
int i;
int count = [urls count];
VMGlobals *g = gMainVMGlobals;
pthread_mutex_lock (&gLangMutex);
// TODO: limit at max size of array
for (i = 0; i < count; i++)
{
PyrString* pyrPathString = newPyrString(g->gc,[[[urls
objectAtIndex: i ] path] cString],0,true);
PyrSlot slot;
SetObject(&slot, pyrPathString);
returnSlot->uo->slots[i].ucopy = slot.ucopy;
g->gc->GCWrite(returnSlot->uo,pyrPathString);
// have to set size field each time in order that gc can
find the created objects
returnSlot->uo->size = i+1;
}
pthread_mutex_unlock (&gLangMutex);
[self ok];
} else {
[self cancel];
}
//[self release];
[pool release];
}
@end
-felix