1

我的代码在我正常运行时工作正常,但是当我运行此单元测试时,此错误会打印在控制台中。我在这个单元测试中做错了什么?

测试运行失败:由于“进程崩溃”,检测运行失败。

日志猫

01-13 03:52:12.560: I/DEBUG(31): *** *** *** *** *** *** *** *** *** *** *** *** *** 

*** *** ***
01-13 03:52:12.560: I/DEBUG(31): Build fingerprint: 'generic/sdk/generic/:2.2/FRF91/43546:eng/test-keys'
01-13 03:52:12.560: I/DEBUG(31): pid: 446, tid: 452  >>> com.frozendragon.Sceptrum <<<
01-13 03:52:12.560: I/DEBUG(31): signal 11 (SIGSEGV), fault addr 00000028
01-13 03:52:12.560: I/DEBUG(31):  r0 00000000  r1 0026148c  r2 00000000  r3 0026148c
01-13 03:52:12.560: I/DEBUG(31):  r4 00260bd8  r5 002614cc  r6 00000000  r7 00000000
01-13 03:52:12.560: I/DEBUG(31):  r8 00000001  r9 00000000  10 00000000  fp 00000000
01-13 03:52:12.560: I/DEBUG(31):  ip 00000000  sp 485c1b38  lr 00000000  pc ab166044  cpsr 60000010
01-13 03:52:12.606: I/DEBUG(31):          #00  pc 00066044  /system/lib/libskia.so
01-13 03:52:12.606: I/DEBUG(31):          #01  pc 00068bb4  /system/lib/libskia.so
01-13 03:52:12.606: I/DEBUG(31):          #02  pc 00064e68  /system/lib/libskia.so
01-13 03:52:12.606: I/DEBUG(31):          #03  pc 0004b1ea  /system/lib/libandroid_runtime.so
01-13 03:52:12.606: I/DEBUG(31):          #04  pc 00013974  /system/lib/libdvm.so
01-13 03:52:12.606: I/DEBUG(31):          #05  pc 0003ddb4  /system/lib/libdvm.so
01-13 03:52:12.606: I/DEBUG(31):          #06  pc 00037186  /system/lib/libdvm.so
01-13 03:52:12.606: I/DEBUG(31):          #07  pc 00018714  /system/lib/libdvm.so
01-13 03:52:12.616: I/DEBUG(31):          #08  pc 0001e8c4  /system/lib/libdvm.so
01-13 03:52:12.616: I/DEBUG(31):          #09  pc 0001d790  /system/lib/libdvm.so
01-13 03:52:12.616: I/DEBUG(31):          #10  pc 0005408e  /system/lib/libdvm.so
01-13 03:52:12.616: I/DEBUG(31):          #11  pc 0005bde2  /system/lib/libdvm.so
01-13 03:52:12.616: I/DEBUG(31):          #12  pc 00018714  /system/lib/libdvm.so
01-13 03:52:12.616: I/DEBUG(31):          #13  pc 0001e8c4  /system/lib/libdvm.so
01-13 03:52:12.616: I/DEBUG(31):          #14  pc 0001d790  /system/lib/libdvm.so
01-13 03:52:12.616: I/DEBUG(31):          #15  pc 00053eec  /system/lib/libdvm.so
01-13 03:52:12.616: I/DEBUG(31):          #16  pc 00054102  /system/lib/libdvm.so
01-13 03:52:12.626: I/DEBUG(31):          #17  pc 0004825a  /system/lib/libdvm.so
01-13 03:52:12.626: I/DEBUG(31):          #18  pc 0001103c  /system/lib/libc.so
01-13 03:52:12.626: I/DEBUG(31):          #19  pc 00010b20  /system/lib/libc.so
01-13 03:52:12.626: I/DEBUG(31): code around pc:
01-13 03:52:12.626: I/DEBUG(31): ab166024 e59d001c e3a01000 e5c010a8 eaffff95 
01-13 03:52:12.626: I/DEBUG(31): ab166034 e1d4e2f4 e1d472f6 e5946004 e197200e 
01-13 03:52:12.626: I/DEBUG(31): ab166044 e5969028 e596a024 0a00002e e59db00c 
01-13 03:52:12.626: I/DEBUG(31): ab166054 e2848028 e1a0c008 e8bb000f e8ac000f 
01-13 03:52:12.626: I/DEBUG(31): ab166064 e8bb000f e8ac000f e89b0003 e26eb000 
01-13 03:52:12.626: I/DEBUG(31): code around lr:
01-13 03:52:12.626: I/DEBUG(31): stack:
01-13 03:52:12.626: I/DEBUG(31):     485c1af8  43480000  /data/dalvik-cache/system@framework@framework.jar@classes.dex
01-13 03:52:12.626: I/DEBUG(31):     485c1afc  002613c8  [heap]
01-13 03:52:12.626: I/DEBUG(31):     485c1b00  485c1be8  
01-13 03:52:12.626: I/DEBUG(31):     485c1b04  00261020  [heap]
01-13 03:52:12.626: I/DEBUG(31):     485c1b08  485c1be8  
01-13 03:52:12.626: I/DEBUG(31):     485c1b0c  ab165be8  /system/lib/libskia.so
01-13 03:52:12.626: I/DEBUG(31):     485c1b10  00000001  
01-13 03:52:12.636: I/DEBUG(31):     485c1b14  00000007  
01-13 03:52:12.636: I/DEBUG(31):     485c1b18  420d1a98  /dev/ashmem/dalvik-LinearAlloc (deleted)
01-13 03:52:12.636: I/DEBUG(31):     485c1b1c  80846dad  /system/lib/libdvm.so
01-13 03:52:12.636: I/DEBUG(31):     485c1b20  00000024  
01-13 03:52:12.636: I/DEBUG(31):     485c1b24  00231b78  [heap]
01-13 03:52:12.636: I/DEBUG(31):     485c1b28  46002d90  /dev/ashmem/mspace/dalvik-heap/2 (deleted)
01-13 03:52:12.636: I/DEBUG(31):     485c1b2c  8083d9b9  /system/lib/libdvm.so
01-13 03:52:12.636: I/DEBUG(31):     485c1b30  df002777  
01-13 03:52:12.636: I/DEBUG(31):     485c1b34  e3a070ad  
01-13 03:52:12.636: I/DEBUG(31): #00 485c1b38  46002d90  /dev/ashmem/mspace/dalvik-heap/2 (deleted)
01-13 03:52:12.636: I/DEBUG(31):     485c1b3c  8082e5b3  /system/lib/libdvm.so
01-13 03:52:12.636: I/DEBUG(31):     485c1b40  00000000  
01-13 03:52:12.636: I/DEBUG(31):     485c1b44  002614a4  [heap]
01-13 03:52:12.636: I/DEBUG(31):     485c1b48  00004000  
01-13 03:52:12.636: I/DEBUG(31):     485c1b4c  ffffffff  
01-13 03:52:12.636: I/DEBUG(31):     485c1b50  00000000  
01-13 03:52:12.636: I/DEBUG(31):     485c1b54  00261020  [heap]
01-13 03:52:12.636: I/DEBUG(31):     485c1b58  485c1be8  
01-13 03:52:12.636: I/DEBUG(31):     485c1b5c  002316e8  [heap]
01-13 03:52:12.636: I/DEBUG(31):     485c1b60  46002d90  /dev/ashmem/mspace/dalvik-heap/2 (deleted)
01-13 03:52:12.636: I/DEBUG(31):     485c1b64  ad32e451  /system/lib/libandroid_runtime.so
01-13 03:52:12.636: I/DEBUG(31):     485c1b68  ad374d50  /system/lib/libandroid_runtime.so
01-13 03:52:12.636: I/DEBUG(31):     485c1b6c  ad34bf0f  /system/lib/libandroid_runtime.so
01-13 03:52:12.636: I/DEBUG(31):     485c1b70  485c1f00  
01-13 03:52:12.636: I/DEBUG(31):     485c1b74  485c1be8  
01-13 03:52:12.646: I/DEBUG(31):     485c1b78  00261020  [heap]
01-13 03:52:12.646: I/DEBUG(31):     485c1b7c  ab165b68  /system/lib/libskia.so
01-13 03:52:12.646: I/DEBUG(31):     485c1b80  485c1be8  
01-13 03:52:12.646: I/DEBUG(31):     485c1b84  485c1c0c  
01-13 03:52:12.646: I/DEBUG(31):     485c1b88  485c1bb0  
01-13 03:52:12.646: I/DEBUG(31):     485c1b8c  00261020  [heap]
01-13 03:52:12.646: I/DEBUG(31):     485c1b90  00000000  
01-13 03:52:12.646: I/DEBUG(31):     485c1b94  00000001  
01-13 03:52:12.646: I/DEBUG(31):     485c1b98  00000000  
01-13 03:52:12.646: I/DEBUG(31):     485c1b9c  00000000  
01-13 03:52:12.646: I/DEBUG(31):     485c1ba0  00000000  
01-13 03:52:12.646: I/DEBUG(31):     485c1ba4  ab168bb8  /system/lib/libskia.so
01-13 03:52:12.646: I/DEBUG(31): #01 485c1ba8  00000000  
01-13 03:52:12.646: I/DEBUG(31):     485c1bac  00000000  
01-13 03:52:12.646: I/DEBUG(31):     485c1bb0  000013fc  
01-13 03:52:12.646: I/DEBUG(31):     485c1bb4  000001b8  
01-13 03:52:12.646: I/DEBUG(31):     485c1bb8  485c1c68  
01-13 03:52:12.646: I/DEBUG(31):     485c1bbc  00000000  
01-13 03:52:12.646: I/DEBUG(31):     485c1bc0  00000000  
01-13 03:52:12.646: I/DEBUG(31):     485c1bc4  00000000  
01-13 03:52:12.646: I/DEBUG(31):     485c1bc8  00261020  [heap]
01-13 03:52:12.646: I/DEBUG(31):     485c1bcc  433f6c68  /data/dalvik-cache/system@framework@framework.jar@classes.dex
01-13 03:52:12.646: I/DEBUG(31):     485c1bd0  8086caa4  /system/lib/libdvm.so
01-13 03:52:12.646: I/DEBUG(31):     485c1bd4  80870eea  /system/lib/libdvm.so
01-13 03:52:12.646: I/DEBUG(31):     485c1bd8  000013fc  
01-13 03:52:12.646: I/DEBUG(31):     485c1bdc  80887fc4  /system/lib/libdvm.so
01-13 03:52:12.646: I/DEBUG(31):     485c1be0  485c1f00  
01-13 03:52:12.656: I/DEBUG(31):     485c1be4  485c1c0c  
01-13 03:52:12.656: I/DEBUG(31):     485c1be8  00261020  [heap]
01-13 03:52:12.656: I/DEBUG(31):     485c1bec  00000003  
01-13 03:52:12.656: I/DEBUG(31):     485c1bf0  00000000  
01-13 03:52:12.656: I/DEBUG(31):     485c1bf4  485c1c68  
01-13 03:52:12.656: I/DEBUG(31):     485c1bf8  43957d20  
01-13 03:52:12.656: I/DEBUG(31):     485c1bfc  43957d0c  
01-13 03:52:12.656: I/DEBUG(31):     485c1c00  00231b78  [heap]
01-13 03:52:12.656: I/DEBUG(31):     485c1c04  ab164e6c  /system/lib/libskia.so
01-13 03:52:13.006: I/BootReceiver(73): Copying /data/tombstones/tombstone_07 to DropBox (SYSTEM_TOMBSTONE)
01-13 03:52:13.026: D/Zygote(33): Process 446 terminated by signal (11)
01-13 03:52:13.076: D/dalvikvm(73): GC_FOR_MALLOC freed 4012 objects / 829984 bytes in 66ms
01-13 03:52:13.076: I/ActivityManager(73): Process com.frozendragon.Sceptrum (pid 446) has died.
01-13 03:52:13.076: W/ActivityManager(73): Crash of app com.frozendragon.Sceptrum running instrumentation ComponentInfo{com.frozendragon.Sceptrum.test/android.test.InstrumentationTestRunner}
01-13 03:52:13.076: I/ActivityManager(73): Force stopping package com.frozendragon.Sceptrum uid=10028
01-13 03:52:13.087: D/AndroidRuntime(440): Shutting down VM
01-13 03:52:13.087: D/jdwp(440): Got wake-up signal, bailing out of select
01-13 03:52:13.087: D/dalvikvm(440): Debugger has detached; object registry had 1 entries
01-13 03:54:28.720: D/SntpClient(73): request time failed: java.net.SocketException: Address family not supported by protocol

