Skip to content

Commit

Permalink
Fix a potential NPE Crash due to Mismatched Thread Lifecycle
Browse files Browse the repository at this point in the history
- the thread creation and recycling was not being handled symmetrically
- this fix is based off of these two PR: DImuthuUpe#824 and #2
  • Loading branch information
mhiew committed Dec 27, 2021
1 parent 81ae29e commit 41f912e
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ ScrollHandle getScrollHandle() {
public PDFView(Context context, AttributeSet set) {
super(context, set);

renderingHandlerThread = new HandlerThread("PDF renderer");

if (isInEditMode()) {
return;
}
Expand Down Expand Up @@ -462,6 +460,14 @@ public void computeScroll() {
animationManager.computeFling();
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (renderingHandlerThread == null) {
renderingHandlerThread = new HandlerThread("PDF renderer");
}
}

@Override
protected void onDetachedFromWindow() {
recycle();
Expand Down Expand Up @@ -753,6 +759,10 @@ void loadComplete(PdfFile pdfFile) {

this.pdfFile = pdfFile;

if (renderingHandlerThread == null) {
return;
}

if (!renderingHandlerThread.isAlive()) {
renderingHandlerThread.start();
}
Expand Down

0 comments on commit 41f912e

Please sign in to comment.