Skip to content

Commit

Permalink
QA: add debug statements to catch OOM error
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindeland committed Oct 26, 2018
1 parent 9f920a0 commit 3b326bb
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import cmu.xprize.util.IScope;
import cmu.xprize.util.JSON_Helper;

import static android.graphics.Bitmap.createScaledBitmap;
import static android.graphics.BitmapFactory.decodeResource;

public class CBpBackground extends View implements ILoadableObject {

private Paint mPaint;
Expand Down Expand Up @@ -300,8 +303,14 @@ public void onDraw(Canvas canvas) {

CLogManager.getInstance().postEvent_I(TAG, "PickedBackground:" + nextBackground);

Bitmap bmp = BitmapFactory.decodeResource(getResources(), nextBackground);
Bitmap scaled = Bitmap.createScaledBitmap(bmp, canvas.getWidth(), canvas.getHeight(), false);
Bitmap bmp = decodeResource(getResources(), nextBackground);

Log.wtf("BIG_IMAGE", "c_width=" + bmp.getWidth() + "; c_height=" + bmp.getHeight() + "; c_bytes=" + ((bmp.getWidth() * bmp.getHeight()) * 16 + 12));
int width = canvas.getWidth(), height = canvas.getHeight();
int total = width*height;
int projected_byte_failure = (total * 16) + 12;
Log.wtf("BIG_IMAGE", "c_width=" + width + "; c_height=" + height + "; c_bytes=" + projected_byte_failure);
Bitmap scaled = createScaledBitmap(bmp, canvas.getWidth(), canvas.getHeight(), false);
canvas.drawBitmap(scaled, mViewRegion, mViewRegion, mPaint);
} catch (Exception e) {
// if there's an error setting the image, use gray bg, instead of crashing
Expand Down

0 comments on commit 3b326bb

Please sign in to comment.