views:

21

answers:

1

Hi all,

I am doing drag and drop with NSView.

In the object to be dragged, which is subclass of NSView, I implemented mouseDown: method as follows:

@try {
    NSPoint location; 
    NSSize size ;
    NSPasteboard *pb = [NSPasteboard pasteboardWithName:@"CameraIconContainer"];

    location.x =  ([self bounds].size.width - size.width)/2 - 21.0;
    location.y =  ([self bounds].size.height - size.height)/2 - 7.0;

    NSLog(@"mouseDown: location- (%f, %f)",location.x,location.y);


    NSDictionary *iconViewDict = [[NSDictionary alloc] initWithObjectsAndKeys:[cameraNo stringValue],@"cameraNo",nil];
    NSLog(@"iconViewDict - %@",iconViewDict);

    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:iconViewDict];


    [pb declareTypes:[NSArray arrayWithObject:IconDragDataType] owner:self];
    [pb setData:data forType:IconDragDataType];
    [self dragImage:[NSImage imageNamed:@"camera_icon.png"] at:location offset:NSZeroSize event:e pasteboard:pb source:self slideBack:YES];
}
@catch (NSException * e) {
    NSLog(@"CameraIconView (-mouseDown:), error - %@",e);
}

Most of the time it is working fine but problem is- sometimes it is raising this

exception:Invalid parameter not satisfying: theWriteStream != NULL

in the mouseDown: method, because of it the dragged image continuously appears over screen, which does not disappear even if some other window is selected.

Can anyone suggest me why is it occurring and how can I resolve it?

Thanks,

Miraaj

+2  A: 
exception:Invalid parameter not satisfying: theWriteStream != NULL

That sort of exception comes from an assertion. Something is about to try to write to a stream, and asserted that it has a stream to write to. When the assertion fails, that means that the condition was untrue; in this case, it means that it did not have a stream to write to.

I don't see any stream-related code in the sample you provided, so it's either somewhere else in your app or somewhere within a framework you're using. You should turn on “Stop on Objective-C exceptions” in Xcode, then run your app under the debugger until the exception occurs, then look at the stack trace in the debugger to see exactly what threw the exception.

Peter Hosey
ok.. thanks for your clarification... in my application I have integrated a chat client application in which I am using AsyncSocket class. When chat client is not connected to chat server it yields, following error in debugger : *** Assertion failure in -[AsyncSocket doCFWriteStreamCallback:forStream:]... Invalid parameter not satisfying: theWriteStream != NULL... I think this can be the reason for me getting exception on mouseDown: ?
Miraaj
Yup. `mouseDown:` actually has nothing to do with the problem. Are you sending the `doCFWriteStreamCallback:forStream:` message to the socket yourself? Normally, there is no reason why it should receive such a message except when its CFWriteStream callback is called, which should only ever happen because a CFWriteStream called it.
Peter Hosey
ok... I will check!
Miraaj