androidpdfsegmentation-faultandroid-pdf-api

Android PdfDocument multipage cause Fatal signal 11 (SIGSEGV)


I am trying to create a multipage PDF file on Android, using PDFDocument. After creating a new page (method newPDFPage()) the next following line, for example canvas.drawLine(start, position, finish, position, paint); causes the app to crash with no reference to a line in code.

Error: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x12

@TargetApi(Build.VERSION_CODES.KITKAT)
public void newPDFPage() {

    document.finishPage(page);
    pageInfo = new PdfDocument.PageInfo.Builder(595, 842, 1).create();
    page = document.startPage(pageInfo);
    position = titleBaseLine;

}

It does not crash every time, and occurs at random (works 2/10).

Full stack-trace

Fatal signal 11 (SIGSEGV), code 1, fault addr 0x12 in tid 20916 (com.example.app)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'htc/htc_europe/htc_m8:6.0/MRA58K/662736.4:user/release-keys'
Revision: '0'
ABI: 'arm'
pid: 20916, tid: 20916, name: com.example.app  >>> com.example.app <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x12
r0 b8bc42e8  r1 42340000  r2 43480000  r3 44098000
r4 00000000  r5 b8bc42e8  r6 ffffffff  r7 b8aa20d0
r8 ffffffff  r9 b70269a0  sl 133b4b50  fp 12e6de80
ip 00000013  sp beef6d70  lr 7313d985  pc 00000012  cpsr 600e0030
#00 pc 00000012  <unknown>
#01 pc 02cb8983  /system/framework/arm/boot.oat (offset 0x2256000)    

If there is anything missing, let me know and i'll edit the question!


Solution

  • The problem is probably, that when you are creating a new page, you have to re-initialize / get the Canvas again.

    Canvas canvas = page.getCanvas();