fix deadlock and remove unused bx::Error (#2589)

This commit is contained in:
DarkContact 2021-08-18 19:22:55 +03:00 committed by GitHub
parent be0e7ef307
commit 8f60971dd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 41 deletions

View File

@ -58,16 +58,15 @@ bool openFileSelectionDialog(
)
{
NSMutableArray* fileTypes = [NSMutableArray arrayWithCapacity:10];
bx::Error err;
for (bx::LineReader lr(_filter); !lr.isDone() && err.isOk();)
for (bx::LineReader lr(_filter); !lr.isDone();)
{
const bx::StringView line = lr.next();
const bx::StringView sep = bx::strFind(line, '|');
if (!sep.isEmpty() )
{
for (Split split(bx::strTrim(bx::StringView(sep.getPtr()+1, line.getTerm() ), " "), ' '); !split.isDone() && err.isOk();)
for (Split split(bx::strTrim(bx::StringView(sep.getPtr()+1, line.getTerm() ), " "), ' '); !split.isDone();)
{
const bx::StringView token = split.next();
@ -82,14 +81,8 @@ bool openFileSelectionDialog(
}
__block NSString* fileName = nil;
bx::Semaphore semaphore;
bx::Semaphore* psemaphore = &semaphore;
CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop],
kCFRunLoopCommonModes,
^{
void (^invokeDialog)(void) = ^{
NSSavePanel* panel = nil;
if ( FileSelectionDialogType::Open == _type)
{
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
@ -117,10 +110,25 @@ bool openFileSelectionDialog(
}
}
[panel close];
};
if ([NSThread isMainThread])
{
invokeDialog();
}
else
{
bx::Semaphore semaphore;
bx::Semaphore* psemaphore = &semaphore;
CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop],
kCFRunLoopCommonModes,
^{
invokeDialog();
psemaphore->post();
});
semaphore.wait();
}
if ( fileName != nil )
{