Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_assert.cpp File Reference
#include "kis_assert.h"
#include <QString>
#include <QMessageBox>
#include <QThread>
#include <QProcessEnvironment>
#include <QCoreApplication>
#include <QApplication>
#include <klocalizedstring.h>
#include <KisUsageLogger.h>
#include <string>
#include "config-safe-asserts.h"

Go to the source code of this file.

Functions

void kis_assert_common (const char *assertion, const char *file, int line, bool abort, bool isIgnorable)
 
void kis_assert_exception (const char *assertion, const char *file, int line)
 
void kis_assert_recoverable (const char *assertion, const char *file, int line)
 
void kis_assert_x_exception (const char *assertion, const char *where, const char *what, const char *file, int line)
 
void kis_safe_assert_recoverable (const char *assertion, const char *file, int line)
 

Function Documentation

◆ kis_assert_common()

void kis_assert_common ( const char * assertion,
const char * file,
int line,
bool abort,
bool isIgnorable )

TODO: Add automatic saving of the documents

Requirements: 1) Should save all open KisDocument objects 2) Should not overwrite original document since the saving process may fail. 3) Should not overwrite any autosaved documents since the saving process may fail. 4) Double-fault tolerance! Assert during emergency saving should not lead to an infinite loop.

Definition at line 34 of file kis_assert.cpp.

35{
36 QString shortMessage =
37 QString("%4ASSERT (krita): \"%1\" in file %2, line %3")
38 .arg(assertion)
39 .arg(file)
40 .arg(line)
41 .arg(isIgnorable ? "SAFE " : "");
42
43 QString longMessage =
44 QString(
45 "Krita has encountered an internal error:\n\n"
46 "%1\n\n"
47 "Please report a bug to developers!\n\n"
48 "Press Ignore to try to continue.\n"
49 "Press Abort to see developers information (all unsaved data will be lost)")
50 .arg(shortMessage);
51
52 KisUsageLogger::log(shortMessage);
53
54 bool disableAssertMsg =
55 QProcessEnvironment::systemEnvironment().value("KRITA_NO_ASSERT_MSG", "0").toInt();
56
57 // disable message box if the assert happened in non-gui thread
58 // or if the GUI is not yet instantiated
59 if (!QCoreApplication::instance() || QThread::currentThread() != QCoreApplication::instance()->thread()) {
60 disableAssertMsg = true;
61 }
62
63 bool shouldIgnoreAsserts = false;
64 bool forceCrashOnSafeAsserts = false;
65
66#ifdef HIDE_SAFE_ASSERTS
67 shouldIgnoreAsserts |= HIDE_SAFE_ASSERTS;
68#endif
69
70#ifdef CRASH_ON_SAFE_ASSERTS
71 forceCrashOnSafeAsserts |= CRASH_ON_SAFE_ASSERTS;
72#endif
73
74 disableAssertMsg |= shouldIgnoreAsserts || forceCrashOnSafeAsserts;
75
76 QMessageBox::StandardButton button =
77 isIgnorable && !forceCrashOnSafeAsserts ?
78 QMessageBox::Ignore : QMessageBox::Abort;
79
80 if (!disableAssertMsg) {
81 button =
82 QMessageBox::critical(qApp->activeWindow(), i18nc("@title:window", "Krita: Internal Error"),
83 longMessage,
84 QMessageBox::Ignore | QMessageBox::Abort,
85 QMessageBox::Ignore);
86 }
87
88 if (button == QMessageBox::Abort || abort) {
89 qFatal("%s", shortMessage.toLatin1().data());
90 } else if (isIgnorable) {
91 // Assert is a bug! Please don't change this line to warnKrita,
92 // the user must see it!
93 qWarning("%s", shortMessage.toLatin1().data());
94 }
95}
static void log(const QString &message)
Logs with date/time.
QString button(const QWheelEvent &ev)

References button(), and KisUsageLogger::log().

◆ kis_assert_exception()

void kis_assert_exception ( const char * assertion,
const char * file,
int line )

Definition at line 108 of file kis_assert.cpp.

109{
110 kis_assert_common(assertion, file, line, true, false);
111}
void kis_assert_common(const char *assertion, const char *file, int line, bool abort, bool isIgnorable)

References kis_assert_common().

◆ kis_assert_recoverable()

void kis_assert_recoverable ( const char * assertion,
const char * file,
int line )

Definition at line 98 of file kis_assert.cpp.

99{
100 kis_assert_common(assertion, file, line, false, false);
101}

References kis_assert_common().

◆ kis_assert_x_exception()

void kis_assert_x_exception ( const char * assertion,
const char * where,
const char * what,
const char * file,
int line )

Definition at line 113 of file kis_assert.cpp.

117{
118 QString res =
119 QString("ASSERT failure in %1: \"%2\" (%3)")
120 .arg(where, what, assertion);
121
122 kis_assert_common(res.toLatin1().data(), file, line, true, false);
123}

References kis_assert_common().

◆ kis_safe_assert_recoverable()

void kis_safe_assert_recoverable ( const char * assertion,
const char * file,
int line )

Definition at line 103 of file kis_assert.cpp.

104{
105 kis_assert_common(assertion, file, line, false, true);
106}

References kis_assert_common().