OS X Cardboard Crash

I have an application that reads in text by emulating the CMD-C copy and cardboard read commands - unfortunately this is the only way to achieve what I need. Sometimes, since this is in development, from time to time I do something wrong (I don't think it has to do with the copy command) and the application crashes. It has an impact on system-wide cardboard from time to time - any other running application crashes if I try to copy, cut or paste.

Is there a sustainable way to handle this - is there something I should be doing with the NSPasteboard before going out? Any information about what might happen is appreciated.

For completeness, here are just code snippets that refer to cardboard:

Reading from cardboard:

NSString *pBoardText = [[NSPasteboard generalPasteboard]stringForType:NSStringPboardType];

      

Initially cleaning the cardboard (I only run it once, on startup):

[[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject:NSStringPboardType] owner: self];
    [[NSPasteboard generalPasteboard] setString: @"" forType: NSStringPboardType];

      

PS I forgot to mention that this copy command works in a loop, in a different thread - it might be important. Although I tried not to access the cardboard in the main thread without first checking that the loop is stopped.

Update - a few questions about what I am doing ...

  • Can you post a crash report

Working on it right now - unfortunately, accidents are irregular. Let me be clear though - this is an app I'm still developing and sometimes I present a bug. When it crashes, the system-wide cardboard is messed up with SOMETIMES. It doesn't sound like filing cabinet access in my application raises suspicion, however, that it exits when the background loop is in the delicate stage of interacting with PB. Update - Repeat crash reporting - how important is it to you guys? I'm still developing, but I might try to run it multiple times in the non-debugger until something breaks. Unfortunately I have fixed all the outstanding bugs so far and am not getting any crashes. This suggests that the problem isn't with the PBoard code itself - I'm more looking for some precautions, so if this is a disaster,it does not destroy my entire system. All these reboots are getting annoying.

  • Can you elaborate on why you need to emulate Cmd-C in order to do what you need to do?

I am clearing text from a chat window in an external application. The chatbox is built to prevent me from using the Accessibility interface or any other means.

  • Why are you clearing the contents of the clipboard on startup?

I am reviewing cardboard text for new text. This was a quick way to make sure I was not processing text that was copied from another application.

  • Why are you running your code on a thread at all?

The loop constantly posts events to simulate user input, including going to a chat window and copying selected text. If done on the main thread, my app UI will just hang. I am using the user interface to display an overview of what is happening.

  • please show the code that runs in the main thread and will check the loop and refer to cardboard

background thread transfers data to main thread using NSNotifications:

[self performSelectorOnMainThread:@selector(postNote:) withObject:d waitUntilDone:NO];

      

+2


a source to share


1 answer


Some thoughts:



  • It is highly unlikely that any threading issues in one application will crash other applications. Since this appears to be your main problem, it seems more likely that the problem is with the data you are putting in the filing cabinet or the data description. Trying apps for some reason when they try to use data on cardboard.
  • The code you are using is only for 10.5 or earlier. There were several major changes to the way we use cardboard in 10.6. If you are running 10.6, using 10.5 methods might be your problem.
  • One of the major changes in 10.6 is the use of UTIs to accurately describe data on cardboard. If the UTI is invalid or malformed, any application attempting to consume the data on the assumption that it is some other data may crash.
  • If you are using 10.6, be sure to use the Framework Programming Guide as your reference and not the older programming topics for Cocoa.
+1


a source







All Articles