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 35 of file OOTextureInternal.h.

Method Documentation

◆ addToCaches

- (void) addToCaches

Extends class OOTexture.

Definition at line 412 of file OOTexture.m.

413{
414#ifndef OOTEXTURE_NO_CACHE
415 NSString* cacheKey = [self cacheKey];
416 if (cacheKey == nil)
417 return;
418
419 // Add self to in-use textures cache, wrapped in an NSValue so the texture isn't retained by the cache.
421 sLiveTextureCache = [[NSMutableDictionary alloc] init];
422
423 SET_TRACE_CONTEXT(@"in-use textures cache - SHOULD NOT RETAIN");
424 [sLiveTextureCache setObject:[NSValue valueWithPointer:self] forKey:cacheKey];
426
427 // Add self to recent textures cache.
429 sRecentTextures = [[OOCache alloc] init];
430 [sRecentTextures setName:@"recent textures"];
432 [sRecentTextures setPruneThreshold:kRecentTexturesCount];
433 }
434
435 SET_TRACE_CONTEXT(@"adding to recent textures cache");
436 [sRecentTextures setObject:self forKey:cacheKey];
438#endif
439}
#define EXPECT_NOT(x)
return nil
#define CLEAR_TRACE_CONTEXT()
Definition OOTexture.m:128
#define SET_TRACE_CONTEXT(str)
Definition OOTexture.m:124
static OOCache * sRecentTextures
Definition OOTexture.m:94
static NSMutableDictionary * sLiveTextureCache
Definition OOTexture.m:92
void setPruneThreshold:(unsigned threshold)
Definition OOCache.m:279
void setName:(NSString *name)
Definition OOCache.m:350
void setAutoPrune:(BOOL flag)
Definition OOCache.m:294
void setObject:forKey:(id value,[forKey] id key)
Definition OOCache.m:256

Referenced by OOConcreteTexture::initWithLoader:key:options:anisotropy:lodBias:.

Here is the caller graph for this function:

◆ existingTextureForKey:

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

Extends class OOTexture.

◆ removeFromCaches

- (void) removeFromCaches

Extends class OOTexture.

Definition at line 441 of file OOTexture.m.

442{
443#ifndef OOTEXTURE_NO_CACHE
444 NSString* cacheKey = [self cacheKey];
445 if (cacheKey == nil)
446 return;
447
448 [sLiveTextureCache removeObjectForKey:cacheKey];
449 if (EXPECT_NOT([sRecentTextures objectForKey:cacheKey] == self)) {
450 /* Experimental for now: I think the recent crash problems may
451 * be because if the last reference to a texture is in
452 * sRecentTextures, and the texture is regenerated, it
453 * replaces the texture, causing a release. Therefore, if this
454 * texture *isn't* overretained in the texture cache, the 2009
455 * crash avoider will delete its replacement from the cache
456 * ... possibly before that texture has been fully added to
457 * the cache itself. So, the texture is only removed from the
458 * cache by key if it was in it with that key. The extra time
459 * needed to generate a planet texture compared with loading a
460 * standard one may be why this problem shows up. - CIM 20140122
461 */
462 NSAssert2(0, @"Texture retain count error for %@; cacheKey is %@.", self, cacheKey); // miscount in autorelease
463 // The following line is needed in order to avoid crashes when there's a 'texture retain count error'. Please do not delete. -- Kaks 20091221
464 [sRecentTextures removeObjectForKey:cacheKey]; // make sure there's no reference left inside sRecentTexture ( was a show stopper for 1.73)
465 }
466#endif
467}
void removeObjectForKey:(id key)
Definition OOCache.m:269

References OOTexture::cacheKey, EXPECT_NOT, nil, removeFromCaches, OOCache::removeObjectForKey:, and sRecentTextures.

Referenced by OOConcreteTexture::dealloc, and removeFromCaches.

Here is the call graph for this function:
Here is the caller graph for this function:

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