Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGAffineTransformInvert: singular matrix

Tags:

ios

uiwebview

I've been occasionally seeing the error message:

CGAffineTransformInvert: singular matrix

In the logging area of Xcode. This seems to occur (infrequently, fortunately) when I pinch to resize a web site within a UIWebView. [Commercial website, not my own.] Since I do no Affine Transformations in my App, I'm wondering if this might be a bug/feature of UIWebView. If so, can I ignore it, since it doesn't seem to be interfering with anything?

like image 273
Ric Steinberger Avatar asked Aug 18 '12 04:08

Ric Steinberger


4 Answers

From looking around at other posts, it appears you'll get this message if you try and set the zoom scale to zero. Would be useful to NSLog the scale value when you pinch and see if it gets to zero (and occurs at the same time as the affine transform error).

like image 119
Magic Bullet Dave Avatar answered Oct 04 '22 03:10

Magic Bullet Dave


Try using a real near zero value then :

#define kNearZeroValue 0.001f
like image 39
Vaseltior Avatar answered Oct 04 '22 03:10

Vaseltior


This is the problem with affine transformations when transforming matrix somewhere in the code.

So basically the code is trying to transform a singular matrix (determinant is 0) which is invalid. So you should avoid matrices like:

0 0 0
0 0 0
0 0 1

and similar by checking whether it's singular 3x3 matrix based on its determinant. It is considered a mathematical violation to perform operations on matrices with a determinant of zero (similar to dividing by zero).

If you're using uiscrollview class, make sure you aren't scaling instance to 0 either using setZoomScale:animated: method or zoomScale property, so please check your scroll views (set your zoomScale, minimumZoomScale and maximumZoomScale to set to at least 0.1).

Source: CGAffineTransformInvert - singular matrix error

like image 32
kenorb Avatar answered Oct 04 '22 03:10

kenorb


For each webView do:

webView.scrollView.minimumZoomScale = 0.1;

Or any other number greater than zero.

like image 35
Terminus Avatar answered Oct 04 '22 03:10

Terminus