Permalink
Browse files

Handle out-of-memory situations, giving users the opportunity to save…

… their project.
  • Loading branch information...
1 parent 1f295a8 commit e69c56879b2594c94a3fca179cb9f606c912a77c @Tulon Tulon committed Oct 23, 2011
Showing with 106 additions and 82 deletions.
  1. +16 −2 Application.cpp
  2. +3 −1 Application.h
  3. +4 −0 OutOfMemoryDialog.cpp
  4. +2 −2 OutOfMemoryHandler.cpp
  5. +81 −77 ui/OutOfMemoryDialog.ui
View
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2009 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -16,9 +16,23 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "Application.h"
#include "Application.h.moc"
+#include "OutOfMemoryHandler.h"
+#include <new>
Application::Application(int& argc, char** argv)
: QApplication(argc, argv)
{
-}
+}
+
+bool
+Application::notify(QObject* receiver, QEvent* e)
+{
+ try {
+ return QApplication::notify(receiver, e);
+ } catch (std::bad_alloc const&) {
+ OutOfMemoryHandler::instance().handleOutOfMemorySituation();
+ return false;
+ }
+}
View
@@ -1,6 +1,6 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
- Copyright (C) 2007-2009 Joseph Artsimovich <joseph_a@mail.ru>
+ Copyright (C) Joseph Artsimovich <joseph.artsimovich@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -26,6 +26,8 @@ class Application : public QApplication
Q_OBJECT
public:
Application(int& argc, char** argv);
+
+ virtual bool notify(QObject* receiver, QEvent* e);
};
#endif
@@ -30,6 +30,10 @@ OutOfMemoryDialog::OutOfMemoryDialog(QWidget* parent)
: QDialog(parent)
{
ui.setupUi(this);
+ if (sizeof(void*) > 32) {
+ ui.only_32bit_1->hide();
+ ui.only_32bit_2->hide();
+ }
ui.topLevelStack->setCurrentWidget(ui.mainPage);
@@ -34,8 +34,8 @@ OutOfMemoryHandler::instance()
// However, because we insist an instance of this object to be created early on,
// the only case that might get us into trouble is an out-of-memory situation
// after main() has returned and this instance got destroyed. This scenario
- // sounds rather fantastic, and is not a big deal, as the project would
- // already be saved.
+ // sounds rather fantastic, and is not a big deal, as the project would have
+ // already been saved.
static OutOfMemoryHandler object;
return object;
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>470</width>
- <height>362</height>
+ <height>342</height>
</rect>
</property>
<property name="windowTitle">
@@ -62,6 +62,9 @@ font-weight: bold;</string>
<property name="currentIndex">
<number>0</number>
</property>
+ <property name="documentMode">
+ <bool>false</bool>
+ </property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Possible reasons</string>
@@ -89,60 +92,62 @@ font-weight: bold;</string>
<rect>
<x>0</x>
<y>0</y>
- <width>448</width>
- <height>237</height>
+ <width>446</width>
+ <height>227</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
- <property name="spacing">
- <number>10</number>
- </property>
<item>
<widget class="QLabel" name="label_4">
- <property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
- </property>
<property name="text">
<string>Did you have to fix the DPI of your source images? Are you sure the values you entered were correct?</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
- <widget class="QLabel" name="label_6">
- <property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_6">
<property name="text">
- <string>Sometimes your source images may have wrong DPI embedded into them. Scan Tailor tries to detect such cases, but it may miss some. You may need to check &quot;Fix DPI even if they look normal&quot; when creating a project and look into &quot;All pages&quot; tab in the &quot;Fix DPI&quot; dialog.</string>
+ <string>Sometimes your source images may have wrong DPI embedded into them. Scan Tailor tries to detect those, but it's not always easy to tell. You may need to check &quot;Fix DPI even if they look normal&quot; when creating a project and look into &quot;All pages&quot; tab in the &quot;Fix DPI&quot; dialog, which is also accessible from the Tools menu.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
- <widget class="QLabel" name="label_8">
- <property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
+ <widget class="Line" name="line_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_8">
<property name="text">
<string>Is your output DPI set too high? Usually you don't need it higher than 600.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
@@ -188,77 +193,82 @@ font-weight: bold;</string>
<rect>
<x>0</x>
<y>0</y>
- <width>432</width>
- <height>330</height>
+ <width>446</width>
+ <height>227</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
- <property name="spacing">
- <number>10</number>
- </property>
<item>
<widget class="QLabel" name="label_10">
- <property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
- </property>
<property name="text">
- <string>Fix your DPIs. Learn how to estimate unknown DPIs.</string>
+ <string extracomment="Feel free to change the URL to a localized video / text tutorial.">Fix your DPIs. Learn how to &lt;a href=&quot;http://vimeo.com/12524529&quot;&gt;estimate unknown DPIs&lt;/a&gt;.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
- <widget class="QLabel" name="label_12">
- <property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
+ <widget class="Line" name="line_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="only_32bit_1">
<property name="text">
- <string>When working with grayscale images, make sure they are really grayscale. If they are actually color images just happening to look grayscale, convert them to grayscale using a program like XnView. This will save you significant amount of memory.</string>
+ <string>If your hardware and operating system are 64-bit capable, consider switching to a 64-bit version of Scan Tailor.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
- <widget class="QLabel" name="label_14">
- <property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
+ <widget class="Line" name="only_32bit_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_12">
<property name="text">
- <string>As a last resort, you can save some memory by making sure thumbnails are pre-created rather than are created on demand. This can be done by slowly scrolling the thumbnail list all the way from top to bottom before starting any work.</string>
+ <string>When working with grayscale images, make sure they are really grayscale. If they are actually color images that just happen to look grayscale, convert them to grayscale using some kind of batch image converter. This will both save memory and increase performance.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
- <widget class="QLabel" name="label_18">
- <property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
+ <widget class="Line" name="line_5">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_14">
<property name="text">
- <string>Moving from a 32-bit to 64-bit version of Windows will increase limit of available memory for 32-bit applications from 2 to 3 GB.
-[For experts only!] There is a way to achieve the same effect on 32-bit versions of Windows.</string>
+ <string>As a last resort, you can save some memory by making sure thumbnails are pre-created rather than created on demand. This can be done by slowly scrolling the thumbnail list all the way from top to bottom before starting any real work.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>
@@ -284,10 +294,7 @@ font-weight: bold;</string>
<attribute name="title">
<string>What won't help</string>
</attribute>
- <layout class="QVBoxLayout" name="verticalLayout_7">
- <property name="spacing">
- <number>0</number>
- </property>
+ <layout class="QVBoxLayout" name="verticalLayout_8">
<property name="margin">
<number>0</number>
</property>
@@ -296,6 +303,9 @@ font-weight: bold;</string>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
+ <property name="frameShadow">
+ <enum>QFrame::Plain</enum>
+ </property>
<property name="widgetResizable">
<bool>true</bool>
</property>
@@ -304,28 +314,22 @@ font-weight: bold;</string>
<rect>
<x>0</x>
<y>0</y>
- <width>448</width>
- <height>237</height>
+ <width>446</width>
+ <height>227</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_8">
- <property name="spacing">
- <number>10</number>
- </property>
+ <layout class="QVBoxLayout" name="verticalLayout_7">
<item>
- <widget class="QLabel" name="label_16">
- <property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
- </property>
- <property name="frameShadow">
- <enum>QFrame::Raised</enum>
- </property>
+ <widget class="QLabel" name="label_5">
<property name="text">
- <string>Upgrading your RAM or any other hardware won't help. The operating system uses swapping to compensate the lack of RAM. However, 32-bit programs are limited to 3 (often 2) GB of memory. Scan Tailor just hit that limit.</string>
+ <string>Surprisingly, upgrading your RAM won't help here. The lack of RAM is compensated by the swap mechanism, which makes things slow, but keeps programs running. An out of memory situation means we ran out of memory address space, which has nothing to do with the amount of RAM you have. The only way to increase the memory address space is to go 64-bit hardware, 64-bit operating system and 64-bit Scan Tailor.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
</widget>
</item>
<item>

0 comments on commit e69c568

Please sign in to comment.