Why “CCTextureCache+CCBigImageExtensions” isn't linked in my Kobold2D project?

妖精的绣舞 提交于 2019-12-12 03:42:07

问题


I am using CCBigImage in an iOS/Kobold2d project as the sprite would be too big to be loaded at once. Unfortunately when executing the application it stops with

ERROR: Uncaught exception -[CCTextureCache
addImageFromAnotherThreadWithName:target:selector:]: unrecognized
selector sent to instance 0xa17d010

when loading the plist file into CCBigImage. I nailed it down to the point that

CCBigImage* bg = [CCBigImage nodeWithTilesFile:@"bg1dot5.plist" tilesExtension: @"pvr.ccz" tilesZ: 0]

calls CCBigImage load(). This method calls

[CCTextureCache sharedTextureCache] addImageFromAnotherThreadWithName: _imageName
                                                               target: self
                                                             selector: @selector(loadedTexture:)

that finally leads to the specified exception. I imported "CCTextureCache+CCBigImageExtensions.h" into the source file that loads the CCBigImage so I expected the given selector to be added to CCTextureCache but obviously it is not.

I am using Kobold2d 1.1.0 and XCode 4.3.3 (so all latest versions). Is there something else I need to do in order to have that selector being included?

I also called

[[CCTextureCache sharedTextureCache] addImageFromAnotherThreadWithName:@"" target:nil selector:nil];

directly, the project compiles fine as I included the extension header file but the same exception occures as when I load a CCBigImage.


回答1:


Static libraries containing Objective-C categories must be force-linked with iOS apps (Mac apps don't have this problem) otherwise the category methods can not be resolved and you get the error you described. More info here.

It is not recommended to use the -all_load flag, particularly in Kobold2D. This would blindly link all available code to the app, even the code you're not using in your app. It basically makes the linker blind and stupid and the app size grows possibly by several megabytes.

I will add the force-link of the cocos2d extensions in future Kobold2D versions. For now the fix is to edit the FrameworksAndLibraries.xcconfig file, in Xcode in the Kobold2D-Libraries project in the BuildSettings group.

Locate the section where frameworks/libraries are force-loaded:

LINK_WITH_ADMOB = $(KKLIBROOT)/GoogleAdMobAdsSDK/libGoogleAdMobAds.a
FORCE_LOAD_COCOS2D = -force_load "$(BUILT_PRODUCTS_DIR)/libcocos2d-ios.a"
FORCE_LOAD_KOBOLD2D = -force_load "$(BUILT_PRODUCTS_DIR)/libkobold2d-ios.a"
FORCE_LOAD_KOBOLDSCRIPT = -force_load "$(BUILT_PRODUCTS_DIR)/libkoboldscript-ios.a"
FORCE_LOAD_KOBOLDSCRIPTWRAPPER = -force_load "$(BUILT_PRODUCTS_DIR)/libkoboldscriptwrapper-ios.a"
FORCE_LOAD_ISIMULATE = -force_load "$(KKLIBROOT)/iSimulateSDK/libisimulate-4.x-opengl.a"
FORCE_LOAD_COCOS3D = -force_load "$(BUILT_PRODUCTS_DIR)/libcocos3d-ios.a"

KKFW_IOS = $(KKFW_SysConfig) $(KKFW_AVFoundation) $(KKFW_CoreGraphics) $(KKFW_CoreLocation) $(KKFW_MediaPlayer) $(KKFW_OpenGLES) $(LINK_WITH_ADMOB) $(FORCE_LOAD_KOBOLD2D) $(FORCE_LOAD_KOBOLDSCRIPT) $(FORCE_LOAD_KOBOLDSCRIPTWRAPPER) $(FORCE_LOAD_COCOS2D) 

Now add another FORCE_LOAD_… entry before the "KKFW_IOS = …" line to -force_load the cocos2d-extensions library (this is all in one line, I just added the line break for readability):

FORCE_LOAD_COCOS2D_EXTENSIONS = 
           -force_load "$(BUILT_PRODUCTS_DIR)/libcocos2d-extensions-ios.a"

Then append this new FORCE_LOAD_COCOS2D_EXTENSIONS entry at the end of the "KKFW_IOS = …" line (abbreviated for readability):

KKFW_IOS = $(KKFW_SysConfig) … $(FORCE_LOAD_COCOS2D_EXTENSIONS)

This should resolve the issue and you should now be able to use the CCBigImage category methods.



来源:https://stackoverflow.com/questions/11163759/why-cctexturecacheccbigimageextensions-isnt-linked-in-my-kobold2d-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!