可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
In the app I'm developing on Android, I keep getting a Fatal Signal 11 error.
I think it's something to do with the way that I'm accessing the memory but I can't figure out what is causing it.
Any help will be much appreciated!
Here's the LogCat:
05-02 23:47:17.618: D/dalvikvm(590): GC_FOR_ALLOC freed 68K, 4% free 6531K/6787K, paused 101ms
05-02 23:47:17.638: I/dalvikvm-heap(590): Grow heap (frag case) to 7.619MB for 1228816-byte allocation
05-02 23:47:17.738: D/dalvikvm(590): GC_CONCURRENT freed 1K, 4% free 7730K/8007K, paused 5ms+14ms
05-02 23:47:17.878: D/dalvikvm(590): GC_FOR_ALLOC freed <1K, 4% free 7730K/8007K, paused 37ms
05-02 23:47:17.888: I/dalvikvm-heap(590): Grow heap (frag case) to 8.790MB for 1228816-byte allocation
05-02 23:47:17.998: D/dalvikvm(590): GC_CONCURRENT freed <1K, 4% free 8930K/9223K, paused 4ms+4ms
05-02 23:47:17.998: A/libc(590): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)
回答1:
I had been trying to call an uninitialised Canvas inside another Class so when it was trying to get the height or width of it, it would crash.
回答2:
I had the same problem with an instance of android.media.MediaRecorder.
The code accessed #getMaxAmplitude()
after #reset()
and #release()
on the MediaRecorder instance had been called.
回答3:
I had this same problem this morning and was able to track it back to accidentally saving an image 800 pixels wide in the drawable-mdpi folder. When I realized what happened I tinkered with it for a second. I tried compressing it hard to see if it was related to file size and it was not. Then I tried saving it again at 650 pixels wide and it worked out of that folder. So somewhere between there is the breaking point for every folder I would guess. Then I put the 800 p wide image in the intended hdpi folder and the 480 p wide in the mdpi and it fixed it.
回答4:
I had the same problem and found after a good night of sleep and a coffee in the morning that I had been silly enough to back the canvas with an uninitialized Bitmap. It seems that much if not all of the canvas drawing code is native code and passing of uninitialized objects is not detected everywhere.
SIGSEGV with a null address (0x00000000) means that your application has dereferenced a null pointer, so look out for places where you pass null pointers (i.e. empty references to object instances you haven't instantiated in the first place) to code that is backed by native code and does not properly check for this error.
回答5:
I experienced the same Fatal error while using Canvas class.
My code looks likes this. The following piece of code initializes an Arc and draws it on the canvas.
private RectF r1 = null;
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
public Arc(Context ctx) {
super(ctx);
mPaint.setColor(0xFFFF0000);
r1 = new RectF(200, 200, 400, 400);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawArc(r1, 0, 90, true, mPaint);
}
The problem occurred because my instance of RectF was not initialized which resulted in NullPointerException and the fatal error.
回答6:
i had this problem when i was making a cocos2d-x app on android. the problem was that my layer was a CCLayer:
CCLayer::init()
but in the header file i had:
class HelloWorld : public cocos2d::CCLayerColor
i changed CCLayerColor to CCLayer and my app worked
回答7:
Same thing happened to me during game development using LibGDX framework for Android, and here's why:
I have 2 screens - GameScreen
and BattleScreen
. GameScreen
is where I move my character on the map. When I have collision with enemy sprite I instantly use game.setScreen(new BattleScreen(this))
and change current screen to BattleScreen
. Here's where the Fatal Signal 11 used to happen. At first I thought it had something to do with loading assets, because my asset manager instance was static. I was trying multiple ways of loading them but nothing worked. It turned out I was changing the screen in the wrong place. For my GameScreen
I had WorldController
and WorldRenderer
instance. I was using worldController.update()
and worldRenderer.render()
inside GameScreen
's render(float deltaTime)
method. Inside worldController.update()
I was checking for collisions and changing screen as soon as I found one with the enemy. It was not good for Android, maybe because it happened between update and render, or it took some time, while update was still running and it lead to conflicts - I don't know. But here is how I fixed it:
- I added a boolean flag (false by default) inside
WorldController
and everytime a collision with enemy happened I was setting it to true
- In
GameScreen
's render()
I was checking this flag - if it was true I would change the screen to BattleScreen
, otherwise I would update and render GameScreen
Now it works perfectly everytime, no FATAL SIGNAL ERROR 11 whatsoever
Here's my GameScreen
's render()
method:
@Override
public void render(float deltaTime) {
if(worldController.isCollisionWithEnemy()) {
game.setScreen(game.battleScreen);
} else {
if(!paused) {
worldController.update(deltaTime);
}
Gdx.gl.glClearColor(57.0f / 255.0f, 181.0f / 225.0f, 115.0f / 255.0f, 1.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
worldRenderer.render();
}
}
回答8:
In my case, it was a null pointer exception inside an onDraw event that prevent the draw to be completed on the canvas. I think is a general error message given when a draw problem ocurr.
回答9:
I too had this error when using Libgdx for android, and I found out this error is
caused by Box2d which uses native code, it is better to look at part of your code which uses Box2d and see if there is any null pointers.
回答10:
In my case the BluetoothSocket
was null when trying to establish a Bluetooth connection