Skip to content

Commit

Permalink
Fixing some crash issues. (#2541)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingpqi123 authored Oct 22, 2024
1 parent a25261a commit e94bd69
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/platform/cocoa/private/PAGFileImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ + (void)LoadAsync:(NSString*)path completionBlock:(void (^)(PAGFile*))callback {
return;
}
void (^copyCallback)(PAGFile*) = Block_copy(callback);
[path retain];
tgfx::Task::Run([callBack = copyCallback, path]() {
PAGFile* file = [PAGFileImpl Load:path];
[path release];
callBack(file);
Block_release(callBack);
});
Expand Down
11 changes: 6 additions & 5 deletions src/platform/ios/PAGImageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,7 @@ - (BOOL)setPath:(NSString*)newPath {

- (BOOL)setPath:(NSString*)path maxFrameRate:(float)maxFrameRate {
std::lock_guard<std::mutex> autoLock(imageViewLock);
if ([filePath isEqualToString:path]) {
return YES;
}
if (filePath) {
if (filePath != nil) {
[filePath release];
filePath = nil;
}
Expand All @@ -524,10 +521,14 @@ - (void)setPathAsync:(NSString*)path
filePath = nil;
}
filePath = [path retain];
[self retain];
[PAGFile LoadAsync:path
completionBlock:^(PAGFile* pagFile) {
[self setComposition:pagFile maxFrameRate:maxFrameRate];
imageViewLock.lock();
[self setCompositionInternal:pagFile maxFrameRate:maxFrameRate];
imageViewLock.unlock();
callback(pagFile);
[self release];
}];
}

Expand Down
19 changes: 9 additions & 10 deletions src/platform/ios/PAGView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
@implementation PAGView {
PAGPlayer* pagPlayer;
PAGSurface* pagSurface;
PAGFile* pagFile;
NSString* filePath;
PAGAnimator* animator;
BOOL _isVisible;
Expand All @@ -40,7 +39,6 @@ - (instancetype)initWithFrame:(CGRect)frame {

- (void)initPAG {
_isVisible = FALSE;
pagFile = nil;
filePath = nil;
self.contentScaleFactor = [UIScreen mainScreen].scale;
self.backgroundColor = [UIColor clearColor];
Expand All @@ -65,7 +63,6 @@ - (void)dealloc {
[animator release];
[pagPlayer release];
[pagSurface release];
[pagFile release];
[filePath release];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
Expand Down Expand Up @@ -203,9 +200,9 @@ - (BOOL)setPath:(NSString*)path {
[filePath release];
filePath = nil;
}
PAGFile* file = [PAGFile Load:path];
[self setComposition:file];
filePath = [path retain];
PAGFile* file = [PAGFile Load:path];
[self setCompositionInternal:file];
return file != nil;
}

Expand All @@ -215,10 +212,12 @@ - (void)setPathAsync:(NSString*)path completionBlock:(void (^)(PAGFile*))callbac
filePath = nil;
}
filePath = [path retain];
[self retain];
[PAGFile LoadAsync:path
completionBlock:^(PAGFile* file) {
[self setComposition:file];
[self setCompositionInternal:file];
callback(file);
[self release];
}];
}

Expand All @@ -231,10 +230,10 @@ - (void)setComposition:(PAGComposition*)newComposition {
[filePath release];
filePath = nil;
}
if (pagFile != nil) {
[pagFile release];
pagFile = nil;
}
[self setCompositionInternal:newComposition];
}

- (void)setCompositionInternal:(PAGComposition*)newComposition {
[pagPlayer setComposition:newComposition];
[animator setProgress:[pagPlayer getProgress]];
if (_isVisible) {
Expand Down
3 changes: 3 additions & 0 deletions src/rendering/utils/Directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ bool Directory::CreateRecursively(const std::string& folder) {

void Directory::VisitFiles(const std::string& folder,
std::function<void(const std::string&, size_t)> callback) {
if (!std::filesystem::exists(folder)) {
Directory::CreateRecursively(folder);
}
for (const auto& entry : std::filesystem::directory_iterator(folder)) {
if (entry.is_regular_file()) {
std::string str = entry.path().filename().string();
Expand Down

0 comments on commit e94bd69

Please sign in to comment.