Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash originating in ChartViewPortHandler #576

Closed
fguchelaar opened this issue Nov 27, 2015 · 13 comments
Closed

Crash originating in ChartViewPortHandler #576

fguchelaar opened this issue Nov 27, 2015 · 13 comments

Comments

@fguchelaar
Copy link

After running a couple of weeks with no issues, today I received a crashreport through Crashlytics for my app. It's the first time I'm seeing this crash and (sadly?) I am not able to reproduce it. Any thoughts?

Thread : Crashed: com.apple.main-thread
0  Charts                         0x2def9c _TFC6Charts20ChartViewPortHandler15isInBoundsRightfS0_FV12CoreGraphics7CGFloatSb + 188
1  Charts                         0x320e10 _TTSf4g_n___TFC6Charts17LineChartRendererP33_E2D8D44B88C9349B6643B50EDA26A8FC11drawCirclesfS0_FT7contextGSqCSo9CGContext__T_ + 2128
2  Charts                         0x320e10 _TTSf4g_n___TFC6Charts17LineChartRendererP33_E2D8D44B88C9349B6643B50EDA26A8FC11drawCirclesfS0_FT7contextGSqCSo9CGContext__T_ + 2128
3  Charts                         0x31aba0 _TFC6Charts17LineChartRenderer10drawExtrasfS0_FT7contextGSqCSo9CGContext__T_ + 16
4  Charts                         0x263a60 _TFC6Charts20BarLineChartViewBase8drawRectfS0_FVSC6CGRectT_ + 5384
5  Charts                         0x263e0c _TFC6Charts20BarLineChartViewBase8drawRectfS0_FVSC6CGRectT_ + 6324
6  UIKit                          0x2943d5b7 -[UIView(CALayerDelegate) drawLayer:inContext:] + 386
7  QuartzCore                     0x28ca8411 -[CALayer drawInContext:] + 228
8  QuartzCore                     0x28c91cff CABackingStoreUpdate_ + 1866
9  QuartzCore                     0x28d7fa25 ___ZN2CA5Layer8display_Ev_block_invoke + 52
10 QuartzCore                     0x28c9122b CA::Layer::display_() + 1170
11 QuartzCore                     0x28c753e1 CA::Layer::display_if_needed(CA::Transaction*) + 208
12 QuartzCore                     0x28c75099 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
13 QuartzCore                     0x28c745b1 CA::Context::commit_transaction(CA::Transaction*) + 368
14 QuartzCore                     0x28c74263 CA::Transaction::commit() + 614
15 UIKit                          0x293b4ab7 _UIApplicationHandleEventQueue + 5518
16 CoreFoundation                 0x252447c7 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
17 CoreFoundation                 0x252443b7 __CFRunLoopDoSources0 + 454
18 CoreFoundation                 0x2524271f __CFRunLoopRun + 806
19 CoreFoundation                 0x251950d9 CFRunLoopRunSpecific + 516
20 CoreFoundation                 0x25194ecd CFRunLoopRunInMode + 108
21 GraphicsServices               0x2e37caf9 GSEventRunModal + 160
22 UIKit                          0x2941e2dd UIApplicationMain + 144
23 THeAppInQuestion               0x2fe04 main (AppDelegate.swift:16)
24 libdyld.dylib                  0x37414873 start + 2

Details:
Charts version 2.1.4, installed with CocoaPods
Crash reported from an iPad 4, running iOS 9.1

@liuxuan30
Copy link
Member

    public func isInBoundsRight(x: CGFloat) -> Bool
    {
        let normalizedX = CGFloat(Int(x * 100.0)) / 100.0
        return (_contentRect.origin.x + _contentRect.size.width) >= normalizedX ? true : false
    }

