9

My coworker and I are experiencing very strange behavior with an Android Canvas object.

We're dealing with an initialized canvas object and are selectively getting a Fatal Signal 11 Error between 2 Nexus 7 tablets; one of which runs 4.2.2 and works fine, and the other which runs 4.3 and crashes. We are trying to figure out how to go about troubleshooting the problem which involves determining if the error is on our part, or a glitch somehow in the Android API (unlikely).

The error occurs when we try to call canvas.getWidth() on the object.

Our Java code: ( not that it probably matters but Rect is from our codebase, it's not an android.graphics.Rect)


public Rect getViewportBounds() { 
    Canvas can = _diagram._canvas;
    Rect vb = _viewportBounds;
    if (can == null) return vb;
    Point pos = _position;
    int[] approxWindowVals = { (int) pos.getX(), (int) pos.getY() };
    double sc = _scale;
    vb._set(approxWindowVals[0], approxWindowVals[1], Math.max(can.getWidth(), 0) / sc, Math.max(can.getHeight(), 0) / sc);
    return vb;
}

Our information from LogCat is here

08-09 16:49:14.883: W/View(4083): requestLayout() improperly called by com.nwoods.go.Viewport{41dfcb08 V.ED.... ......I. 0,0-0,0} during layout: running second layout pass
08-09 16:49:14.893: W/View(4083): requestLayout() improperly called by com.nwoods.go.Viewport{41dfcb08 V.ED.... ......I. 0,0-0,0} during second layout pass: posting in next frame
08-09 16:49:14.923: W/View(4083): requestLayout() improperly called by com.nwoods.go.Viewport{41dfcb08 V.ED.... ......I. 0,0-0,0} during layout: running second layout pass
08-09 16:49:14.943: D/abc(4083): onDraw
08-09 16:49:14.943: W/View(4083): requestLayout() improperly called by com.nwoods.go.Viewport{41dfcb08 V.ED.... ......I. 0,0-0,0} during second layout pass: posting in next frame
08-09 16:49:14.973: W/View(4083): requestLayout() improperly called by com.nwoods.go.Viewport{41dfcb08 V.ED.... ......I. 0,0-0,0} during layout: running second layout pass
08-09 16:49:14.983: W/View(4083): requestLayout() improperly called by com.nwoods.go.Viewport{41dfcb08 V.ED.... ......I. 0,0-0,0} during second layout pass: posting in next frame
08-09 16:49:15.003: W/View(4083): requestLayout() improperly called by com.nwoods.go.Viewport{41dfcb08 V.ED.... ......I. 0,0-0,0} during layout: running second layout pass
08-09 16:49:15.033: A/libc(4083): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 4083 (egressiontester)

Our hardware configurations are as follows:

+---------+------------+-----------------------+
| Tablet  | Android OS |     Reached Error     |
+---------+------------+-----------------------+
| Nexus 7 | 4.2.2      | NO                    |
| Nexus 7 | 4.3        | YES                   |
+---------+------------+-----------------------+

If you have any idea as to why this is happening please let me know. We might have to restructure the Canvas, but we're both pretty confused that a class as common as Canvas is behaving differently on two identical tablets.

Thank you very much for your support :)

deadboy
  • 849
  • 2
  • 9
  • 28
  • 2
    Do you use hardware accelerated canvas? Have you tried turning hardware acceleration on/off? – Andrzej Duś Aug 12 '13 at 15:07
  • @AndrzejDuś, Hardware acceleration was initially turned off, and turning it on **did** solve the problem, however we are developing a class library and so we must write code for as many users&use cases as possible. – deadboy Aug 12 '13 at 16:17

2 Answers2

1

Not rendering on the second layout pass if the changed flag is false solved this issue for me.

Mike
  • 26
  • 1
  • Welcome to Stack Overflow! Please don't add "thanks" as answers. Invest some time in the site and you will gain sufficient [privileges](http://stackoverflow.com/privileges) to upvote answers you like, which is the Stack Overflow way of saying thank you. – John Dvorak Sep 09 '13 at 22:23
0

We fixed this issue by simply assigning our Canvas object to null after using it. Under the hood this probably caused the Android API to reinitialize it with a valid address.

The problem has been solved, but the fact that the address issue got resolved implicitly on 4.2.2 and not on 4.3 is probably a bug and should be researched further.

deadboy
  • 849
  • 2
  • 9
  • 28
  • If you think it's a bug in Android, report it on the Android bug tracker. Right now, you're the only one who can research it further: no one else has the same code or instructions to reproduce. – Dan Hulme Aug 19 '13 at 10:15
  • It's not a bug. You should not be holding a reference to a `Canvas`. Further, you should probably not use `Canvas.getWidth` since it has different meaning depending on whether it's a hardware-accelerated view or not (full window size vs just View size) – Delyan Aug 19 '13 at 10:55