Getting Strange video warning from my IKPictureTaker App - cocoa

I have a simple little osx app that just starts up an IKPictureTaker and then saves the resulting picture as a .tiff file. It all seems to work fine but everytime I take the picture I get this error repeatedly:
2009-11-10 12:25:38.890 Take A Picture[855:9c23] *** QTCaptureSession warning: Session received the following error while decompressing video: Error Domain=NSOSStatusErrorDomain Code=-67441 "Operation could not be completed. (OSStatus error -67441.)". Make sure that the formats of all video outputs are properly configured.
The code is pretty simple:
- (void)awakeFromNib
{
IKPictureTaker *sharedPictureTaker = [IKPictureTaker pictureTaker];
[sharedPictureTaker setValue:[NSNumber numberWithBool:YES] forKey:IKPictureTakerShowEffectsKey];
[sharedPictureTaker beginPictureTakerWithDelegate:self didEndSelector:#selector(pictureTakerDidEnd:returnCode:contextInfo:) contextInfo:nil];
}
- (void) pictureTakerDidEnd:(IKPictureTaker *) picker
returnCode:(NSInteger) code
contextInfo:(void*) contextInfo
{
NSImage *image = [picker outputImage];
NSString *folder = #"/Users/Mike/Library/Application Support/file.tiff";
folder = [folder stringByExpandingTildeInPath];
[[image TIFFRepresentation] writeToFile:#"~/Library/Application Support/file2.tiff" atomically:NO];
}

Sounds like there might be some configuration issue with your machine. Are you able to test it on another? Is there anything else going on in your app? Do you get the same thing if you select different kinds of image files or only when capturing?
Your strings are a bit mixed up in the writing method, but that aside the code works fine for me in an otherwise virgin app.

Related

Close and launch with different command line parameters/arguments

I am running a .app and I need to "restart" it so to speak. Basically I need to tell it to close, then after closing, it should launch the path i tell (which is to itself) with some command line arguments. Is this possible with cocoa? Im getting stuck at the part where my app is closing then closed, then I cant get it back.
My code is in js-ctypes, but here is the objc pseudo code:
default_center = [NSDistributedNotificationCenter defaultCenter];
shared_workspace = [NSWorkspace sharedWorkspace];
notification_center = [[NSWorkspace sharedWorkspace] notificationCenter];
[notification_center addObserver:selector:name:object: ***, ***, NSWorkspaceDidLaunchApplicationNotification, NIL]
And in my observr when it responds with completion of quit it has code to launch. But as my app is closed it never gets to the observer responder.
Here
Thanks
You didn't mention any reason that you cannot launch a second instance of your app from the first instance, rather than the chicken & egg approach of trying to restart after you've quit... I have this code in my AppWillTerminate function where I have a situation like yours:
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:appUrl options:NSWorkspaceLaunchNewInstance configuration:nil error:&error];
( To get the AppWillTerminate to be called in the first place, I had to disableSuddenTermination before calling [app quit] )
There's also some flag in the app's plist file like "allow multiple instance" or something.
Also, KNOW THIS: if your app is sandboxed, this will not work UNLESS it is code signed with an AppleStore given id, or with a Developer ID Application id. Also, it won't work on X.7 no matter what, when sandboxed.
METHOD TWO,
is to create a "Helper App". Your KillerApp goes through the Quit process, and right before it dies, it launches "HelperApp", which is a tiny command line tool which waits for KillerApp to really die, then relaunches it.
In XCode, the code for the HelperApp, a "Command line tool", is like this:
#import <Cocoa/Cocoa.h>
int main( int argc , char *argv[] ) {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
pid_t parentPID = atoi(argv[2]);
ProcessSerialNumber psn;
while ( GetProcessForPID(parentPID, &psn) != procNotFound )
sleep(1);
NSString* appPath = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
BOOL success = [[NSWorkspace sharedWorkspace] openFile:[appPath stringByExpandingTildeInPath]];
if ( ! success )
NSLog(#"Error: could not relaunch application at %#", appPath);
[pool drain];
return (success) ? 0 : 1;
}
As you can see, you call the HelperApp with a couple parameters from your KillerApp... And in the case where you don't need to be sandboxed, that's about it.
If you DO need sandboxing, then it gets more complicated, of course. You need to create a "privileged helper tool", and thank goodness there is sample code for it.
"SMJobBless" is the Apple sample code project which outlines how to do this, but it's kind of weird-- it doesn't actually DO anything. Thankfully, somebody took that project and created "SMJobBlessXPC" from it, which really does finish the job, ( and when you get it working, your KillerApp can actually communicate with your HelperApp ). The downside is that you need to exactly maintain the plist files of the two apps in terms of code signing.

How to debug EXC_BAD_ACCESS error using Profile in Xcode

After I received a exc_bad_access error I read this tutorial: http://www.ioslearner.com/debugging-exc_bad_access-error-xcode-instruments/ and followed the steps:
Run Profile
Choose Zombies
Everything looks the same on my computer except that I do not get the Zomie Signal.
In order to make sure I did not forget a step I tried it with the example code provided in the Tutorial. There I see the Zombi Signal
So how do I get the zombie signal in my project using Xcode -> Profile?
This is the sample code I use:
I am well aware that the two releases cause the error. Again the question is how get the "Zombie Message" in the Profile using Xcode:
NSArray *currentRestaurant = [restaurants objectAtIndex:i];
RestauInfo *restauInfo = [NSEntityDescription
insertNewObjectForEntityForName:#"RestauInfo"
inManagedObjectContext:context];
[restauInfo release];
restauInfo.Name = [currentRestaurant objectAtIndex:0];
restauInfo.Cuisine = [currentRestaurant objectAtIndex:1];
NSError *error;
if (![context save:&error]) {
NSLog(#"Whoops, couldn't save: %#", [error localizedDescription]);
}
[restauInfo release];// - this release would cause an EXC_BAD_ACCESS
Another question is: Why do I get bad_access at the second release - and not when accessing restauInfo after the first release?
I found another way detecting faults in memory management:
In Xcode you can choose "Run", "Test", "Profile" and "Analyze"
(By pressing and holding the run Button in the upper left corner)
Running the analyze reveals memory management errors - such as
over releasing
leaks
You are overreleasing restauInfo, its an autoreleased object and you call -release manually twice, causing your crashes.
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSEntityDescription_Class/NSEntityDescription.html

Xode 4.5 Hello World example doesn't work

I am pretty much an XCode beginner, and I therefore tried the, "Hello World" example given in the XCode documentation: Quick Start Guide: Tutorial: Using Xcode to Write “Hello, World!” for OS X.
I am using XCode 4.5.1 from whose documentation I took this example using OS 10.8.2. I followed the instructions; the example didn't work. It produced the window but not the "hello world" printing. The relevant code is:
- (void)drawRect:(NSRect)dirtyRect
{
// Drawing code here.
NSString *hello = #"Hello, World!";
NSPoint point =NSMakePoint(15, 75);
NSMutableDictionary *font_attributes = [[NSMutableDictionary alloc] init];
NSFont *font = [NSFont fontWithName:#"Futura-MediumItalic" size:42];
[font_attributes setObject:font forKey:NSFontAttributeName];
[hello drawAtPoint:point withAttributes:font_attributes];
[font_attributes release];
}
There are two notable things. The last line of this code gives an error:
release is unavailable: not available in automatic reference counting mode
So I commented this line out and ran the program. The window appeared, but no "Hello World". A long message appeared in the All Output, part of which read:
"/Users/me/Library/ScriptingAdditions/YouHelper.osax/Contents/MacOS/YouHelper: no matching architecture in universal wrapper
Hello: OpenScripting.framework - scripting addition "/Users/me/Library/ScriptingAdditions/YouHelper.osax" declares no loadable handlers."
Am I doing something dumb, or am I using the wrong example?
You have to remove [font_attributes release]; at the end of your code.
release, retain, alloc and dealloc are not available in ARC(Automatic Reference Counting). This is what the error says.
And for the second error you should remove anything that is referring to AppleScript and similar scripting addons for the app.
Without seeing you project it's difficult to find out what's wrong with it. My guess is: You forgot to specify the custom view's class in IB (Step 12 in "Design the User Interface").

Weird Xcode behavior

Lately something weird has been happening to my projects in xcode: I've been trying to learn a lot of new stuff, and doing so by testing things out in different simple cocoa apps (written by me, from scratch). sometimes I will get a code that doesn't have any error messages, but when i run it, i will stop at some break-point. I then conclude that I have probably done something wrong, and restores the code back to the form it was before the error, but from then on out it is impossible to get the code to run. even if i restore the code to a state that i am 100 % sure that has worked before, it just stops at the same break-point. in order to fix this problem, i have to copy my code from the class this has happened to, delete the class, make a new one with the exact same name, paste the exact same code back in the class, and voila, it works again. what on earth is happening? my newest problem code goes like this:
-(IBAction)openFile:(id)sender {
NSOpenPanel *openPanel = [[NSOpenPanel alloc] init];
NSURL *fileURL;
[openPanel setCanChooseFiles:YES];
[openPanel setCanChooseDirectories:NO];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setAllowedFileTypes:[NSArray arrayWithObject:#"txt"]];
if ( [openPanel runModal] == NSOKButton ) {
fileURL = [openPanel URL];
}
[openPanel release];
}
I know this code has worked before. It is currently my only method, and it activates when i press open in the menu. If I delete everything inside the method, so that pressing open should do nothing it stops at a break-point inside the method anyway. I have had exactly the same kind of problem before with openGL codes, and with a method that used c syntax to do file reading. Does anybody know what kind of horrible mistake I'm making over and over again?
A Breakpoint is something you yourself set explicitly to tell Xcode to pause the program at this exact line. Superficially it might look like the program crashed, but in reality it's just waiting for you to tell it to go on.
This page looks like it has a nice explanation of the breakpoint interface in Xcode. (This is from a framework called Cocos2D, but ignore that. You should stick to ordinary Cocoa until you know what you're doing.)

Three20: unreconized selector when adding TTActivityLabel like in the sample

I add an TTActivityLabel, pretty much like in the sample:
TTActivityLabel *label = [[[TTActivityLabel alloc] initWithStyle:TTActivityLabelStyleBlackBezel] autorelease];
label.text = #"Hello World.";
[label sizeToFit];
label.frame = CGRectMake(0, 0, myView.width, label.height);
[myView addSubview:label];
The code crashes on -sizeToFit with:
2010-02-09 14:42:21.065 MIB[17092:207] *** -[UICFFont ttLineHeight]: unrecognized selector sent to instance 0xf15e30
I already figured out, that ttLineHeight is an addition to UIFont, that seems to not be correctly identified by Xcode. How can this happen? Maybe i do something wrong when importing Three20?
When i run the debugger, it interrupts inside the code of TTActivityLabel where the error happens. I am not sure if this is the correct behaviour. Maybe it should not break inside TT code, since this is a static library?
Any help is appreciated =)
Alright, i found the solution.
There was indeed an error made by me when i added the three20 libraries to my project.
"Other linker flags" in build settings was not set to "-all_load -ObjC". I fixed that and now it works fine.

Resources