halfhp / androidplot

Charts and plots for Android
http://androidplot.com
Apache License 2.0
505 stars 159 forks source link

NullPointerException at com.androidplot.Plot$BufferedCanvas.recycle(Plot.java:240) #83

Closed Jonathan727 closed 5 years ago

Jonathan727 commented 6 years ago

One of my users encountered a crash that was caused by androidplot attempting to recycle a null Bitmap, bgBuffer. The version of androidplot was 1.5.5.

--------- beginning of crash
E/AndroidRuntime(28933): FATAL EXCEPTION: Androidplot renderThread
E/AndroidRuntime(28933): Process: biz.innomatix.bluefontz, PID: 28933
E/AndroidRuntime(28933): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.
recycle()' on a null object reference
E/AndroidRuntime(28933):        at com.androidplot.Plot$BufferedCanvas.recycle(Plot.java:240)
E/AndroidRuntime(28933):        at com.androidplot.Plot$1.run(Plot.java:422)
E/AndroidRuntime(28933):        at java.lang.Thread.run(Thread.java:818)

I haven't looked into the precise conditions that could cause this yet. An easy solution would be to just check for null:

public void recycle() {
    if (bgBuffer != null) {
        bgBuffer.recycle();
        bgBuffer = null;
    }

    if (fgBuffer != null) {
        fgBuffer.recycle();
        fgBuffer = null;
    }
    System.gc();
}

This crash is probably pretty rare, I've never seen it myself while developing and testing.

halfhp commented 6 years ago

Thanks for reporting - will make sure this is fixed in the next release

halfhp commented 5 years ago

fixed in 1.5.7