Fix potential crash when sharing an image of the board

DroidFish.shareImage() can theoretically be called before the chess
board widget measurement has been finished, which would crash the
app.
This commit is contained in:
Peter Osterlund 2019-07-20 08:06:21 +02:00
parent 4411b7f8b6
commit 0dd276ba22

@ -2391,8 +2391,11 @@ public class DroidFish extends Activity
private void shareImage() { private void shareImage() {
View v = findViewById(R.id.chessboard); View v = findViewById(R.id.chessboard);
Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), int w = v.getWidth();
Bitmap.Config.ARGB_8888); int h = v.getHeight();
if (w <= 0 || h <= 0)
return;
Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b); Canvas c = new Canvas(b);
v.draw(c); v.draw(c);
File imgDir = new File(getFilesDir(), "shared"); File imgDir = new File(getFilesDir(), "shared");