Skip to content

Commit

Permalink
Fix linux crash on vector style editor tab (opentoonz#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
manongjohn authored and shun-iwasawa committed Dec 16, 2020
1 parent ff7b10b commit 8292321
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion toonz/sources/toonzlib/stylemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ void CustomStyleManager::StyleLoaderTask::run() {
assert(vPalette);
vimg->setPalette(vPalette);

#ifdef LINUX
TOfflineGL *glContext = 0;
glContext = TOfflineGL::getStock(chipSize);
glContext->clear(TPixel32::White);
#else
QOpenGLContext *glContext = new QOpenGLContext();
if (QOpenGLContext::currentContext())
glContext->setShareContext(QOpenGLContext::currentContext());
Expand All @@ -135,6 +140,7 @@ void CustomStyleManager::StyleLoaderTask::run() {

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
#endif

TRectD bbox = img->getBBox();
double scx = 0.8 * chipSize.lx / bbox.getLx();
Expand All @@ -148,14 +154,20 @@ void CustomStyleManager::StyleLoaderTask::run() {
TTranslation(-0.5 * (bbox.x0 + bbox.x1), -0.5 * (bbox.y0 + bbox.y1));
TVectorRenderData rd(aff, chipSize, vPalette, 0, true);

#ifdef LINUX
glContext->draw(img, rd);
// No need to clone! The received raster already is a copy of the
// context's buffer
ras = glContext->getRaster(); //->clone();
#else
tglDraw(rd, vimg.getPointer());

image = new QImage(fb.toImage().scaled(QSize(chipSize.lx, chipSize.ly),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation));
fb.release();
glContext->deleteLater();

#endif
} else if (rimg) {
TDimension size = rimg->getRaster()->getSize();
if (size == chipSize)
Expand All @@ -170,11 +182,18 @@ void CustomStyleManager::StyleLoaderTask::run() {
TRop::addBackground(rout, TPixel::White);
ras = rout;
}
#ifndef LINUX
image = new QImage(chipSize.lx, chipSize.ly, QImage::Format_RGB32);
convertRaster32ToImage(ras, image);
#endif
} else
assert(!"unsupported type for custom styles!");

#ifdef LINUX
image = new QImage(chipSize.lx, chipSize.ly, QImage::Format_RGB32);
convertRaster32ToImage(ras, image);
#endif

m_data.m_patternName = m_fp.getName();
m_data.m_isVector = (m_fp.getType() == "pli" || m_fp.getType() == "svg");
m_data.m_image = image;
Expand Down

0 comments on commit 8292321

Please sign in to comment.