Android crash on create array of int (Solved)


#1

I try to use AWTextureFilter (attached to topic) and got a crash with log:

D/cocos2d-x debug info( 1048): AWTextureFilter::blurInput - kernel size: 33
F/libc ( 1048): Fatal signal 11 (SIGSEGV) at 0xa9ea2fc8 (code=1), thread 1061 (Thread-75)
I/DEBUG ( 47): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG ( 47): Build fingerprint: 'generic/sdk/generic:4.4/KRT16L/892118:eng/test-keys’
I/DEBUG ( 47): Revision: '0’
I/DEBUG ( 47): pid: 1048, tid: 1061, name: Thread-75 >>> com.my.game <<<
I/DEBUG ( 47): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr a9ea2fc8
I/DEBUG ( 47): r0 00000000 r1 00000001 r2 00000001 r3 a9ea2fc8
I/DEBUG ( 47): r4 00000000 r5 a9d41008 r6 00000000 r7 00000010
I/DEBUG ( 47): r8 ab4beac4 r9 ab988f00 sl b77b5418 fp ab4beadc
I/DEBUG ( 47): ip 43a00000 sp ab4be888 lr ab861a78 pc ab605e1a cpsr 00000030
I/DEBUG ( 47): d0 3e93f7b1c0000000 d1 3fdffffec084e400
I/DEBUG ( 47): d2 3fe0000000000000 d3 0000000000000000
I/DEBUG ( 47): d4 4024000000000000 d5 4074000000000000
I/DEBUG ( 47): d6 3fe000009fbd8e00 d7 3e5312d000000000
I/DEBUG ( 47): d8 0000000000000000 d9 0000000000000000
I/DEBUG ( 47): d10 0000000000000000 d11 0000000000000000
I/DEBUG ( 47): d12 0000000000000000 d13 0000000000000000
I/DEBUG ( 47): d14 0000000000000000 d15 0000000000000000
I/DEBUG ( 47): scr 20000010
I/DEBUG ( 47):
I/DEBUG ( 47): backtrace:

I/DEBUG ( 47): #00 pc 00146e1a /data/app-lib/com.my.game-1/libcocos2dcpp.so (AWTextureFilter::blurInput(void, void, cocos2d::CCTexture2DPixelFormat, int, int, cocos2d::CCSize, int, cocos2d::CCRect)+465)
I/DEBUG ( 47): #01 pc 00147203 /data/app-lib/com.my.game-1/libcocos2dcpp.so (AWTextureFilter::blur(cocos2d::CCTexture2DMutable*, int, cocos2d::CCRect)+110)
I/DEBUG ( 47): #02 pc 00145283 /data/app-lib/com.my.game-1/libcocos2dcpp.so (MainMenu::createBlurredScreenTexture()+378)**

I/DEBUG ( 47):
I/DEBUG ( 47): stack:
I/DEBUG ( 47): ab4be848 00000000
I/DEBUG ( 47): ab4be84c 00000000
I/DEBUG ( 47): ab4be850 00000010
I/DEBUG ( 47): ab4be854 ab4beac4 [stack:1061]
I/DEBUG ( 47): ab4be858 ab988f00
I/DEBUG ( 47): ab4be85c b77b5418 [heap]
I/DEBUG ( 47): ab4be860 ab4beadc [stack:1061]
I/DEBUG ( 47): ab4be864 b6e9dae9 /system/lib/libc.so (malloc+12)
I/DEBUG ( 47): ab4be868 00000001
I/DEBUG ( 47): ab4be86c 00000000
I/DEBUG ( 47): ab4be870 43a00000
I/DEBUG ( 47): ab4be874 00000000
I/DEBUG ( 47): ab4be878 00000000

I/DEBUG ( 47): ab4be87c ab861aa0 /data/app-lib/com.my.game-1/libcocos2dcpp.so (__aeabi_fcmplt+8)
I/DEBUG ( 47): ab4be880 ab605df9 /data/app-lib/com.my.game-1/libcocos2dcpp.so (AWTextureFilter::blurInput(void
, void
, cocos2d::CCTexture2DPixelFormat, int, int, cocos2d::CCSize, int, cocos2d::CCRect)+432)
I/DEBUG ( 47): ab4be884 ab605db9 /data/app-lib/com.my.game-1/libcocos2dcpp.so (AWTextureFilter::blurInput(void*, void*, cocos2d::CCTexture2DPixelFormat, int, int, cocos2d::CCSize, int, cocos2d::CCRect)+368)**

I/DEBUG ( 47): #00 ab4be888 00000000
I/DEBUG ( 47): ab4be88c 00000000
I/DEBUG ( 47): ab4be890 43a00000
I/DEBUG ( 47): ab4be894 a9d41008
I/DEBUG ( 47): ab4be898 00000000
I/DEBUG ( 47): ab4be89c 00000000
I/DEBUG ( 47): ab4be8a0 000071a0
I/DEBUG ( 47): ab4be8a4 b77f1558 [heap]
I/DEBUG ( 47): ab4be8a8 a9ea3008
I/DEBUG ( 47): ab4be8ac fffffff0
I/DEBUG ( 47): ab4be8b0 00000021
I/DEBUG ( 47): ab4be8b4 b77c8750 [heap]
I/DEBUG ( 47): ab4be8b8 00000000
I/DEBUG ( 47): ab4be8bc a9ea3008
I/DEBUG ( 47): ab4be8c0 ab4beac4 [stack:1061]
I/DEBUG ( 47): ab4be8c4 b6ea111f /system/lib/libc.so (dlfree+50)
I/DEBUG ( 47): … …
I/DEBUG ( 47): #01 ab4be908 00000140
I/DEBUG ( 47): ab4be90c 000000bc
I/DEBUG ( 47): ab4be910 ab4be940 [stack:1061]
I/DEBUG ( 47): ab4be914 00000010
I/DEBUG ( 47): ab4be918 ab4be948 [stack:1061]
I/DEBUG ( 47): ab4be91c 000014b0
I/DEBUG ( 47): ab4be920 b77f1e60 [heap]
I/DEBUG ( 47): ab4be924 a9ea3008
I/DEBUG ( 47): ab4be928 a9ea3008
I/DEBUG ( 47): ab4be92c 00000000
I/DEBUG ( 47): ab4be930 00000140
I/DEBUG ( 47): ab4be934 000000bc
I/DEBUG ( 47): ab4be938 00000010
I/DEBUG ( 47): ab4be93c ab4be9a8 [stack:1061]
I/DEBUG ( 47): ab4be940 43a00000
I/DEBUG ( 47): ab4be944 433c0000
I/DEBUG ( 47): … …
I/DEBUG ( 47): #02 ab4be970 433c0000
I/DEBUG ( 47): ab4be974 ab4be9a8 [stack:1061]
I/DEBUG ( 47): ab4be978 00000000
I/DEBUG ( 47): ab4be97c 40740000
I/DEBUG ( 47): ab4be980 ab4be9a8 [stack:1061]
I/DEBUG ( 47): ab4be984 b77f1a8c [heap]
I/DEBUG ( 47): ab4be988 b77f1a8c [heap]
I/DEBUG ( 47): ab4be98c b77f1e60 [heap]
I/DEBUG ( 47): ab4be990 00000010
I/DEBUG ( 47): ab4be994 43a00000
I/DEBUG ( 47): ab4be998 a9e2d008
I/DEBUG ( 47): ab4be99c 00000000
I/DEBUG ( 47): ab4be9a0 00000000

I/DEBUG ( 47): ab4be9a4 ab80fb10 /data/app-lib/com.my.game-1/libcocos2dcpp.so (operator new(unsigned int)+24)

I/DEBUG ( 47): ab4be9a8 00000000
I/DEBUG ( 47): ab4be9ac 00000000

I think what error is here, line 45 AWTextureFilter.cpp
//Generate Gaussian kernel
radius = MIN(MAX(1,radius), 248);
int kernelSize = 1+radius2;
CCLOG(“AWTextureFilter::blurInput - kernel size: %d”, kernelSize);
int
kernel = new int[kernelSize];

I searched this error in Google but there is nothing result.
On iOS it works fine. On Android emulator it crashes.


AWTextureFilter.cpp.zip (2.2 KB)


AWTextureFilter.h.zip (1.3 KB)


#2

Can anybody help me? Do I need to link some libs?


#3

Hi,
Could you please provide the missing class (CCTexture2DMutable) so I can test. Did you tried on iOS?
Laurent


#4

OK.
I’m new in C++ and on Android, this Cpp classes aren’t mine.
I test app on Android Emulator (I didn’t have any device) v4.4 and build app with minSdkVersion=“8” and target-19…
I found, that error occurred lately create int array. I’m continuing find a bug.

Code of using AWTextureFilter

    // data is created from CCRenderTexture (with snapshot of base scene node, it's for screenshot) r->newCCImage->getData();
    CCTexture2DMutable* mTex = new CCTexture2DMutable();
    mTex->initWithData(data, tex->getPixelFormat(), width, height, CCSizeMake( width, height));    
    // create filter
    AWTextureFilter *textFilter = new AWTextureFilter();
    CCTexture2DMutable *blurTex = textFilter->blur(mTex, int(0.0125*visibleSize.width), CCRectMake(0, 0, width, height));
    // crash inside this call

#5

I found location of issue. In AWTextureFilter.cpp line
cr+= pixel->r*kernel[i];
I don’t know why it causes crash.

EDIT
Read operation from pixel crashes.

EDIT 2
originalData is not empty, but pixel - does.
It seems like pixel = &originalData[read]; doesn’t work properly.

EDIT 3
I found what index read is below zero on the start of calculations.


#6

I’ve tested on iOS. It does not crash but the texture is black so I’m not sure the blur algorithm woks at all.

    CCImage *image = new CCImage();
    image->initWithImageFile("Icon-114.png");

    CCTexture2DMutable* mTex = new CCTexture2DMutable();
    mTex->initWithImage(image);

    AWTextureFilter *textFilter = new AWTextureFilter();
    CCTexture2DMutable *blurTex = textFilter->blur(mTex, 6);

    layer->addChild(CCSprite::createWithTexture(blurTex));

Note that you have to edit CCTexture2D.h and set the initWithData to virtual

virtual bool initWithData(const void* data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, const CCSize& contentSize);

#7

@laurentzubiaur it’s strange, i have it works on iOS fine. Without edit CCTexture2D.h :;qst
After addition some if-conditions into AWTextureFilter like
if(read >= 0) {...
if(yi+xl >= 0) {...
I have worked blur on Android.
Thanks for help!


#8

You’re welcome!
PS: I meant you had to set CCTexture2D::initWithData virtual if you wanted to use initWithImage like I did in my code above.