Oolite 1.91.0.7645-241119-222d325
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 924 of file OOTexture.m.

445{
446#ifndef OOTEXTURE_NO_CACHE
447 NSString *cacheKey = [self cacheKey];
448 if (cacheKey == nil) return;
449
450 // Add self to in-use textures cache, wrapped in an NSValue so the texture isn't retained by the cache.
451 if (EXPECT_NOT(sLiveTextureCache == nil)) sLiveTextureCache = [[NSMutableDictionary alloc] init];
452
453 SET_TRACE_CONTEXT(@"in-use textures cache - SHOULD NOT RETAIN");
454 [sLiveTextureCache setObject:[NSValue valueWithPointer:self] forKey:cacheKey];
456
457 // Add self to recent textures cache.
459 {
460 sRecentTextures = [[OOCache alloc] init];
461 [sRecentTextures setName:@"recent textures"];
462 [sRecentTextures setAutoPrune:YES];
463 [sRecentTextures setPruneThreshold:kRecentTexturesCount];
464 }
465
466 SET_TRACE_CONTEXT(@"adding to recent textures cache");
467 [sRecentTextures setObject:self forKey:cacheKey];
469#endif
470}
#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 924 of file OOTexture.m.

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

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