prevent NPE

This commit is contained in:
Anthony Calosa
2022-07-12 10:23:17 +08:00
parent 9dd5d9282d
commit 3ac2f00f46
2 changed files with 27 additions and 4 deletions

View File

@@ -927,8 +927,15 @@ public class Forge implements ApplicationListener {
@Override
public void resume() {
try {
Texture.setAssetManager(getAssets().manager);
needsUpdate = true;
} catch (Exception e) {
//the application context must have been recreated from its last state.
//it could be triggered by the low memory on heap on android.
needsUpdate = false;
e.printStackTrace();
}
if (MatchController.getHostedMatch() != null) {
MatchController.getHostedMatch().resume();
}

View File

@@ -661,8 +661,10 @@ public class Graphics {
drawRoundRect(2f, borderLining(borderColor.toString()), x, y, w, h, (h-w)/12);
fillRoundRect(tintColor, x, y, w, h, (h-w)/12);
} else {
if (image != null) {
image.draw(this, x, y, w, h);
fillRoundRect(borderColor, x, y, w, h, (h-w)/10);//show corners edges
fillRoundRect(borderColor, x, y, w, h, (h - w) / 10);//show corners edges
}
}
setAlphaComposite(oldalpha);
}
@@ -672,10 +674,14 @@ public class Graphics {
setAlphaComposite(oldalpha);
}
public void drawImage(FImage image, Color borderColor, float x, float y, float w, float h) {
if (image == null)
return;
image.draw(this, x, y, w, h);
fillRoundRect(borderColor, x+1, y+1, w-1.5f, h-1.5f, (h-w)/10);//used by zoom let some edges show...
}
public void drawAvatarImage(FImage image, float x, float y, float w, float h, boolean drawGrayscale) {
if (image == null)
return;
if (!drawGrayscale) {
image.draw(this, x, y, w, h);
} else {
@@ -693,6 +699,8 @@ public class Graphics {
}
}
public void drawCardImage(FImage image, TextureRegion damage_overlay, float x, float y, float w, float h, boolean drawGrayscale, boolean damaged) {
if (image == null)
return;
if (!drawGrayscale) {
image.draw(this, x, y, w, h);
if (damage_overlay != null && damaged)
@@ -752,6 +760,8 @@ public class Graphics {
}
}
public void drawGrayTransitionImage(FImage image, float x, float y, float w, float h, boolean withDarkOverlay, float percentage) {
if (image == null)
return;
batch.end();
shaderGrayscale.bind();
shaderGrayscale.setUniformf("u_grayness", percentage);
@@ -839,6 +849,8 @@ public class Graphics {
batch.begin();
}
public void drawWarpImage(FImage image, float x, float y, float w, float h, float time) {
if (image == null)
return;
batch.end();
shaderWarp.bind();
shaderWarp.setUniformf("u_amount", 0.2f);
@@ -854,6 +866,8 @@ public class Graphics {
batch.begin();
}
public void drawUnderWaterImage(FImage image, float x, float y, float w, float h, float time, boolean withDarkOverlay) {
if (image == null)
return;
batch.end();
shaderUnderwater.bind();
shaderUnderwater.setUniformf("u_amount", 10f*time);
@@ -893,6 +907,8 @@ public class Graphics {
drawImage(image, x, y, w, h, false);
}
public void drawImage(FImage image, float x, float y, float w, float h, boolean withDarkOverlay) {
if (image == null)
return;
image.draw(this, x, y, w, h);
if(withDarkOverlay){
float oldalpha = alphaComposite;