From 347a070e6a75bed15e44aa43a1045b8335703e99 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 24 Jan 2003 21:51:26 +0000 Subject: [PATCH] Not to freak out if we get to a tileset image that we can't trim because its hosed. Instead write an error image/tileset to the bundle and keep on truckin'. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2219 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../tile/bundle/tools/TileSetBundler.java | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/java/com/threerings/media/tile/bundle/tools/TileSetBundler.java b/src/java/com/threerings/media/tile/bundle/tools/TileSetBundler.java index e9466415e..e8da9452d 100644 --- a/src/java/com/threerings/media/tile/bundle/tools/TileSetBundler.java +++ b/src/java/com/threerings/media/tile/bundle/tools/TileSetBundler.java @@ -1,5 +1,5 @@ // -// $Id: TileSetBundler.java,v 1.12 2003/01/24 19:34:25 mdb Exp $ +// $Id: TileSetBundler.java,v 1.13 2003/01/24 21:51:26 mdb Exp $ package com.threerings.media.tile.bundle.tools; @@ -33,6 +33,7 @@ import com.samskivert.io.PersistenceException; import com.threerings.media.Log; import com.threerings.media.image.Colorization; +import com.threerings.media.image.ImageUtil; import com.threerings.media.image.Mirage; import com.threerings.media.tile.ObjectTileSet; @@ -40,6 +41,7 @@ import com.threerings.media.tile.SimpleCachingImageProvider; import com.threerings.media.tile.TileSet; import com.threerings.media.tile.TileSetIDBroker; import com.threerings.media.tile.TrimmedObjectTileSet; +import com.threerings.media.tile.UniformTileSet; import com.threerings.media.tile.bundle.BundleUtil; import com.threerings.media.tile.bundle.TileSetBundle; @@ -308,12 +310,12 @@ public class TileSetBundler jar.putNextEntry(new JarEntry(imagePath)); // if this is an object tileset, we can't trim it! - try { - if (set instanceof ObjectTileSet) { - // set the tileset up with an image provider; we - // need to do this so that we can trim it! - set.setImageProvider(improv); + if (set instanceof ObjectTileSet) { + // set the tileset up with an image provider; we + // need to do this so that we can trim it! + set.setImageProvider(improv); + try { // create a trimmed object tileset, which will // write the trimmed tileset image to the jar // output stream @@ -325,18 +327,30 @@ public class TileSetBundler // tileset in the tileset bundle bundle.addTileSet(tileSetId, tset); - } else { - // open the image and pipe it into the jar file - File imgfile = new File(bundleDesc.getParent(), - imagePath); - FileInputStream imgin = new FileInputStream(imgfile); - StreamUtils.pipe(imgin, jar); + } catch (Exception e) { + System.err.println("Error adding tileset to bundle " + + "[set=" + set.getName() + + ", ipath=" + imagePath + "]."); + e.printStackTrace(System.err); + // replace the tileset with an error tileset + UniformTileSet ets = new UniformTileSet(); + ets.setName(set.getName()); + ets.setWidth(50); + ets.setHeight(50); + ets.setTileCount(1); + ets.setImagePath(imagePath); + bundle.addTileSet(tileSetId, ets); + // and write an error image to the jar file + ImageIO.write(ImageUtil.createErrorImage(50, 50), + "PNG", jar); } - } catch (Exception e) { - String errmsg = "Error adding tileset to bundle " + - "[set=" + set.getName() + ", ipath=" + imagePath + "]"; - throw (IOException)new IOException(errmsg).initCause(e); + } else { + // open the image and pipe it into the jar file + File imgfile = new File( + bundleDesc.getParent(), imagePath); + FileInputStream imgin = new FileInputStream(imgfile); + StreamUtils.pipe(imgin, jar); } }