android中0x00000000处的致命信号11(SIGSEGV)
在我的android应用程序中,我必须不断创建位图,代码如下:android中0x00000000处的致命信号11(SIGSEGV),android,Android,在我的android应用程序中,我必须不断创建位图,代码如下: @Override protected byte[] getTile(int level, int col, int row) { double[] bbox = getBBOX(level, col, row); byte[] res = Util.getBitMapByteArray(bbox); return res; } public static byte[] getBitMapByteArra
@Override
protected byte[] getTile(int level, int col, int row) {
double[] bbox = getBBOX(level, col, row);
byte[] res = Util.getBitMapByteArray(bbox);
return res;
}
public static byte[] getBitMapByteArray(double[] bbox) {
Bitmap map = MapEngine.GetBitMap(bbox);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
map.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
}
当触发getTile
时,我得到了错误,我的应用程序将退出当前活动并返回到上一个活动:
12-10 10:25:43.424: A/libc(12035): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 12035 (droidPlatEngine)
12-10 10:25:43.424: A/libc(12035): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 12102 (Thread-4336)
而MapEngine.GetBitMap
将通过从本机库调用本机方法
由于方法getTile
的调用是由我无法控制的其他组件进行的(它可能从多个线程调用该方法),因此我尝试将synchronized
关键字添加到这两个方法中:
@Override
protected synchronized byte[] getTile(int level, int col, int row) {
double[] bbox = getBBOX(level, col, row);
byte[] res = Util.getBitMapByteArray(bbox);
return res;
}
public static synchronized byte[] getBitMapByteArray(double[] bbox) {
Bitmap map = MapEngine.GetBitMap(bbox);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
map.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
}
现在,我的应用程序可以运行一段时间,但同样的错误仍会在某个时候再次发生
然后我尝试使用DDMS查看发生了什么,这是heap对话框:
我还发现,如果我一直按“原因GC”按钮,我的应用程序将运行很长一段时间,如果我停止按该按钮,则会退出到以前的活动
现在我不确定这是由线程还是内存、java代码还是本机库引起的
谁能告诉我怎么继续