Commit f5c9ae34 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Possible fix for the Generator Dialog update crash

The dialog should also care about the thread safety and use
the cookie returned by the updating threads.

BUG:428014
parent 069dd6ba
......@@ -146,12 +146,13 @@ void KisGeneratorLayer::requestUpdateJobsWithStroke(KisStrokeId strokeId, KisFil
m_d->preparedForFilter = filterConfig;
}
void KisGeneratorLayer::previewWithStroke(const KisStrokeId strokeId)
QWeakPointer<bool> KisGeneratorLayer::previewWithStroke(const KisStrokeId strokeId)
{
KisFilterConfigurationSP filterConfig = filter();
KIS_SAFE_ASSERT_RECOVER_RETURN(filterConfig);
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(filterConfig, QWeakPointer<bool>());
requestUpdateJobsWithStroke(strokeId, filterConfig);
return m_d->updateCookie;
}
void KisGeneratorLayer::update()
......
......@@ -65,7 +65,7 @@ public:
* re-runs the generator with the specified configuration.
* Used for previewing the layer inside the stroke.
*/
void previewWithStroke(const KisStrokeId stroke);
QWeakPointer<bool> previewWithStroke(const KisStrokeId stroke);
using KisSelectionBasedLayer::setDirty;
void setDirty(const QVector<QRect> &rects) override;
......
......@@ -43,26 +43,26 @@ QVector<KisStrokeJobData *>KisGeneratorStrokeStrategy::createJobsData(const KisG
for(const auto& tile: tiles) {
KisProcessingInformation dstCfg(dev, tile.topLeft(), KisSelectionSP());
addJobConcurrent(jobsData, [=]() {
const_cast<QSharedPointer<bool> &>(cookie).clear();
f->generate(dstCfg, tile.size(), filterConfig, helper->updater());
// HACK ALERT!!!
// this avoids cyclic loop with KisRecalculateGeneratorLayerJob::run()
const_cast<KisGeneratorLayerSP &>(layer)->setDirtyWithoutUpdate({tile});
const_cast<QSharedPointer<bool> &>(cookie).clear();
});
}
} else {
KisProcessingInformation dstCfg(dev, rc.topLeft(), KisSelectionSP());
addJobSequential(jobsData, [=]() {
const_cast<QSharedPointer<bool>&>(cookie).clear();
f->generate(dstCfg, rc.size(), filterConfig, helper->updater());
// HACK ALERT!!!
// this avoids cyclic loop with KisRecalculateGeneratorLayerJob::run()
const_cast<KisGeneratorLayerSP &>(layer)->setDirtyWithoutUpdate({rc});
const_cast<QSharedPointer<bool>&>(cookie).clear();
});
}
}
......
......@@ -127,8 +127,12 @@ void KisDlgGeneratorLayer::slotNameChanged(const QString & text)
void KisDlgGeneratorLayer::slotDelayedPreviewGenerator()
{
if (!m_stroke.isNull()) {
layer->setFilterWithoutUpdate(configuration()->cloneWithResourcesSnapshot());
layer->previewWithStroke(m_stroke);
if (m_updateCookie) {
m_compressor.start();
} else {
layer->setFilterWithoutUpdate(configuration()->cloneWithResourcesSnapshot());
m_updateCookie = layer->previewWithStroke(m_stroke);
}
} else {
KIS_ASSERT_RECOVER_RETURN(layer);
layer->setFilter(configuration()->cloneWithResourcesSnapshot());
......
......@@ -65,6 +65,7 @@ private:
bool m_freezeName;
KisStrokeId m_stroke;
KisThreadSafeSignalCompressor m_compressor;
QWeakPointer<bool> m_updateCookie;
};
#endif
Supports Markdown
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