diff --git a/libs/pigment/KoColor.h b/libs/pigment/KoColor.h --- a/libs/pigment/KoColor.h +++ b/libs/pigment/KoColor.h @@ -44,17 +44,8 @@ { public: - 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; - } + KoColor(); /// 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 @@ const KoColorSpace *m_colorSpace; quint8 m_data[MAX_PIXEL_SIZE]; quint8 m_size; - - static const KoColor *s_prefab; }; Q_DECLARE_METATYPE(KoColor) diff --git a/libs/pigment/KoColor.cpp b/libs/pigment/KoColor.cpp --- a/libs/pigment/KoColor.cpp +++ b/libs/pigment/KoColor.cpp @@ -33,21 +33,35 @@ #include "KoColorSpaceRegistry.h" #include "KoChannelInfo.h" -const KoColor *KoColor::s_prefab = nullptr; +#include -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); + KIS_ASSERT(defaultColorSpace); + + 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."; #endif #endif + } + + KoColor *value = 0; +}; + +Q_GLOBAL_STATIC(DeafultKoColorInitializer, s_defaultKoColor); + +} + + +KoColor::KoColor() { + *this = *s_defaultKoColor->value; } KoColor::KoColor(const KoColorSpace * colorSpace) diff --git a/libs/ui/KisApplication.cpp b/libs/ui/KisApplication.cpp --- a/libs/ui/KisApplication.cpp +++ b/libs/ui/KisApplication.cpp @@ -421,10 +421,6 @@ processEvents(); addResourceTypes(); - // now we're set up, and the LcmsEnginePlugin will have access to resource paths for color management, - // we can finally initialize KoColor. - KoColor::init(); - // Load all resources and tags before the plugins do that loadResources(); diff --git a/libs/widgetutils/KoResourcePaths.h b/libs/widgetutils/KoResourcePaths.h --- a/libs/widgetutils/KoResourcePaths.h +++ b/libs/widgetutils/KoResourcePaths.h @@ -226,9 +226,10 @@ 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(); private: diff --git a/libs/widgetutils/KoResourcePaths.cpp b/libs/widgetutils/KoResourcePaths.cpp --- a/libs/widgetutils/KoResourcePaths.cpp +++ b/libs/widgetutils/KoResourcePaths.cpp @@ -558,7 +558,7 @@ 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; } diff --git a/plugins/color/lcms2engine/LcmsEnginePlugin.cpp b/plugins/color/lcms2engine/LcmsEnginePlugin.cpp --- a/plugins/color/lcms2engine/LcmsEnginePlugin.cpp +++ b/plugins/color/lcms2engine/LcmsEnginePlugin.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "kis_assert.h" @@ -88,7 +89,12 @@ { // 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. - KoResourcePaths::assertReady(); + + 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 cmsSetLogErrorHandler(&lcms2LogErrorHandlerFunction);