-
-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Failed to create instance #202
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,9 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda | |
#else | ||
d->memory = new QSharedMemory( d->blockServerName ); | ||
#endif | ||
d->memory->attach(); | ||
delete d->memory; | ||
bool ok = d->memory->attach(); | ||
qCritical() << "d->memory->attach():" << ok; | ||
if (ok) delete d->memory; | ||
Comment on lines
+75
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That first As such I didn't think I need to check their success status. |
||
#endif | ||
// Guarantee thread safe behaviour with a shared memory block. | ||
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0) | ||
|
@@ -91,23 +92,46 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda | |
} | ||
d->initializeMemoryBlock(); | ||
} else { | ||
|
||
qCritical() << "Shared memory creation failed:" << d->memory->errorString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a valid code path when there is already an instance running. There is no need for |
||
|
||
if( d->memory->error() == QSharedMemory::AlreadyExists ){ | ||
// Attempt to attach to the memory segment | ||
if( ! d->memory->attach() ){ | ||
qCritical() << "SingleApplication: Unable to attach to shared memory block."; | ||
abortSafely(); | ||
} else { | ||
qCritical() << "Successfully attached to existing shared memory block"; | ||
} | ||
if( ! d->memory->lock() ){ | ||
qCritical() << "SingleApplication: Unable to lock memory block after attach."; | ||
abortSafely(); | ||
} else { | ||
qCritical() << "Memory block successfully locked"; | ||
} | ||
|
||
} else { | ||
qCritical() << "SingleApplication: Unable to create block."; | ||
abortSafely(); | ||
} | ||
} | ||
|
||
auto *inst = static_cast<InstancesInfo*>( d->memory->data() ); | ||
|
||
if (!inst) { | ||
qCritical() << "Shared memory data is NULL!"; | ||
abortSafely(); | ||
} else { | ||
|
||
qCritical() << "Shared memory data doesn't NULL!"; | ||
qCritical() << "Primary: " << inst->primary << QString::asprintf("0x%X", inst->primary); | ||
qCritical() << "Secondary: " << inst->secondary << QString::asprintf("0x%X", inst->secondary); | ||
qCritical() << "Primary PID: " << inst->primaryPid << QString::asprintf("0x%llX", inst->primaryPid); | ||
qCritical() << "Checksum: " << inst->checksum << QString::asprintf("0x%X", inst->checksum); | ||
qCritical() << "Primary User: " << inst->primaryUser; | ||
} | ||
|
||
|
||
QElapsedTimer time; | ||
time.start(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When debugging and releasing, there is a high probability that this line will crash after a few more tries;