{"id":7138,"date":"2014-05-25T20:57:53","date_gmt":"2014-05-25T20:57:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/25\/nsinternalinconsistencyexception-do-not-initialize-the-texturecache-before-the-director-collection-of-common-programming-errors-2\/"},"modified":"2014-05-25T20:57:53","modified_gmt":"2014-05-25T20:57:53","slug":"nsinternalinconsistencyexception-do-not-initialize-the-texturecache-before-the-director-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/25\/nsinternalinconsistencyexception-do-not-initialize-the-texturecache-before-the-director-collection-of-common-programming-errors-2\/","title":{"rendered":"&#39;NSInternalInconsistencyException: Do not initialize the TextureCache before the Director&#39;-Collection of common programming errors"},"content":{"rendered":"<p>To find a solution I have gone thru this similar link: TextureCache Error from Cocos2d when integrated into UIKit App but seems like it is dealing with this error in a different context..<\/p>\n<p><em>Question:<\/em> I have a UIKit project integrated with Cocos2d. When build, succeeds and runs but, at times crashes after <em>receiving a memory warning<\/em> with this error:<\/p>\n<p><strong>Assertion failure in -[CCTextureCache init], \/Users\/MyName\/Documents\/CSProject\/CSProject\/libs\/cocos2d\/CCTextureCache.m:90<\/strong><\/p>\n<p><strong>Terminating app due to uncaught exception &#8216;NSInternalInconsistencyException&#8217;, reason: &#8216;Do not initialize the TextureCache before the Director&#8217;<\/strong><\/p>\n<p>The cocos2d scene is run from the view controller when a button is touched and the code is given below:<\/p>\n<p>In ViewController.m<\/p>\n<pre><code>-(IBAction)overToCocos:(id)sender{\n    CCDirector *director = [CCDirector sharedDirector];\n    CCGLView *glView = [CCGLView viewWithFrame:CGRectMake(-100, -50, 480, 480)\n                                   pixelFormat:kEAGLColorFormatRGBA8\n                                   depthFormat:0];\n    glView.opaque = NO;\n    self.imagePicker.cameraOverlayView.userInteractionEnabled = YES;\n    [self.imagePicker.cameraOverlayView insertSubview:glView atIndex:0];\n    [self.imagePicker.cameraOverlayView bringSubviewToFront:glView];\n    [director setView:glView];\n    [director runWithScene:[HelloWorldLayer scene]];\n}\n<\/code><\/pre>\n<p>Since the crash occurs after receiving a memory warning, I tried this<\/p>\n<pre><code>- (void)didReceiveMemoryWarning\n{\n    [super didReceiveMemoryWarning];\n    \/\/ Dispose of any resources that can be recreated.\n    if ( [ CCDirector sharedDirector ].view != nil ){\n        [[CCTextureCache sharedTextureCache] removeUnusedTextures];\n    }\n\n}\n<\/code><\/pre>\n<p>Also added this to AppDelegate&#8217;s applicationDidReceiveMemoryWarning. But the crash still exists.. Please point me to the right direction to handle this error..<\/p>\n<p>Thanks in advance!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To find a solution I have gone thru this similar link: TextureCache Error from Cocos2d when integrated into UIKit App but seems like it is dealing with this error in a different context.. Question: I have a UIKit project integrated with Cocos2d. When build, succeeds and runs but, at times crashes after receiving a memory [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7138","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7138"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7138\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}