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.renderer.bucket.TextureItem;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -45,8 +46,13 @@ public class LineTexActivity extends SimpleMapActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextureItem tex = new TextureItem(CanvasAdapter.getBitmapAsset("", "patterns/pike.png"));
TextureItem tex = null;
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) {
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
public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) {
try {
public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException {
return new AndroidSvgBitmap(inputStream, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
@Override
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) {
try {
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) throws IOException {
return createBitmap(relativePathPrefix, src, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override

View File

@@ -104,32 +104,17 @@ public class AwtGraphics extends CanvasAdapter {
}
@Override
public Bitmap decodeBitmapImpl(InputStream inputStream) {
try {
public Bitmap decodeBitmapImpl(InputStream inputStream) throws IOException {
return new AwtBitmap(inputStream);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
@Override
public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) {
try {
public Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException {
return new AwtSvgBitmap(inputStream, width, height, percent);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
@Override
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) {
try {
public Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) throws IOException {
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
protected Bitmap decodeBitmapImpl(InputStream inputStream) {
try {
protected Bitmap decodeBitmapImpl(InputStream inputStream) throws IOException {
return new IosBitmap(inputStream);
} catch (IOException e) {
log.error("decodeBitmapImpl", e);
return null;
}
}
@Override
protected Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) {
try {
protected Bitmap decodeSvgBitmapImpl(InputStream inputStream, int width, int height, int percent) throws IOException {
return new IosSvgBitmap(inputStream, width, height, percent);
} catch (IOException e) {
log.error("decodeSvgBitmapImpl", e);
return null;
}
}
@Override
protected Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) {
try {
protected Bitmap loadBitmapAssetImpl(String relativePathPrefix, String src, int width, int height, int percent) throws IOException {
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
* @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);
}
@@ -123,9 +123,9 @@ public abstract class CanvasAdapter {
* @param inputStream the input stream
* @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);
}
@@ -136,13 +136,13 @@ public abstract class CanvasAdapter {
* @param src the resource
* @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);
}
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);
}

View File

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

View File

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

View File

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