Skip to content

Commit

Permalink
clear NSImage cache after screen resolution change
Browse files Browse the repository at this point in the history
  • Loading branch information
onflapp committed Dec 30, 2023
1 parent 3f9b3b7 commit 2b6a26b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Source/NSImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ - (void) dealloc
@interface NSImage (Private)
+ (void) _clearFileTypeCaches: (NSNotification*)notif;
+ (void) _reloadCachedImages;
- (void) _clearRepCaches: (NSNotification*)notif;
- (BOOL) _useFromFile: (NSString *)fileName;
- (BOOL) _loadFromData: (NSData *)data;
- (BOOL) _loadFromFile: (NSString *)fileName;
Expand Down Expand Up @@ -456,6 +457,7 @@ + (void) initialize
selector: @selector(_clearFileTypeCaches:)
name: NSImageRepRegistryChangedNotification
object: [NSImageRep class]];

[imageLock unlock];
}
}
Expand Down Expand Up @@ -535,6 +537,12 @@ - (id) initWithSize: (NSSize)aSize
ASSIGN(_color, clearColor);
_cacheMode = NSImageCacheDefault;

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(_clearRepCaches:)
name:NSApplicationDidChangeScreenParametersNotification
object:nil];

return self;
}

Expand Down Expand Up @@ -670,6 +678,7 @@ - (id) initWithPasteboard: (NSPasteboard *)pasteboard

- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
if (_name == nil)
{
RELEASE(_reps);
Expand Down Expand Up @@ -2280,6 +2289,11 @@ + (NSString *) _resourceNameForImageNamed: (NSString *)aName
return name;
}

- (void) _clearRepCaches: (NSNotification*)notif
{
NSDebugLLog(@"NSImage", @"Screen size has changed");
[self recache];
}
- (BOOL) _loadFromData: (NSData *)data
{
BOOL ok;
Expand Down

0 comments on commit 2b6a26b

Please sign in to comment.