Oolite
Loading...
Searching...
No Matches
OOTexture(SubclassInterface) Category Reference

#include <OOTextureInternal.h>

Instance Methods

(void) - addToCaches
 
(void) - removeFromCaches
 

Class Methods

(OOTexture *) + existingTextureForKey:
 

Detailed Description

Definition at line 34 of file OOTextureInternal.h.

Method Documentation

◆ addToCaches

- (void) addToCaches

Extends class OOTexture.

Definition at line 923 of file OOTexture.m.

444{
445#ifndef OOTEXTURE_NO_CACHE
446 NSString *cacheKey = [self cacheKey];
447 if (cacheKey == nil) return;
448
449 // Add self to in-use textures cache, wrapped in an NSValue so the texture isn't retained by the cache.
450 if (EXPECT_NOT(sLiveTextureCache == nil)) sLiveTextureCache = [[NSMutableDictionary alloc] init];
451
452 SET_TRACE_CONTEXT(@"in-use textures cache - SHOULD NOT RETAIN");
453 [sLiveTextureCache setObject:[NSValue valueWithPointer:self] forKey:cacheKey];
455
456 // Add self to recent textures cache.
458 {
459 sRecentTextures = [[OOCache alloc] init];
460 [sRecentTextures setName:@"recent textures"];
461 [sRecentTextures setAutoPrune:YES];
462 [sRecentTextures setPruneThreshold:kRecentTexturesCount];
463 }
464
465 SET_TRACE_CONTEXT(@"adding to recent textures cache");
466 [sRecentTextures setObject:self forKey:cacheKey];
468#endif
469}
#define EXPECT_NOT(x)
return nil
#define CLEAR_TRACE_CONTEXT()
Definition OOTexture.m:129
#define SET_TRACE_CONTEXT(str)
Definition OOTexture.m:125
static OOCache * sRecentTextures
Definition OOTexture.m:97
static NSMutableDictionary * sLiveTextureCache
Definition OOTexture.m:95

◆ existingTextureForKey:

+ (OOTexture *) existingTextureForKey: (NSString *)  key

Extends class OOTexture.

◆ removeFromCaches

- (void) removeFromCaches

Extends class OOTexture.

Definition at line 923 of file OOTexture.m.

473{
474#ifndef OOTEXTURE_NO_CACHE
475 NSString *cacheKey = [self cacheKey];
476 if (cacheKey == nil) return;
477
478 [sLiveTextureCache removeObjectForKey:cacheKey];
479 if (EXPECT_NOT([sRecentTextures objectForKey:cacheKey] == self))
480 {
481 /* Experimental for now: I think the recent crash problems may
482 * be because if the last reference to a texture is in
483 * sRecentTextures, and the texture is regenerated, it
484 * replaces the texture, causing a release. Therefore, if this
485 * texture *isn't* overretained in the texture cache, the 2009
486 * crash avoider will delete its replacement from the cache
487 * ... possibly before that texture has been fully added to
488 * the cache itself. So, the texture is only removed from the
489 * cache by key if it was in it with that key. The extra time
490 * needed to generate a planet texture compared with loading a
491 * standard one may be why this problem shows up. - CIM 20140122
492 */
493 NSAssert2(0, @"Texture retain count error for %@; cacheKey is %@.", self, cacheKey); //miscount in autorelease
494 // The following line is needed in order to avoid crashes when there's a 'texture retain count error'. Please do not delete. -- Kaks 20091221
495 [sRecentTextures removeObjectForKey:cacheKey]; // make sure there's no reference left inside sRecentTexture ( was a show stopper for 1.73)
496 }
497#endif
498}
return self

The documentation for this category was generated from the following file: