mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2829 Add overall handling of std::bad_alloc exception with a message box. Now the user can know what is happening, and possibly save his work. On linux this will only work sometimes unless sysctl vm.overcommit_memory = 2
This commit is contained in:
parent
92fd4183a9
commit
2f80e99abc
@ -134,6 +134,40 @@ void AppEnum< RiaApplication::RINavigationPolicy >::setUp()
|
||||
//==================================================================================================
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::notify(QObject* receiver, QEvent* event)
|
||||
{
|
||||
// Pre-allocating a memory exhaustion message
|
||||
// Doing som e trickery to avoid deadlock, as creating a messagebox actually triggers a call to this notify method.
|
||||
|
||||
static QMessageBox* memoryExhaustedBox = nullptr;
|
||||
static bool allocatingMessageBox = false;
|
||||
if (!memoryExhaustedBox && !allocatingMessageBox)
|
||||
{
|
||||
allocatingMessageBox = true;
|
||||
memoryExhaustedBox = new QMessageBox(QMessageBox::Critical,
|
||||
"ResInsight Exhausted Memory",
|
||||
"Memory is Exhausted!\n ResInsight could not allocate the memory needed, and is now unstable and will probably crash soon.");
|
||||
}
|
||||
|
||||
bool done = true;
|
||||
try
|
||||
{
|
||||
done = QApplication::notify(receiver, event);
|
||||
}
|
||||
catch ( const std::bad_alloc& )
|
||||
{
|
||||
if (memoryExhaustedBox) memoryExhaustedBox->exec();
|
||||
std::cout << "ResInsight: Memory is Exhausted!\n ResInsight could not allocate the memory needed, and is now unstable and will probably crash soon." << std::endl;
|
||||
// If we really want to crash instead of limping forward:
|
||||
// throw;
|
||||
}
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -216,6 +216,8 @@ private:
|
||||
friend RiaArgumentParser;
|
||||
void setHelpText(const QString& helpText);
|
||||
|
||||
virtual bool notify(QObject *, QEvent *) override;
|
||||
|
||||
private slots:
|
||||
void slotWorkerProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
|
||||
|
@ -49,7 +49,22 @@ int main(int argc, char *argv[])
|
||||
RiaLogging::setLoggerInstance(new RiuMessagePanelLogger(window.messagePanel()));
|
||||
RiaLogging::loggerInstance()->setLevel(RI_LL_DEBUG);
|
||||
|
||||
int exitCode = app.exec();
|
||||
int exitCode = 0;
|
||||
try
|
||||
{
|
||||
exitCode = app.exec();
|
||||
}
|
||||
catch (std::exception& exep )
|
||||
{
|
||||
std::cout << "A standard c++ exception that terminated ResInsight caught in RiaMain.cpp: " << exep.what() << std::endl;
|
||||
throw;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cout << "An unknown exception that terminated ResInsight caught in RiaMain.cpp. " << std::endl;
|
||||
throw;
|
||||
}
|
||||
|
||||
RiaLogging::deleteLoggerInstance();
|
||||
|
||||
return exitCode;
|
||||
|
Loading…
Reference in New Issue
Block a user