Throw exceptions in Pony.getBufferedImage().

If an exception is thrown, don't save the Pony.
This commit is contained in:
Matthew Messinger 2019-07-13 20:11:14 -04:00
parent 3355a7cb8a
commit b3d849fdc9
2 changed files with 16 additions and 9 deletions

View file

@ -50,7 +50,12 @@ public class Pony implements IPony {
private boolean initialized = false; private boolean initialized = false;
public Pony(Identifier resource) { Pony(Identifier resource, IPonyData data) {
texture = resource;
metadata = data;
}
Pony(Identifier resource) {
texture = resource; texture = resource;
metadata = checkSkin(texture); metadata = checkSkin(texture);
} }
@ -122,8 +127,8 @@ public class Pony implements IPony {
int width = getTexLevelParameter(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH); int width = getTexLevelParameter(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH);
int height = getTexLevelParameter(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT); int height = getTexLevelParameter(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT);
if (width == 0 || height == 0) { if (width * height == 0) {
return null; throw new IllegalStateException("GL texture not uploaded yet");
} }
NativeImage.Format channels = getFormat(format); NativeImage.Format channels = getFormat(format);
@ -135,11 +140,8 @@ public class Pony implements IPony {
try { try {
image.loadFromTextureImage(0, false); image.loadFromTextureImage(0, false);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// Out of memory image.close();
// or buffer contained no/invalid image throw e;
MineLittlePony.logger.fatal("Could not load texture from GL memory", e);
return null;
} }
return image; return image;
} }

View file

@ -36,6 +36,7 @@ import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -66,7 +67,11 @@ public class PonyManager implements IPonyManager, IdentifiableResourceReloadList
@Override @Override
public IPony getPony(Identifier resource) { public IPony getPony(Identifier resource) {
return poniesCache.getUnchecked(resource); try {
return poniesCache.get(resource);
} catch (ExecutionException e) {
return new Pony(resource, new PonyData());
}
} }
@Override @Override