Do not catch graphics exception too early (#413)

This commit is contained in:
Andrey Novikov
2017-09-27 13:54:05 +03:00
committed by Emux
parent 75c2841a13
commit 4a848cc08c
8 changed files with 36 additions and 70 deletions

View File

@@ -28,6 +28,7 @@ import org.oscim.layers.vector.geometries.Style;
import org.oscim.map.Map; import org.oscim.map.Map;
import org.oscim.renderer.bucket.TextureItem; import org.oscim.renderer.bucket.TextureItem;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -45,8 +46,13 @@ public class LineTexActivity extends SimpleMapActivity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
TextureItem tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png")); TextureItem tex = null;
tex.mipmap = true; try {
tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
tex.mipmap = true;
} catch (IOException e) {
e.printStackTrace();
}
for (double lat = -90; lat <= 90; lat += 5) { for (double lat = -90; lat <= 90; lat += 5) {
int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f); int c = Color.fade(Color.rainbow((float) (lat + 90) / 180), 0.5f);

View File

@@ -59,23 +59,13 @@ public final class AndroidGraphics extends CanvasAdapter {
} }
@Override @Override
public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) { public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException {
try { return new AndroidSvgBitmap(inputStream, width, height, percent);
return new AndroidSvgBitmap(inputStream, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
return null;
}
} }
@Override @Override
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) { public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) throws IOException {
try { return createBitmap(relativePathPrefix, src, width, height, percent);
return createBitmap(relativePathPrefix, src, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
}
return null;
} }
@Override @Override

View File

@@ -104,32 +104,17 @@ public class AwtGraphics extends CanvasAdapter {
} }
@Override @Override
public Bitmap decodeBitmapImpl(InputStream inputStream) { public Bitmap decodeBitmapImpl(InputStream inputStream) throws IOException {
try { return new AwtBitmap(inputStream);
return new AwtBitmap(inputStream);
} catch (IOException e) {
e.printStackTrace();
return null;
}
} }
@Override @Override
public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) { public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException {
try { return new AwtSvgBitmap(inputStream, width, height, percent);
return new AwtSvgBitmap(inputStream, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
return null;
}
} }
@Override @Override
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) { public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) throws IOException {
try { return createBitmap(relativePathPrefix, src, width, height, percent);
return createBitmap(relativePathPrefix, src, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
}
return null;
} }
} }

View File

@@ -55,32 +55,17 @@ public class IosGraphics extends CanvasAdapter {
} }
@Override @Override
protected Bitmap decodeBitmapImpl(InputStream inputStream) { protected Bitmap decodeBitmapImpl(InputStream inputStream) throws IOException {
try { return new IosBitmap(inputStream);
return new IosBitmap(inputStream);
} catch (IOException e) {
log.error("decodeBitmapImpl", e);
return null;
}
} }
@Override @Override
protected Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) { protected Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException {
try { return new IosSvgBitmap(inputStream, width, height, percent);
return new IosSvgBitmap(inputStream, width, height, percent);
} catch (IOException e) {
log.error("decodeSvgBitmapImpl", e);
return null;
}
} }
@Override @Override
protected Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) { protected Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) throws IOException {
try { return createBitmap(relativePathPrefix, src, width, height, percent);
return createBitmap(relativePathPrefix, src, width, height, percent);
} catch (IOException e) {
log.error("loadBitmapAssetImpl", e);
return null;
}
} }
} }

View File

