【发布时间】:2015-07-01 06:03:03
【问题描述】:
我正在尝试在 onDraw 方法中使用 android Movie 类在 ImageView 中显示动画 gif,如下所示:
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT);
super.onDraw(canvas);
long now = android.os.SystemClock.uptimeMillis();
if (movieStart == 0) {
movieStart = now;
}
movie = getMovieFromGif();
if (movie != null && movie.duration() > 0) {
try {
int relTime = (int) ((now - movieStart) % movie.duration());
movie.setTime(relTime);
float movie_height = convertDpToPixels(movie.height());
float movie_width = convertDpToPixels(movie.width());
float new_movie_height = movie_height;
float new_movie_width = movie_width;
float movie_ratio = movie_width / movie_height;
if (new_movie_width > container_width) {
new_movie_width = container_width;
new_movie_height = new_movie_width / movie_ratio;
}
if (new_movie_height > container_height) {
new_movie_height = container_height;
new_movie_width = new_movie_height * movie_ratio;
}
float scale_x = container_width / new_movie_width;
float scale_y = container_height / new_movie_height;
scale_x = new_movie_width / (float) movie.width();
scale_y = new_movie_height / (float) movie.height();
canvas.scale(scale_x, scale_y);
float x = 0;
if ((float) this.getWidth() > new_movie_width) {
x = ((this.getWidth() - (movie.width() * scale_x)) / 2f)
/ scale_x;
}
movie.draw(canvas, x, 0);
this.invalidate();
} catch (Exception ex) {
Log.i("onDraw()", "Error: " + ex.getMessage());
}
}
}
代码在大多数设备上运行良好,但在华为 Ascend P7 和三星 Galaxy a5 上,应用程序在 movie.draw(canvas, x, 0) 上崩溃,但有异常:
A/libc(23632):致命信号 11 (SIGSEGV) 位于 0x00000000 (code=1), 线程 23632
知道这些设备上的 movie.draw 有什么问题吗?
更新: 以下是完整的堆栈跟踪
04-29 12:09:24.979: D/Activity(18951): #2 setTransGradationModeColor 为真
04-29 12:09:25.049: I/Adreno-EGL(18951): : EGL 1.4 高通构建: ()
04-29 12:09:25.049:I/Adreno-EGL(18951):OpenGL ES 着色器编译器版本: E031.24.02.07
04-29 12:09:25.049:I/Adreno-EGL(18951):构建 日期:2014 年 8 月 6 日星期三
04-29 12:09:25.049:I/Adreno-EGL(18951):本地 分支:rb1
04-29 12:09:25.049:I/Adreno-EGL(18951):远程 分支:
04-29 12:09:25.049:I/Adreno-EGL(18951):本地补丁:
04-29 12:09:25.049:I/Adreno-EGL(18951):重建分支:
04-29 12:09:25.079:D/OpenGLRenderer(18951):启用调试模式 0
04-29 12:09:25.109: D/skia(18951): streamToByte: 输入 agif 图片大于 30MB。
04-29 12:09:25.109: D/skia(18951): streamToByte : Quram agif - 长度 : 10473
04-29 12:09:25.109: D/skia(18951):Wink AGIF Move Constructer End 9, totalTime : 2700
04-29 12:09:25.109: A/libc(18951): 致命信号 11 (SIGSEGV) 在 0x00000000(代码=1),线程 18951 (com.android.gif)
执行代码movie.draw()后出现致命信号错误,rest是movie.draw()之前行执行的堆栈跟踪。
【问题讨论】:
-
这似乎是一个原生空指针取消引用,但您需要发布完整的原生堆栈跟踪才能解开它,而不仅仅是一行的一部分。
-
用堆栈跟踪更新了问题。
-
这不是堆栈跟踪,而是紧接在堆栈跟踪之前的一些日志消息。也包括实际的堆栈跟踪。
标签: java android fatal-error samsung-mobile