Commit 73ee104c authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix initialization of KoColor to use QGlobalStatic

Also disable the assert for unittests. Ideally, we should somehow
initialize paths for unittests as well, but it is a separate task.

Differential Revision:
parent 4461dcaf
......@@ -33,21 +33,35 @@
#include "KoColorSpaceRegistry.h"
#include "KoChannelInfo.h"
const KoColor *KoColor::s_prefab = nullptr;
#include <QGlobalStatic>
void KoColor::init()
namespace {
struct DeafultKoColorInitializer
KIS_ASSERT(s_prefab == nullptr);
KoColor *prefab = new KoColor(KoColorSpaceRegistry::instance()->rgb16(0));
prefab->m_colorSpace->fromQColor(Qt::black, prefab->m_data);
prefab->m_colorSpace->setOpacity(prefab->m_data, OPACITY_OPAQUE_U8, 1);
s_prefab = prefab;
DeafultKoColorInitializer() {
const KoColorSpace *defaultColorSpace = KoColorSpaceRegistry::instance()->rgb16(0);
value = new KoColor(Qt::black, defaultColorSpace);
#ifndef NODEBUG
#ifndef QT_NO_DEBUG
// warn about rather expensive checks in assertPermanentColorspace().
qWarning() << "KoColor debug runtime checks are active.";
// warn about rather expensive checks in assertPermanentColorspace().
qWarning() << "KoColor debug runtime checks are active.";
KoColor *value = 0;
Q_GLOBAL_STATIC(DeafultKoColorInitializer, s_defaultKoColor);
KoColor::KoColor() {
*this = *s_defaultKoColor->value;
KoColor::KoColor(const KoColorSpace * colorSpace)
......@@ -44,17 +44,8 @@ class KRITAPIGMENT_EXPORT KoColor : public boost::equality_comparable<KoColor>
static void init();
/// Create an empty KoColor. It will be valid, but also black and transparent
KoColor() {
const KoColor * const prefab = s_prefab;
// assert that KoColor::init was called and everything is set up properly.
KIS_ASSERT_X(prefab != nullptr, "KoColor::KoColor()", "KoColor not initialized yet.");
*this = *prefab;
/// Create a null KoColor. It will be valid, but all channels will be set to 0
explicit KoColor(const KoColorSpace * colorSpace);
......@@ -230,8 +221,6 @@ private:
const KoColorSpace *m_colorSpace;
quint8 m_data[MAX_PIXEL_SIZE];
quint8 m_size;
static const KoColor *s_prefab;
......@@ -421,10 +421,6 @@ bool KisApplication::start(const KisApplicationArguments &args)
// now we're set up, and the LcmsEnginePlugin will have access to resource paths for color management,
// we can finally initialize KoColor.
// Load all resources and tags before the plugins do that
......@@ -558,7 +558,7 @@ void KoResourcePaths::setReady()
s_instance->d->ready = true;
void KoResourcePaths::assertReady()
bool KoResourcePaths::isReady()
KIS_ASSERT_X(s_instance->d->ready, "KoResourcePaths::assertReady", "Resource paths are not ready yet.");
return s_instance->d->ready;
......@@ -226,9 +226,10 @@ public:
static void setReady();
* Assert that all resource paths have been initialized.
* Return if resource paths have been initialized and users
* of this class may expect to load resources from the proper paths.
static void assertReady();
static bool isReady();
......@@ -29,6 +29,7 @@
#include <KoResourcePaths.h>
#include <klocalizedstring.h>
#include <QDebug>
#include <QApplication>
#include "kis_assert.h"
......@@ -88,7 +89,12 @@ LcmsEnginePlugin::LcmsEnginePlugin(QObject *parent, const QVariantList &)
// We need all resource paths to be properly initialized via KisApplication, otherwise we will
// initialize this instance with lacking color profiles which will cause lookup errors later on.
KIS_ASSERT_X(KoResourcePaths::isReady() ||
(QApplication::instance()->applicationName() != "krita" &&
QApplication::instance()->applicationName() != "krita.exe"),
"LcmsEnginePlugin::LcmsEnginePlugin", "Resource paths are not ready yet.");
// Set the lmcs error reporting function
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment