Assert Error on creating a CCSprite using CCSprite::createWithSpriteFrameName() ?


#1

I have a CCDictionary object which contains three keys (id , img , selected image).

Dictionary definition in plist is as

<dict> <key>id</key> <integer>131</integer> <key>img</key> <string>"menu_play.png"</string> <key>img_sel</key> <string>"menu_play.png"</string> </dict>

In code I am accessing it as follows and I am getting an Assert Error :

CCDictionary *dict = (CCDictionary *) iMenuArr->objectAtIndex(i); const CCString *select = (CCString *) dict->valueForKey("id"); const CCString *image = dict->valueForKey("img"); const CCString *image_sel = dict->valueForKey("img_sel");

// Till here everything is ok , The CCLog below prints the correct value above for all keys.

CCLog(“PList details are s s %d”, image~~>getCString, image_sel~~>getCString(), select->intValue());

// But when I am using above CCString to create Sprites as follows:

@ CCSprite* normalSprite = CCSprite::createWithSpriteFrameName(image->getCString());
CCSprite* selectedSprite = CCSprite::createWithSpriteFrameName(image_sel->getCString());@

// It gives Assert error on run for function *createWithSpriteFrameName()*

Any help ?


#2

CCSprite* normalSprite = CCSprite::create(image->getCString());
CCSprite* selectedSprite = CCSprite::create(image_sel->getCString());


#3

I have loaded all CCSpriteFrames in CCSpriteFrameCache.

That’s why I am accessing CCSprite using CCSpriteFrameByName().

Also I am receiving Error in LogCat as :

@
E/memalloc(6021): /dev/pmem: Failed to map buffer size:92028928 offset:90308608 fd:199 Error: Out of memory
E/msm8660.gralloc(6021): Could not mmap handle 0xa39fd0, fd=199 (Out of memory)
E/msm8660.gralloc(6021): gralloc_register_buffer: gralloc_map failed
W/GraphicBufferMapper(6021): registerBuffer(0xa39fd0) failed 12
E/memalloc: /dev/pmem: Failed to map buffer size:92028928 offset:90308608 fd:199 Error: Out of memory
E/msm8660.gralloc: Could not mmap handle 0xa39fd0, fd=199
E/libgenlock: perform_lock_unlock_operation: GENLOCK_IOC_LOCK failed
E/msm8660.gralloc: gralloc_lock: genlock_lock_buffer failed
W/GraphicBufferMapper: lock failed
22 (Invalid argument)
E/SurfaceTextureClient(6021): error locking dst buffer Invalid argument
E/memalloc(6021): /dev/pmem: Failed to map buffer size:92028928 offset:90308608 fd:199 Error: Out of memory
E/msm8660.gralloc(6021): Could not mmap handle 0xa39fd0, fd=199 (Out of memory)
E/libgenlock(6021): perform_lock_unlock_operation: GENLOCK_IOC_LOCK failed (lockType0x1, err=Connection timed out fd=199)
E/msm8660.gralloc(6021): gralloc_lock: genlock_lock_buffer (lockType=0x2) failed
W/GraphicBufferMapper(6021): lock(…) failed –22 (Invalid argument)
W/SurfaceTextureClient(6021): failed locking buffer (handle = 0xa39fd0)
IllegalArgumentException locking surface
java.lang.IllegalArgumentException
at android.view.Surface.lockCanvasNative(Native Method)
at android.view.Surface.lockCanvas(Surface.java:76)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:1945)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1634)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
@

Also when I am directly giving their name ( as const char **) , it works Sprite appears
CCSprite* normalSprite = CCSprite::createWithSpriteFrameName("menu_play.png"); CCSprite* selectedSprite = CCSprite::createWithSpriteFrameName("menu_play.png");

I think that may due to parameter being passed to the**createWithSpriteFrameName()* which is a constant pointer to char array.


#4

no quotes at the value of key “img” and “img_sel”

id 131 img menu\_play.png img\_sel menu\_play.png

#5

Problem resolved : The error was occurring due to the change in the data plist (id from dict was removed) and code still trying to access id

So segmentation fault occurred.

Thanks All Of You for your replies.

Hi MingQing Li

That’s not required in my project as those names are referring to the frames in other sprites frame data plist


#6

oh, no! oh, yeah!