UIScrollView CALayer position contains NaN - uiscrollview

While trying to zoom in my UIScrollView I'm getting the following exception..
2015-06-17 12:42:24.959 GeoSwift[7389:1579038] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(0x183e482d8 0x1953bc0e4 0x183e48218 0x1881c4ac4 0x1881c4a1c 0x188a23c74 0x188a1f0dc 0x1888b8720 0x188d294fc 0x18887c484 0x18887a830 0x1888b6898 0x1888b5f50 0x18888918c 0x188b2a324 0x1888876a0 0x183e00240 0x183dff4e4 0x183dfd594 0x183d292d4 0x18d4076fc 0x1888eefac 0x1000f2f38 0x195a3aa08)
libc++abi.dylib: terminating with uncaught exception of type NSException
That is the problem here? How to solve it?

I've just got quite the same problem and solved this.
Reason (in my case):
The scrollView I used contains an image loaded from the internet, using UIImageView+WebCache (SDWebImage framework). So, before the image is fully loaded, when I try zooming the scroll view, it crashed with the log just like you. I haven't detected the exact reason why, but it's the main reason. Therefore.....
Solution:
I just disable the zoom when the image is not loaded to the scrollView.
self.scrollableImageView.minimumZoomScale = 1;
self.scrollableImageView.maximumZoomScale = 1;
[self.mainImageView sd_setImageWithURL:urlImage placeholderImage:imageHolder options:SDWebImageHighPriority completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
// re-enable zoom
[self updateZoomScale];
}];
Hope this help.

Related

Render a CVPixelBuffer to an NSView (macOS)

I have a CVPixelBuffer that I'm trying to efficiently draw on screen.
The not-efficient way of turning into an NSImage works but is very slow, dropping about 40% of my frames.
Therefore, I've tried rendering it on-screen using CIContext's drawImage:inRect:fromRect. The CIContext was initialized with a NSOpenGLContext who's view was set to my VC's view. When I have a new image, I call the drawImage method which doesn't spit out any errors... but doesn't display anything on screen either (it did log errors when my contexts were not correctly setup).
I've tried to find an example of how this is done on MacOS, but everything seems to be for iOS nowadays.
EDIT:
Here's some of the code I am using. I've left out irrelevant sections
On viewDidLoad I init the GL and CI contexts
NSOpenGLPixelFormatAttribute pixelFormatAttr[] = {
kCGLPFAAllRenderers, 0
};
NSOpenGLPixelFormat *glPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes: pixelFormatAttr];
NSOpenGLContext *glContext = [[NSOpenGLContext alloc] initWithFormat:glPixelFormat shareContext:nil];
glContext.view = self.view;
self.ciContext = [CIContext contextWithCGLContext:glContext.CGLContextObj pixelFormat:glPixelFormat.CGLPixelFormatObj colorSpace:nil options:nil];
Then, when a new frame is ready, I do:
dispatch_async(dispatch_get_main_queue(), ^{
[vc.ciContext drawImage:ciImage inRect:vc.view.bounds fromRect:ciImage.extent];
vc.isRendering = NO;
});
I am not sure I'm calling draw in the right place, but I can't seem to find out where is this supposed to go.
If the CVPixelBuffer has the kCVPixelBufferIOSurfaceCoreAnimationCompatibilityKey attribute, the backing IOSurface (retrieved via CVPixelBufferGetIOSurface) can be passed directly to the contents property of a CALayer.
This is probably the most efficient way to display a CVPixelBuffer.

Drag and drop files into NSOutlineView