@@ -111,9 +111,9 @@ public abstract class CanvasAdapter {
* @param inputStream the input stream * @param inputStream the input stream
* @return the bitmap * @return the bitmap
*/ */
protected abstract Bitmap decodeBitmapImpl(InputStream inputStream); protected abstract Bitmap decodeBitmapImpl(InputStream inputStream) throws IOException;
public static Bitmap decodeBitmap(InputStream inputStream) { public static Bitmap decodeBitmap(InputStream inputStream) throws IOException {
return g.decodeBitmapImpl(inputStream); return g.decodeBitmapImpl(inputStream);
} }
@@ -123,9 +123,9 @@ public abstract class CanvasAdapter {
* @param inputStream the input stream * @param inputStream the input stream
* @return the SVG bitmap * @return the SVG bitmap
*/ */
protected abstract Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent); protected abstract Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException;
public static Bitmap decodeSvgBitmap(InputStream inputStream, int width, int height, int percent) { public static Bitmap decodeSvgBitmap(InputStream inputStream, int width, int height, int percent) throws IOException {
return g.decodeSvgBitmapImpl(inputStream, width, height, percent); return g.decodeSvgBitmapImpl(inputStream, width, height, percent);
} }
@@ -136,13 +136,13 @@ public abstract class CanvasAdapter {
* @param src the resource * @param src the resource
* @return the bitmap * @return the bitmap
*/ */
protected abstract Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent); protected abstract Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) throws IOException;
public static Bitmap getBitmapAsset(String relativePathPrefix, String src) { public static Bitmap getBitmapAsset(String relativePathPrefix, String src) throws IOException {
return getBitmapAsset(relativePathPrefix, src, 0, 0, 100); return getBitmapAsset(relativePathPrefix, src, 0, 0, 100);
} }
public static Bitmap getBitmapAsset(String relativePathPrefix, String src, int width, int height, int percent) { public static Bitmap getBitmapAsset(String relativePathPrefix, String src, int width, int height, int percent) throws IOException {
return g.loadBitmapAssetImpl(relativePathPrefix, src, width, height, percent); return g.loadBitmapAssetImpl(relativePathPrefix, src, width, height, percent);
} }

View File

@@ -1039,7 +1039,7 @@ public class XmlMapsforgeThemeBuilder extends DefaultHandler {
try { try {
b.bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), symbol, b.symbolWidth, b.symbolHeight, b.symbolPercent); b.bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), symbol, b.symbolWidth, b.symbolHeight, b.symbolPercent);
} catch (Exception e) { } catch (Exception e) {
log.debug(e.getMessage()); log.error("{}: {}", symbol, e.getMessage());
} }
} else } else
b.texture = getAtlasRegion(symbol); b.texture = getAtlasRegion(symbol);
@@ -1132,7 +1132,7 @@ public class XmlMapsforgeThemeBuilder extends DefaultHandler {
if (bitmap != null) if (bitmap != null)
return buildSymbol(b, src, bitmap); return buildSymbol(b, src, bitmap);
} catch (Exception e) { } catch (Exception e) {
log.debug(e.getMessage()); log.error("{}: {}", src, e.getMessage());
} }
return null; return null;
} }

View File

@@ -1016,7 +1016,7 @@ public class XmlThemeBuilder extends DefaultHandler {
try { try {
b.bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), symbol, b.symbolWidth, b.symbolHeight, b.symbolPercent); b.bitmap = CanvasAdapter.getBitmapAsset(mTheme.getRelativePathPrefix(), symbol, b.symbolWidth, b.symbolHeight, b.symbolPercent);
} catch (Exception e) { } catch (Exception e) {
log.debug(e.getMessage()); log.error("{}: {}", symbol, e.getMessage());
} }
} else } else
b.texture = getAtlasRegion(symbol); b.texture = getAtlasRegion(symbol);
@@ -1109,7 +1109,7 @@ public class XmlThemeBuilder extends DefaultHandler {
if (bitmap != null) if (bitmap != null)
return buildSymbol(b, src, bitmap); return buildSymbol(b, src, bitmap);
} catch (Exception e) { } catch (Exception e) {
log.debug(e.getMessage()); log.error("{}: {}", src, e.getMessage());
} }
return null; return null;
} }

View File

@@ -61,7 +61,7 @@ public final class Utils {
return new TextureItem(bitmap, true); return new TextureItem(bitmap, true);
} }
} catch (Exception e) { } catch (Exception e) {
log.debug("missing file / {}", e.getMessage()); log.error("{}: missing file / {}", src, e.getMessage());
} }
return null; return null;
} }