From 8b13fa410ffc968c5f092f7f508e0bbc9cdbd0db Mon Sep 17 00:00:00 2001 From: AShiningRay Date: Tue, 31 Dec 2024 23:30:47 -0300 Subject: [PATCH] PlatformImage: If an image from stream is null, don't throw a NPE House M.D tries to load some nonexistent images like ekg_heart.png and doesn't handle the received NullPointerException properly, so we cannot throw an exception in these cases. --- src/org/recompile/mobile/PlatformImage.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/org/recompile/mobile/PlatformImage.java b/src/org/recompile/mobile/PlatformImage.java index c3f9428e..2b1df557 100644 --- a/src/org/recompile/mobile/PlatformImage.java +++ b/src/org/recompile/mobile/PlatformImage.java @@ -107,7 +107,12 @@ public PlatformImage(String name) InputStream stream = Mobile.getPlatform().loader.getMIDletResourceAsStream(name); - if(stream==null) { throw new NullPointerException("Can't load image from resource, as the returned image is null."); } + if(stream==null) + { + // We should really throw an exception here, but House M.D is one game that explicitly tries to load null images without proper exception handling + //throw new NullPointerException("Can't load image from resource, as the returned image is null."); + Mobile.log(Mobile.LOG_WARNING, PlatformImage.class.getPackage().getName() + "." + PlatformImage.class.getSimpleName() + ": " + "Image From Resource Name failed, is NULL. Might not render properly unless the jar expects it"); + } else { try { temp = ImageIO.read(stream); }