bevy / photo-editor-android

Photo Editor SDK contains a lot of features like edit, scale, rotate and draw on images like Instagram stories.
MIT License
547 stars 189 forks source link

App crashes when the user clicks on "Clear All" button in the photo editor screen. #24

Open debabrata-rana opened 5 years ago

debabrata-rana commented 5 years ago

Hi,

I've observed the following crash in the sample app. It crashes when the user clicks the "Clear All" button in the photo editor screen.

Steps to reproduce:

  1. In the sample app, click the "Choose From Camera" button.
  2. Capture a photo.
  3. In the photo editor screen, click the "Clear All" button without modifying the photo.
  4. The app crashes throwing NullPointerException.

Exception log: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Canvas.drawColor(int, android.graphics.PorterDuff$Mode)' on a null object reference at com.ahmedadeltito.photoeditorsdk.BrushDrawingView.clearAll(BrushDrawingView.java:121) at com.ahmedadeltito.photoeditorsdk.PhotoEditorSDK.clearAllViews(PhotoEditorSDK.java:184) at com.ahmedadeltito.photoeditor.PhotoEditorActivity.clearAllViews(PhotoEditorActivity.java:216) at com.ahmedadeltito.photoeditor.PhotoEditorActivity.onClick(PhotoEditorActivity.java:340) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

It would be great if this issue is fixed quickly as I'm planning to integrate this lib.

Thanks & regards, Debu

sreekanth100khere commented 5 years ago

Observed by me also. @debabrata-rana How to fix this problem?

sreekanth100khere commented 5 years ago

I fixed it by adding one line if(drawCanvas!=null)

So now the method looks like below


 void clearAll() {
        if(drawCanvas!=null)
        drawCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
        invalidate();
    }