单元测试代码

Point ImagesPos, SheetSize, CurrentSprite, Size;
    protected void setUp() throws Exception {
        super.setUp();
        gameEngine = new GameEngine(400, 800);
        canvas = new Canvas();
        ImagesPos = new Point(200, 200);
        SheetSize = new Point(9, 9);
        CurrentSprite = new Point(2, 3);
        Size = new Point(200, 400);
        Context context = getContext();
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inScaled = true;
        animationbmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.foot_animation_spritesheet9x9, options);
    }
    public void testDrawAnimationObjectCanvasBitmapIntIntPointPointFloat() {
        float rot = 45f;
        gameEngine.DrawAnimationObject(canvas, animationbmp, ImagesPos.x, ImagesPos.y, SheetSize, CurrentSprite, rot);
        animationbmp.recycle();
        gameEngine.DrawAnimationObject(canvas, animationbmp, ImagesPos.x, ImagesPos.y, SheetSize, CurrentSprite, rot);
        restorebmp();
    }
private void restorebmp()
{
    if(animationbmp.isRecycled() == false)
    {
        animationbmp.recycle();
    }
    Context context = getContext();
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = true;
    animationbmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.foot_animation_spritesheet9x9, options);
}
4

2 回答 2

2

看来您的代码正在回收位图,然后立即尝试再次使用它:

    gameEngine.DrawAnimationObject(canvas, animationbmp, ImagesPos.x, ImagesPos.y, SheetSize, CurrentSprite, rot);
    //////////////////////////////////////////////
    animationbmp.recycle(); //Offending line here/
    //////////////////////////////////////////////
    gameEngine.DrawAnimationObject(canvas, animationbmp, ImagesPos.x, ImagesPos.y, SheetSize, CurrentSprite, rot);

您不应该在回收后使用位图。您需要再次重新创建该位图对象,因为内存现在无效。

于 2013-01-21T20:38:45.853 回答
1

您调用的 C++ 库因尝试取消引用内存地址 0x00...28 而崩溃。看起来像 libskia.so,它是 android 处理图形子系统的一部分。该内存地址意味着它可能正在查看数组中的第 N 个项目,但该数组为空。我会寻找一个传递给绘图调用的空指针,或者对 libskia 错误进行一些严肃的谷歌搜索。恐怕我无能为力,但这是一个开始。

于 2013-01-13T03:31:13.603 回答