ParseKit crashing on simple example - parsekit

I recently tried to integrate ParseKit into my iPhone app. I downloaded release-1.5-tag, and integrated it into my project (XCode 4.4, iOS 5.1), and it builds without issue. When I run a simple example to try and parse some Javascript (using the grammar that comes bundled with ParseKit itself):
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:#"javascript" ofType:#"grammar"];
NSString *g = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
PKParser *parser = [[PKParserFactory factory] parserFromGrammar:g assembler:self];
NSString *s = #"var x = 0;";
[parser parse:s];
My app hangs for a bit, then I get an EXC_BAD_ACCESS after what appear to be tens of thousands of calls to PKParser:matchAndAssemble, and PKSequence:allMatchesFor. At the end of all of these calls, it ends up calling PKTerminal:matchOneAssembly, then PKCaseInsensitiveLiteral:qualifies, then the EXC_BAD_ACCESS. Am I doing something wrong?

Developer of ParseKit here.
Use head of trunk from Google code:
http://code.google.com/p/parsekit/

Related

Different behaviour of [NSMutableString writeToFile] in iOS7 and iOS8

Here i have demo code for saving NSMutableString in to File (FileName.dat)
NSError* error = nil;
NSMutableString* dat = [[NSMutableString alloc] initWithCapacity:1];
BOOL result = [dat writeToFile:#"FileName.dat" atomically:YES encoding:NSUTF8StringEncoding error:&error];
but i have two different output while rung it in iOS7 and iOS8beta5
Output XCode5+iOS7
Output XCode5+iOS8
While running it in iOS7 it shows that there in an error in parsing file path,
but in iOS8beta5 it crash by saying that [NSFileManager fileSystemRepresentationWithPath:] have nil or empty path.
Question :
In both SDK iOS8 and iOS7 it take NSError as argument to return error, so i believe that it should return error instead of crashing application
Is apple mansion any changes regarding it, If yes then please give me reference link for the same.
The path you pass to [NSData writeToFile:atomically:] is not complete and should be a full path.
That is normally done by getting the path to the Documents folder and appending that filename.
The problem is your filename, #"FileName.dat", there is no path to the directory to save to. NSFileManager does not do this itself, you'll want to save to the Documents folder normally. Here is the code I usually use:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:myFileName];

Empty Arrays and iOS 7 SDK

Just updated my XCode from 4.6 to 5, and along with it the iOS7 SDK.
I noticed that all operations (e.g. Predicate filters etc) I attempt to perform on empty NSArray or NSMutableArray cause an exception (NSInvalidArgumentException) when running my app in the simulator for either iOS 5.1 or iOS 7 (still struggling to download iOS 6.1)
My arrays are instantiated (so they are not Nil), but they have 0 entries.
So code that used to work fine in XCode 4.6 now crashes, and I have to add an extra IF to check if the array.count == 0 before running that line of code all over my app. (Monumental task)
When I download my app (version I published with XCode 4.6) from the AppStore to an iOS7 device, it works just fine.
Anyone else also experiencing this?
based on this code, I think the value stored in [defaults objectForKey:#"Wards"] is not an array, please double check the value
NSArray *SelectedWards = [[NSArray alloc]initWithArray:[defaults objectForKey:#"Wards"]];
you may use following code to check
if(![[defaults objectForKey:#"Wards"] isKindOfClass:[NSArray class]])
{
NSLog("OOPs! Wards is not an array");
}

stuck with Social frameworks on ios device

I cannot get social frameworks to function correctly on my ios device, however it functions perfectly in the iOS simulator but not on my iPad, can anyone advise on where I may have gone wrong. Thanks in advance.
- (IBAction)sharefb:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"Share this app with your friends"];
[mySLComposerSheet addImage: [UIImage imageNamed:#"icon2.png"]];
[self presentViewController: mySLComposerSheet animated:
YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^
(SLComposeViewControllerResult result) {
NSString *output = [[NSString alloc] init];
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"Post Cancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Posted successfully";
break;
default:
break;
}
}];
I just copy/pasted your code into a blank project and ran it on my iPad successfully, so I'm not exactly sure what the problem is but here's a couple of things you can try.
First, you use both of these lines in your code:
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
It is unnecessary, and unwise to call alloc/init on the composer right before composeViewControllerForServiceType which returns a SLComposeViewController object already. Omitting the first of those two lines could solve the problem.
Second, are you sure that "icon2.png" exists in the project? This shouldn't be causing the problem, but hey crazier things have happened.
Third, also unlikely but it is possible that you have some strange invisibles creating problems with the arguments of presentViewController due to your spacing and line break placement. Try rewriting the line to look like this:
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
Site note, your NSString *output is creating a memory leak, unless it is used for something else that you haven't included in your code. This is all going off of your original post which does not actually specify the problem. If you can be more specific, I can probably be more helpful.

The function `CGCMSUtilsGetICCProfileDataWithRenderingIntent' is obsolete. Why does this solution work?

I am maintaining some code written by someone else and when I build on Xcode 4.5 and run on iOS 6 I get this run time "error"
<Error>: The function `CGCMSUtilsGetICCProfileDataWithRenderingIntent' is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance. Please use `CGColorSpaceCopyICCProfile' instead.
when executing this code:
CGColorSpaceRef alternate = CGColorSpaceCreateDeviceRGB();
NSString *iccProfilePath = [[NSBundle mainBundle] pathForResource:#"sRGB Profile" ofType:#"icc"];
NSData *iccProfileData = [NSData dataWithContentsOfFile:iccProfilePath];
CGDataProviderRef iccProfile = CGDataProviderCreateWithCFData((CFDataRef)iccProfileData);
const CGFloat range[] = {0,1,0,1,0,1}; // min/max of the three components
CGColorSpaceRef colorSpace = CGColorSpaceCreateICCBased(3, range, iccProfile, alternate);
CGContextRef context = CGBitmapContextCreate(NULL, pageWidth, pageHeight, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
CGDataProviderRelease(iccProfile);
CGColorSpaceRelease(colorSpace);
CGColorSpaceRelease(alternate);
When I run on iOS 5.1 there is no error.
I have found that by making the following changes the error does not appear:
Change:
NSString *iccProfilePath = [[NSBundle mainBundle] pathForResource:#"sRGB Profile" ofType:#"icc"];
NSData *iccProfileData = [NSData dataWithContentsOfFile:iccProfilePath];
CGDataProviderRef iccProfile = CGDataProviderCreateWithCFData((CFDataRef)iccProfileData);
to:
char fname[]= "sRGB Profile.icc";
CGDataProviderRef iccProfile = CGDataProviderCreateWithFilename(fname);
I can't find any reference to CGDataProviderCreateWithCFData being deprecated. Can anyone explain the cause of the problem? It seems as though CGDataProviderCreateWithCFData is using CGCMSUtilsGetICCProfileDataWithRenderingIntent and CGDataProviderCreateWithFilename is using CGColorSpaceCopyICCProfile which suggests to me that CGDataProviderCreateWithCFData is deprecated. I'm not comfortable with the solution I have found because I don't understand this. Also, I hope the solution helps someone.
So, you are attaching the sRGB color profile file to the app resources and then explicitly creating a sRGB color profile at runtime on iOS. Is that needed? This document seems to suggest that the device RGB is actually the sRGB colorspace:
Apple WWDC color management talk
It would be nice if we could just call:
colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
But this does not seem to be supported on iOS either.

OpenCV cvHaarDetectObject error

I am making a project in Visual Studio 2010 using Qt4.8.0 and OpenCV2.3.1 library. Everything is fine as long as I don't use
cvHaarDetectObjects()
function. The program was compiled and built without problems, but when I try to run the application the error 0xc000007b appears. I've done similar program in win console and this function work properly. Why am I receiving this error message? I also try to use:
CascadeClassifier *haar;
haar->load("haarcascade_frontalface_alt.xml");
but it doesn't work even in console.
Example code
MainWindow.cpp:
MainWindow::MainWindow()
{
temp = cvCreateImage(cvSize(200, 200), 8, 1);
haarface = (CvHaarClassifierCascade*) cvLoad("haarcascade_frontalface_alt.xml");
storage = cvCreateMemStorage(0);
twarze = cvHaarDetectObjects(temp, haarface, storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING, cvSize(100,100));
}
MainWindow.h:
class MainWindow
{
private:
CvMemStorage *pamiec;
CvHaarClassifierCascade * haarface;
IplImage *temp2;
CvSeq *twarze;
public:
MainWindow(void);
};
Maybe it something wrong with .xml files?
Are you sure the file haarcascade_frontalface_alt.xml exists in the current directory?
If it does not exist, then cvLoad will return NULL. Use full path for the xml file.
Also, what is error 0xc000007b? Could you post the full error description?
I simply changed slashes to backslashes and it works ;) cvLoad("\haarcascades\haarcascade_frontalface_alt.xml");
EDITED: ok, it doesn't crashes. Actually I am working with 2.4.8 edition o opencv. The problem with this code is cvHaarDetectObjects that seems to be not longer supported. It is recomended to use detectMultiScale instead.

Resources