Microsoft Windows Phone 8.1 support ends (13 Jul 2017)

Microsoft has ended support for Windows Phone 8.1

Questions about iOS development and PDF

EXC_BAD_ACCESS in [PDFPage addContent]

More
IP: 192.168.0.71 12 years 1 month ago #6982 by sparklellama
The following code is intended to inset an image into the PDF at the point the user has tapped. The code works well the first time. However, every time I try and run the code again to add a second image, I get an EXC_BAD_ACCESS from within the Radaee library (when addContent is called). Is there any way you can explain what is going wrong, and potentially how to work around this?

Code:
- (void)OnSingleTapped:(float)x :(float)y :(NSString *)text { x = x - 200; y = y + 100; NSNumber* xx = [NSNumber numberWithInt:x]; NSNumber* yy = [NSNumber numberWithInt:y]; struct PDFV_POS pos; [m_view vGetPos:&pos]; int pageNo = pos.pageno; PDFPage* p = [m_doc page:pageNo]; PDFVPage* vp = [m_view vGetPage:pageNo]; UIImage* temp = [UIImage imageNamed:@"Signature"]; NSString* path = NSTemporaryDirectory(); path = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", [[NSUUID new] UUIDString]]]; BOOL written = [UIImageJPEGRepresentation(temp, 0) writeToFile:path atomically:YES]; NSLog(@"Temp File Written? %@", [NSNumber numberWithBool:written]); PDFDocGState* gs = [m_doc newGState]; [gs setFillAlpha:255]; [gs setStrokeAlpha:255]; PDF_PAGE_GSTATE ppgs = [p addResGState:gs]; PDFDocImage* i = [m_doc newImageJPEG:path]; PDF_PAGE_IMAGE ii = [p addResImage:i]; PDFPageContent* newContent = [[PDFPageContent alloc] init]; [newContent gsSet:ppgs]; NSNumber* scrollx = [NSNumber numberWithInt:[m_view vGetX]]; NSNumber* scrolly = [NSNumber numberWithInt:[m_view vGetY]]; float pdfx = [vp ToPDFX:[xx floatValue] : [scrollx floatValue]]; float pdfy = [vp ToPDFX:[yy floatValue] : [scrolly floatValue]]; int pageHeight = [vp GetHeight] / [vp GetScale]; pdfy = pageHeight - pdfy; PDFMatrix* m = [[PDFMatrix alloc] init:110 :65 :pdfx :pdfy]; [newContent gsCatMatrix:m]; [newContent drawImage:ii]; [newContent gsRestore]; BOOL added = [p addContent:newContent :YES]; NSLog(@"Content Added? %@", [NSNumber numberWithBool:added]); [m_view vRenderPage:vp]; [m_doc save]; NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL deleted = [fileManager removeItemAtPath:path error:NULL];
More
IP: 192.168.0.71 12 years 1 month ago #6984 by radaee
Code:
- (void)OnSingleTapped:(float)x :(float)y :(NSString *)text { x = x - 200; y = y + 100; NSNumber* xx = [NSNumber numberWithInt:x]; NSNumber* yy = [NSNumber numberWithInt:y]; struct PDFV_POS pos; [m_view vGetPos:&pos];//this position from (0,0) of screen. int pageNo = pos.pageno; PDFVPage* vp = [m_view vGetPage:pageNo]; if( !vp ) return; PDFPage* p = [vp Page]; if( !p ) return; UIImage* temp = [UIImage imageNamed:@"Signature"]; NSString* path = NSTemporaryDirectory(); path = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", [[NSUUID new] UUIDString]]]; BOOL written = [UIImageJPEGRepresentation(temp, 0) writeToFile:path atomically:YES]; NSLog(@"Temp File Written? %@", [NSNumber numberWithBool:written]); PDFDocImage* i = [m_doc newImageJPEG:path]; PDF_PAGE_IMAGE ii = [p addResImage:i]; PDFPageContent* newContent = [[PDFPageContent alloc] init]; [newContent gsSet:ppgs]; NSNumber* scrollx = [NSNumber numberWithInt:[m_view vGetX]]; NSNumber* scrolly = [NSNumber numberWithInt:[m_view vGetY]]; float pdfx = [vp ToPDFX:[xx * m_scale floatValue] : [scrollx floatValue]]; float pdfy = [vp ToPDFX:[yy floatValue] : [scrolly floatValue]]; PDFMatrix* m = [[PDFMatrix alloc] init:110 :65 :pdfx :pdfy]; [newContent gsCatMatrix:m]; [newContent drawImage:ii]; [newContent gsRestore]; BOOL added = [p addContent:newContent :YES]; NSLog(@"Content Added? %@", [NSNumber numberWithBool:added]); [m_view vRenderPage:vp]; [m_doc save]; NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL deleted = [fileManager removeItemAtPath:path error:NULL];
More
IP: 192.168.0.71 12 years 1 month ago #6986 by sparklellama
Thank you very much for your help. The code modified as you suggested is simpler and makes more sense, and works well the first time.

However, the second time I tap to add the image to the PDF the second time, the application still crashes with EXC_BAD_ACCESS at the line BOOL added = [p addContent:newContent :YES];
More
IP: 192.168.0.71 12 years 1 month ago #6987 by radaee
are p is null?
More
IP: 192.168.0.71 12 years 1 month ago #6988 by sparklellama
All variables seem to be set up correctly. Here is a screen grab of the exception.

More
IP: 192.168.0.71 12 years 1 month ago #6989 by radaee
[m_view vGetPos:&pos:x:y];
Time to create page: 0.425 seconds
Powered by Kunena Forum