I'm trying to implement simple drag and drop operation into NSOutlineView Based on Apple's example - https://developer.apple.com/library/mac/samplecode/SourceView/Introduction/Intro.html
All seems to be ok, but finally when I drop some files from Finder I get error:
[<ChildNode 0x60800005a280> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key description.') was raised during a dragging session
Here is my test project: https://www.dropbox.com/s/1mgcg2dysvs292u/SimpleDrag.zip?dl=0
What I exactly need in my app: allow user to drag and drop multiple files and folder into some tree list and then display them to user. Also save all this this into some file, so it can be loaded again with all user dragged files and folders.
A final result I want to have like this:
The description property of NSObject is read-only, and is generally set by providing a getter in the implementation file:
- (NSString *)description {
return [self urlString]; // Using urlString solely for demo purposes.
}
You can't set it, either via key-value coding or by direct assignment:
self.description = [self urlString]; // Xcode error: 'Assignment to readonly property'
[self setValue:[self urlString] forKey:#"description"];
In -[ChildNode copyWithZone:] an attempt is made to do the latter of the two, and that's what causes the warning to be logged to the console.
// -------------------------------------------------------------------------------
// copyWithZone:zone
// -------------------------------------------------------------------------------
- (id)copyWithZone:(NSZone *)zone
{
id newNode = [[[self class] allocWithZone:zone] init];
// One of the keys in mutableKeys is 'description'...
// ...but it's readonly! (it's defined in the NSObject protocol)
for (NSString *key in [self mutableKeys])
{
[newNode setValue:[self valueForKey:key] forKey:key];
}
return newNode;
}
This begs the question why do you get the warning in your app, and not in the sample app? From what I can tell no ChildNode instance is ever sent a copyWithZone: message in the sample app, whereas this does happen in your app, immediately after the drop. Of course there's a second question here as well: why do Apple explicitly include the description key-path when it can't be set this way? - unfortunately I can't help you with that.
A really handy way of trying to trap errors that don't actually cause exceptions is to add an All Exceptions breakpoint. If you do this in your sample app you'll see that the app freezes at the line that's causing the problem, giving you a better chance of figuring out the issue.

I am unable to show just simple UIActionSheet in my application in IOS8 on real device

When I run this in IOS 8 I get NSRangeException exception
UIActionSheet *uias = [[UIActionSheet alloc] initWithTitle:#"Test"
delegate:self
cancelButtonTitle:#"Test"
destructiveButtonTitle:#"Test"
otherButtonTitles:#"Test", nil];
[uias showInView:self.view];
Exception from output:
2014-09-26 22:18:17.106 rcherzios[354:51170] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM replaceObjectAtIndex:withObject:]: index 0 beyond bounds for empty array'
* First throw call stack:
(0x2b153f87 0x38bc6c77 0x2b071331 0x10b587 0x2b96109b 0x2b961211 0x2b965897 0x2b963141 0x2b963579 0x2b964391 0x2b964215 0x2b966e2d 0x2b9641ab 0x2b99e65b 0x2b99d067 0x2b99ca87 0x2b9643e7 0x2b964215 0x2b966e2d 0x2b9641ab 0x2b99bd01 0x2b966e2d 0x2b99bc79 0x2b953bed 0x2b953ceb 0x2b11a82d 0x2b119af1 0x2b11864b 0x2b065db1 0x2b0af6cb 0x2b966b7f 0x392a6e67 0x392a6ddb 0x392a4b84)
libc++abi.dylib: terminating with uncaught exception of type NSException
Signal: 6 (signal SIGABRT)
In IOS7 and even in simulator IOS 8 everything works, just on real device in IOS8 it crashes...
It looks like in my complex application on wich I wokr for 3 years also all UIAlertView are crashing with same exception, i tried to test new UIAlertController and have same exception. So my conclusion is that some configuration of my application is causing problem to UIAlertController what is actually what UIAlertView and UIActionSheet are using in ios 8.
OK, this was my fault but I don't understand why this caused so hard to tackle problem just under this special circumstances IOS8 and build running on device and ...
So this code caused problem...
#implementation NSMutableArray (Extension)
- (void)setObject:(id)thing atIndexedSubscript:(NSInteger)index {
[self replaceObjectAtIndex:index withObject:thing];
}

Xcode Bad Access Error when calling method

I have a ViewController and in the viewDidLoad Method i initialize a GLKView.
After the GLKView is initialized i try to call a method of that View:
- (void)viewDidLoad
{
[super viewDidLoad];
self.myController = [[MyController alloc] init];
self.myController.parameter1 = #"BLA";
[self.myController initTargets];
}
My initTargets Method is not really amazing. It actually does not more
than this:
- (void) initTargets
{
MyTarget *targetOne = [[MyTarget alloc] initWithParameter:self.parameter1];
[self.targets addObject:targetOne];
}
When i try to call the initTargets Method like described above i get the
following error:
Thread 1: EXC_BAD_ACCESS (code=1, address = 0xe80000000)
I never had such a Problem with just calling methods and i dont know what
this error is trying to say me.
Go to Breakpoints pane in xCode, and click the plus sign from the lower left corner. By default, xCode adds an "All exceptions" breakpoint, which means it will stop at any exception, before the actual crash. This is how I debug all "Bad access" exceptions, except for the ones in blocks.
Your accessing an object or pointer that doesn't exist / hasn't been allocated yet. Or has already been destroyed.
So either MyTarget isn't being allocated properly or self.targets isn't.
What is self.targets ? Does that need to be allocated first ?
Also, you have self.paramter1, shouldnt it be self.myController.parameter1 ?

Edit the tableview rows for deleting multiple rows in Tableview in iOS giving error

I follow the link
select multiple rows from uitableview and delete
I write the code in the delete method as
(void)deleterows:(id)sender {
NSArray *array=[selectedRows allObjects];
NSLog(#"indexes are::%#",array);
[self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationTop];
}
but it is giving error as Terminating app due to uncaught exception NSInvalidArgumentException
reason: -[__NSCFNumber row]: unrecognized selector sent to instance 0x9161b50
Please tell me where did I made mistake.
Since you are targeting >= iOS5 you could simply use:
self.tableView.allowsMultipleSelection = YES;
and then
(void)deleterows:(id)sender {
NSArray *array= [self.tableView indexPathsForSelectedRows];
NSLog(#"indexes are::%#",array);
[self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationTop];
}
without using the selectedRows array at all.
If you want multiple selection only in edit mode, you should set
self.tableView.allowsMultipleSelection = YES;
Have a look at allowsMultipleSelectionDuringEditing in the Documentation.
selectedRows is an array of NSNumbers. deleteRowsAtIndexPaths:withRowAnimation: expects an array of NSIndexPath objects. The answer you linked clearly states that you should create such array:
in your deleteRows method, iterate through the selectedRows set, building up an array of indexPaths, delete these rows from your data
model, then call (with your preferred animation type):
[self.myTableView deleteRowsAtIndexPaths:arrayOfIndexPathsToDelete
withRowAnimation:UITableViewRowAnimationTop];

Resources