Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
I have this piece of code:

Code:
- (void)processAndSaveImageWithID:(NSString *)imageID
{
	NSString *imagesDirectory = ...
	NSString *mediumImagesDir = ...
	
	NSAutoreleasePool *internalPool = [[NSAutoreleasePool alloc]init];
	
	NSLog(@"processing Image with ID");
	
	UIImage *img = [[UIImage alloc]initWithContentsOfFile:[imagesDirectory stringByAppendingPathComponent:imageID]];
	UIImage *mediumImage = [img scaledImage:428];
	[img release];

	[sharedGlobals saveImageAsJPGFile:mediumImage withQuality:0.6f withFileID:imageID toDirectory:mediumImagesDir];

	UIImage *shrinkedImage = [mediumImage scaledImage:100];

[B]	[sharedGlobals saveImageAsJPGFile:shrinkedImage withQuality:0.6f withFileID:imageID toDirectory:sharedGlobals.applicationThumbnailsDirectory]; //THIS CAUSES THE ERROR!!![/B]
	
	
	self.imageView.image = shrinkedImage;
	[self applyChangesGloballyWithFileID:imageID];
	[self.imageNameTextField setEnabled:YES];
	
	imageNameTextField.userInteractionEnabled = YES;
	imageNameTextField.hidden = NO;
	takePictureButton.userInteractionEnabled = NO;
	
	[internalPool drain];
	
}

And here is my code for the "saveImageAsJPGFile" function:
Code:
- (void)saveImageAsJPGFile:(UIImage *)image withQuality:(CGFloat)quality withFileID:(NSString *)fileID toDirectory:(NSString *)dir
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
	NSLog(@"saving image to %@", dir);
	[UIImageJPEGRepresentation(image, quality) writeToFile:[dir stringByAppendingPathComponent:fileID] atomically:NO];
	[pool drain];
}


Although static analysis does not give me any errors, the folowing appears on the console log:
Code:
009-09-19 14:22:45.325 iMe[6058:5607] saving image to /Users/soulstorm/Library/Application Support/iPhone Simulator/User/Applications/2B74F5DD-A743-484D-92EB-5C9449600C44/Documents/thumbnails
iMe(6058,0xb0103000) malloc: *** error for object 0x188e000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

However, I can't say why this is happening. Putting nslogs after each variable created and each process done shows that before the [internalPool drain] every variable has a retain count of 1.

Can anyone help me on this?
 
However, I can't say why this is happening. Putting nslogs after each variable created and each process done shows that before the [internalPool drain] every variable has a retain count of 1.

Can anyone help me on this?

maybe it's referring to *pool from saveImageAsJPGFile:withQuality:withFileID:toDirectory:?
 
It's possible this is an Apple bug. I've seen some mention of this on the Apple forum. What version of the OS are you testing this with? Can you try it with different versions? I think maybe the apple bug appeared in OS 3.1.
 
It's possible this is an Apple bug. I've seen some mention of this on the Apple forum. What version of the OS are you testing this with? Can you try it with different versions? I think maybe the apple bug appeared in OS 3.1.

Although I'm building against 3.0, the bug appeared after updating my iPhone SDK to 3.1.

I have also some other things to point out, like the UIImagePickerController complaining about a plist file, when it first starts up (although this doesn't affect performance and usability at all).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.