Skip to content

Commit

Permalink
fixes a bug whereby the lack of a proper width or height leads to an …
Browse files Browse the repository at this point in the history
…exception in Bitmap#createBitmap(), now #onDraw() will be skipped in that case - #48
  • Loading branch information
ToBoehmK committed Mar 16, 2016
1 parent 81484d8 commit 346a7eb
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ protected void onDraw(Canvas canvas) {
if (!mShouldRender) return;

// get current dimensions
int width = getMeasuredWidth();
int height = getMeasuredHeight();
final int width = getMeasuredWidth();
final int height = getMeasuredHeight();

// don't bother drawing if there is nothing to draw on
if(width <= 0 || height <= 0) return;

// build a new canvas if needed i.e first pass or new dimensions
if (mBitmap == null || mCanvas == null || mOldHeight != height || mOldWidth != width) {
Expand All @@ -153,7 +156,6 @@ protected void onDraw(Canvas canvas) {

mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);


mCanvas = new Canvas(mBitmap);
}

Expand Down

0 comments on commit 346a7eb

Please sign in to comment.