The crashes happened in drawCircles from the trace:

            for (var j = minx, count = Int(ceil(CGFloat(maxx - minx) * phaseX + CGFloat(minx))); j < count; j++)
            {
                let e = entries[j]
                pt.x = CGFloat(e.xIndex)
                pt.y = CGFloat(e.value) * phaseY
                pt = CGPointApplyAffineTransform(pt, valueToPixelMatrix)

                if (!viewPortHandler.isInBoundsRight(pt.x))
                {
                    break
                }

I guess e.xIndex is transformed to nan and cause crash? Have you changed anything around the x, xIndex, transformer matrix?

These kinds of crashes is a little hard to tell. If you are not sure, maybe add a CLS_LOG to capture what is the x value before and after transform. Also try to capture as many values as possible to help understand what happened, if allowed.

@fguchelaar
Copy link
Author

No, I'm not doing anything with regards to ios-charts, other than having one on a Storyboard, connected to a ViewController and setting some styles and data.

What I find really strange, however, is that the stack trace boils down to the AppDelegate with no mention of a ViewController whatsoever.

Capturing extra data is not possible atm, since I cannot reproduce and the crash is happening somewhere 'in the field'. What I did fail to mention, was the Exception type and code:

EXC_BREAKPOINT 0x00000000e7ffdefe

@liuxuan30
Copy link
Member

Because it crashes inside drawRect of a run loop, at that time, the view controller stuff is not captured. Only things in drawRect and its context.

if you are using crashlytics, is your/your company policy allowed to log down values before/after the transform by using CLSLogv?
something like

CLSLogv("pt.x %f, xValCount:%d before transform", getVaList([pt.x, _data.xValCount]))
...
CLSLogv("pt.x %f, xValCount:%d after transform", getVaList([pt.x, _data.xValCount]))

Usually for this kind of crashes we need to know the x values and data entries to knock it down, it's data related.
Then after your next app release, if you get the same crash again, you can see ths logs from crashlytics and have better ideas.

@fguchelaar
Copy link
Author

Thanks, I'll add the provided code. I'll get back to you, when I have more information.

@tsznober
Copy link

I'm getting an exception in the same place. here is my data:

Nov 30 15:04:17  SpectatorNow[8462] <Error>: CGAffineTransformInvert: singular matrix.
pt.x 318.0, xValCount:68 before transform
Nov 30 15:04:17  SpectatorNow[8462] <Error>: CGAffineTransformInvert: singular matrix.
pt.x nan, xValCount:68 after transform

I'm getting it in public var highestVisibleXIndex: Int (line 1721 of BarLineChartViewBase.swift.

@liuxuan30
Copy link
Member

@tsznober since you get it, you see singular matrix? it appears you'll get this message if you try and set the zoom scale to zero.
Double check your data, print out your matrixValueToPx, expecially matrix.a, matrix.tx, and you can know what's wrong.

@liuxuan30
Copy link
Member

@fguchelaar remember to add enough variables to log down. Like the matrix values when crashing, values can help calculate the matrix, _viewPortHandler.contentRect, etc.
(Usually they are chartXMin, deltaX, deltaY, chartYMin, and _viewPortHandler.contentRect)

@tsznober
Copy link

tsznober commented Dec 2, 2015

@liuxuan30 I captured a bit more data. I did a po for getTransformer(.Left) at the point of the crash. Does this help?

 {
  ObjectiveC.NSObject = {
    isa = Charts.ChartTransformer
  }
  _matrixValueToPx = (a = +Inf, b = NaN, c = -0, d = -501.69921875, tx = NaN, ty = NaN)
  _matrixOffset = (a = 1, b = 0, c = 0, d = 1, tx = 21.1962890625, ty = 511.69921875)
  _viewPortHandler = 0x000000015eebc230 {
    ObjectiveC.NSObject = {
      isa = Charts.ChartViewPortHandler
    }
    _touchMatrix = (a = 1, b = 0, c = 0, d = 1, tx = -0, ty = -0)
    _contentRect = (origin = (x = 21.1962890625, y = 10), size = (width = 685.607421875, height = 501.69921875))
    _chartWidth = 728
    _chartHeight = 551.5
    _minScaleY = 1
    _maxScaleY = 1.7976931348623157E+308
    _minScaleX = 1
    _maxScaleX = 1.7976931348623157E+308
    _scaleX = 1
    _scaleY = 1
    _transX = -0
    _transY = -0
    _transOffsetX = 0
    _transOffsetY = 0
  }
}

@liuxuan30
Copy link
Member

Of course, you see (a = +Inf, b = NaN, c = -0, d = -501.69921875, tx = NaN, ty = NaN)? That's the problem. your matrixValueToPx is a mess. Check why you got this. Do you change it? By default, it will not look like this. You need to check how this is calculated and you know what goes wrong.

@danielgindi
Copy link
Collaborator

Actually, @fguchelaar and @liuxuan30 , isInBoundsRight shouldn't trigger any crash, even on a NaN, as the result of mathematical operations on a NaN will just product a NaN - not an exception. You can test this in the playground.

So my only guess is a compiler bug...

@fguchelaar seems like your scaling is so off, nearing Infinity - so that creates NaN values. I guess you already know what's wrong with your data since you haven't responded for 14 days.

@fguchelaar
Copy link
Author

@danielgindi well... I actually don't know what's wrong. The issue just did not reoccur again (which, off course, is a good thing).

@danielgindi
Copy link
Collaborator

I suspect that it could be tied to empty data object, but that issue is resolved now

@fguchelaar
Copy link
Author

Great! If anything new comes up, I'll report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants