Skip to content

Commit

Permalink
Fix a crash when creating box images. (Probably related to #915 and #877
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cyco committed Dec 30, 2013
1 parent cafe38f commit b6dc687
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions OpenEmu/OEDBGame.m
Original file line number Diff line number Diff line change
Expand Up @@ -386,45 +386,29 @@ - (void)setBoxImageByImage:(NSImage *)img
{
@autoreleasepool
{
OEDBImage *boxImage = [self boxImage];
if(boxImage != nil)
{
NSManagedObjectContext *context = [boxImage managedObjectContext];
[context performBlockAndWait:^{
[context deleteObject:boxImage];
}];
}

if(img == nil) return;

boxImage = [OEDBImage imageWithImage:img inLibrary:[self libraryDatabase]];

NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
NSArray *sizes = [standardDefaults objectForKey:OEBoxSizesKey];
// For each thumbnail size specified in defaults...
for(NSString *aSizeString in sizes)
{
NSSize size = NSSizeFromString(aSizeString);
// ...generate thumbnail
[boxImage generateThumbnailForSize:size];
NSMutableArray *codePath = [NSMutableArray array];
OEDBImage *boxImage = nil;
if(img != nil){
boxImage = [OEDBImage imageWithImage:img inLibrary:[self libraryDatabase]];
NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
NSArray *sizes = [standardDefaults objectForKey:OEBoxSizesKey];
// For each thumbnail size specified in defaults...
for(NSString *aSizeString in sizes)
{
NSSize size = NSSizeFromString(aSizeString);
// ...generate thumbnail
[codePath addObject:[NSString stringWithFormat:@"generateThumbnailForSize: %@", NSStringFromSize(size)]];
[boxImage generateThumbnailForSize:size];
}
}

[codePath addObject:[NSString stringWithFormat:@"set boxImage: %@", boxImage]];
[self setBoxImage:boxImage];
}
}

- (void)setBoxImageByURL:(NSURL *)url
{
OEDBImage *boxImage = [self boxImage];
if(boxImage != nil)
{
NSManagedObjectContext *context = [boxImage managedObjectContext];
[context performBlockAndWait:^{
[context deleteObject:boxImage];
}];
}

boxImage = [OEDBImage imageWithURL:url inLibrary:[self libraryDatabase]];
OEDBImage *boxImage = [OEDBImage imageWithURL:url inLibrary:[self libraryDatabase]];

NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
NSArray *sizes = [standardDefaults objectForKey:OEBoxSizesKey];
Expand All @@ -438,8 +422,8 @@ - (void)setBoxImageByURL:(NSURL *)url

[self setBoxImage:boxImage];
}
#pragma mark - NSPasteboardWriting

#pragma mark - NSPasteboardWriting
// TODO: fix pasteboard writing
- (NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard
{
Expand Down

0 comments on commit b6dc687

Please sign in to comment.