Skip to content

Commit

Permalink
Make image loading errors no longer crash.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommycli committed Dec 31, 2015
1 parent 5bbdd20 commit 5aa3da1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions core/src/main/scala/rpgboss/model/resource/ImageResource.scala
Expand Up @@ -87,9 +87,20 @@ trait TiledImageResource[T, MT <: AnyRef] extends ImageResource[T, MT] {
trait ImageResource[T, MT <: AnyRef]
extends Resource[T, MT]
with RpgGdxAsset[Texture] {
// TODO: Refactor or eliminate this method, since it's unpredictable
lazy val img = Option(ImageIO.read(newDataStream)) getOrElse {
throw ResourceException("Can't load image: %s".format(name))

/**
* Always returns a non-null BufferedImage. Returns a placeholder image on
* error.
*/
lazy val img: BufferedImage = {
val stream = newDataStream
if (stream == null) {
ImageResource.errorTile
} else {
Option(ImageIO.read(stream)) getOrElse {
ImageResource.errorTile
}
}
}
}

Expand Down

0 comments on commit 5aa3da1

Please sign in to comment.