Android:movie.draw 上 0x00000000(代码=1)处的致命信号 11 (SIGSEGV)
Android: Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1) on movie.draw
我正在尝试在 onDraw 方法中使用 android Movie class 在 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());
}
}
}
代码在大多数设备上运行良好,但在 Huawei Ascend P7 和 Samsung galaxy a5 上,应用程序在 movie.draw(canvas, x, 0) 上崩溃,异常:
A/libc(23632): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1),
thread 23632
知道 movie.draw 在这些设备上有什么问题吗?
更新:
以下是完整的堆栈跟踪
04-29 12:09:24.979: D/Activity(18951): #2 setTransGradationModeColor
to true
04-29 12:09:25.049: I/Adreno-EGL(18951):
: EGL 1.4 QUALCOMM build: ()
04-29
12:09:25.049: I/Adreno-EGL(18951): OpenGL ES Shader Compiler Version:
E031.24.02.07
04-29 12:09:25.049: I/Adreno-EGL(18951): Build
Date: 08/06/14 Wed
04-29 12:09:25.049: I/Adreno-EGL(18951): Local
Branch: rb1
04-29 12:09:25.049: I/Adreno-EGL(18951): Remote
Branch:
04-29 12:09:25.049: I/Adreno-EGL(18951): Local Patches:
04-29 12:09:25.049: I/Adreno-EGL(18951): Reconstruct Branch:
04-29 12:09:25.079: D/OpenGLRenderer(18951): Enabling debug mode
0
04-29 12:09:25.109: D/skia(18951): streamToByte : Input agif
image larger than 30MB.
04-29 12:09:25.109: D/skia(18951):
streamToByte : Quram agif - length : 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): Fatal signal 11 (SIGSEGV) at
0x00000000 (code=1), thread 18951 (com.android.gif)
执行代码movie.draw()后发生致命信号错误,其余为movie.draw()之前行的执行堆栈跟踪。
我可以通过禁用 android 硬件加速来解决问题:
android:hardwareAccelerated="false"
和Sultana, but surprisingly here's didn't work for me while this one did. it's 一样
您仅在使用此行绘制电影的特定视图上禁用硬件加速器。
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
我正在尝试在 onDraw 方法中使用 android Movie class 在 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());
}
}
}
代码在大多数设备上运行良好,但在 Huawei Ascend P7 和 Samsung galaxy a5 上,应用程序在 movie.draw(canvas, x, 0) 上崩溃,异常:
A/libc(23632): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 23632
知道 movie.draw 在这些设备上有什么问题吗?
更新: 以下是完整的堆栈跟踪
04-29 12:09:24.979: D/Activity(18951): #2 setTransGradationModeColor to true
04-29 12:09:25.049: I/Adreno-EGL(18951): : EGL 1.4 QUALCOMM build: ()
04-29 12:09:25.049: I/Adreno-EGL(18951): OpenGL ES Shader Compiler Version: E031.24.02.07
04-29 12:09:25.049: I/Adreno-EGL(18951): Build Date: 08/06/14 Wed
04-29 12:09:25.049: I/Adreno-EGL(18951): Local Branch: rb1
04-29 12:09:25.049: I/Adreno-EGL(18951): Remote Branch:
04-29 12:09:25.049: I/Adreno-EGL(18951): Local Patches:
04-29 12:09:25.049: I/Adreno-EGL(18951): Reconstruct Branch:
04-29 12:09:25.079: D/OpenGLRenderer(18951): Enabling debug mode 0
04-29 12:09:25.109: D/skia(18951): streamToByte : Input agif image larger than 30MB.
04-29 12:09:25.109: D/skia(18951): streamToByte : Quram agif - length : 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): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 18951 (com.android.gif)
执行代码movie.draw()后发生致命信号错误,其余为movie.draw()之前行的执行堆栈跟踪。
我可以通过禁用 android 硬件加速来解决问题:
android:hardwareAccelerated="false"
和Sultana, but surprisingly here's didn't work for me while this one did. it's
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);