Skip to content

Commit

Permalink
Fixed crash recovery issues on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pyushkevich committed Jan 14, 2025
1 parent 9878843 commit 6c6443c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Common/IPCHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ IPCHandler::Attach(const char *path, short version, size_t message_size)
m_Interface->SetKey("5A636Q488E.itksnap");

// Attach or create shared memory
AttachStatus status = ATTACHED;
AttachStatus status = IPC_ATTACHED;
if (!m_Interface->Attach())
{
m_Interface->Create(msize);
status = CREATED;
status = IPC_CREATED;
}

// Check if attached
Expand All @@ -53,7 +53,7 @@ IPCHandler::Attach(const char *path, short version, size_t message_size)
cerr << "Error attaching to or creating shared memory: " << strerror(errno) << endl;
cerr << "This error may occur if a user is running two versions of ITK-SNAP" << endl;
cerr << "Multisession support is disabled" << endl;
return ERROR;
return IPC_ERROR;
}

// Set the user data pointer
Expand Down
2 changes: 1 addition & 1 deletion Common/IPCHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class IPCHandler
~IPCHandler();

enum AttachStatus {
CREATED, ATTACHED, ERROR
IPC_CREATED, IPC_ATTACHED, IPC_ERROR
};

/**
Expand Down
2 changes: 1 addition & 1 deletion GUI/Model/SynchronizationModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void SynchronizationModel::OnUpdate()
// << endl;

// If we attached to an existing session, then update from that session.
if (status == IPCHandler::ATTACHED)
if (status == IPCHandler::IPC_ATTACHED)
{
// std::cout << "Reading IPC state after main image update and exiting" << std::endl;
ReadIPCState(false);
Expand Down
18 changes: 1 addition & 17 deletions GUI/Qt/Components/SNAPQApplication.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,7 @@ void SNAPQApplication::setMainWindow(MainImageWindow *mainwin)
bool
SNAPQApplication::notify(QObject *object, QEvent *event)
{
try
{
return QApplication::notify(object, event);
}
// catch (const std::exception &exc)
catch(...)
{
// Crash!
qCritical() << "Caught exception, exiting!!!";
// ReportNonLethalException(
// NULL, exc, "Unexpected Error", "ITK-SNAP has crashed due to an unexpected error");

// Exit the application
QApplication::exit(-1);

return false;
}
return QApplication::notify(object, event);
}

bool SNAPQApplication::event(QEvent *event)
Expand Down
12 changes: 2 additions & 10 deletions GUI/Qt/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ test_terminate_handler()
QPushButton *openFolderButton = msgBox.addButton("Open Folder", QMessageBox::AcceptRole);

// Add the "Close" button
msgBox.addButton(QMessageBox::Close);
msgBox.addButton("Close", QMessageBox::RejectRole);

// Execute the message box and handle the button press
msgBox.exec();
Expand Down Expand Up @@ -1224,15 +1224,7 @@ main(int argc, char *argv[])
}
catch (std::exception &exc)
{
qWarning() << "ITK-SNAP has crashed due to an uncaught exception: " << exc.what();
QString backup_dir = BackupSegmentationToEmergencyFile();
if (backup_dir.size())
QMessageBox::critical(
nullptr,
"Uncaught exception",
QString("ITK-SNAP has crashed due to an uncaught exception. Your unsaved "
"segmentation files were saved to %1")
.arg(backup_dir));
test_terminate_handler();
rc = -1;
}

Expand Down

0 comments on commit 6c6443c

Please sign in to comment.