Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

fix: crash in Select Tool during deletion (TLV Save Box)

Anderson Pradof544ee9a17fc
diff --git a/toonz/sources/toonzlib/stagevisitor.cpp b/toonz/sources/toonzlib/stagevisitor.cpp
index 5a72a283a..1ee4ea551 100644
--- a/toonz/sources/toonzlib/stagevisitor.cpp
+++ b/toonz/sources/toonzlib/stagevisitor.cpp
@@ -129,7 +129,7 @@ QImage rasterToQImage(const TRasterP &ras) {
//! Draw orthogonal projection of \b bbox onto x-axis and y-axis.
void draw3DShadow(const TRectD &bbox, double z, double phi) {
- // bruttino assai, ammetto
+ // Not the most elegant solution
double a = bigBoxSize[0];
double b = bigBoxSize[1];
@@ -454,13 +454,10 @@ TRasterP RasterPainter::getRaster(int index, QTransform &matrix) {
//-----------------------------------------------------------------------------
/*! Make frame visualization.
-\n If onion-skin is active, create a new raster with dimension containing
-all
- frame with onion-skin; recall \b TRop::quickPut with argument
-each frame
- with onion-skin and new raster. If onion-skin is not active
-recall
- \b TRop::quickPut with argument current frame and new raster.
+\n If onion-skin is active, create a new raster with dimension containing
+all frame with onion-skin; recall \b TRop::quickPut with argument
+each frame with onion-skin and new raster. If onion-skin is not active
+recall \b TRop::quickPut with argument current frame and new raster.
*/
namespace {
@@ -486,9 +483,8 @@ void RasterPainter::flushRasterImages() {
int lx = rect.getLx(), ly = rect.getLy();
TDimension dim(lx, ly);
- // this is needed since a stop motion live view
- // doesn't register as a node correctly
- // there is probably a better way to do this.
+ // this is needed since a stop motion live view doesn't register
+ // as a node correctly there is probably a better way to do this.
if (rect.getLx() == 0 && lx == 0) {
rect = m_clipRect;
dim = m_dim;
@@ -516,8 +512,7 @@ void RasterPainter::flushRasterImages() {
// Clear the buffer - it will hold all the stacked nodes content to be overed
// on top of the OpenGL buffer through a glDrawPixel()
ras->lock();
-
- ras->clear(); // ras is typically reused - and we need it transparent first
+ ras->clear(); // ras is typically reused and we need it transparent first
TRect r = rect - rect.getP00();
TRaster32P viewedRaster = ras->extract(r);
@@ -580,59 +575,82 @@ void RasterPainter::flushRasterImages() {
TPaletteP plt;
int gapCheckIndex = -1;
+ TRasterCM32P aux;
if ((tc & ToonzCheck::eGap || tc & ToonzCheck::eAutoclose) &&
m_nodes[i].m_isCurrentColumn) {
- TRasterCM32P aux = srcCm->clone();
- srcCm = Preferences::instance()->getFillOnlySavebox()
- ? (TRasterCM32P)aux->extract(m_nodes[i].m_savebox)
- : aux;
- plt = m_nodes[i].m_palette->clone();
- gapCheckIndex = plt->addStyle(TPixel::Magenta);
- if (tc & ToonzCheck::eGap)
- AreaFiller(srcCm).rectFastFill(m_nodes[i].m_savebox, 1);
+ aux = srcCm->clone();
+ srcCm = Preferences::instance()->getFillOnlySavebox()
+ ? (TRasterCM32P)aux->extract(m_nodes[i].m_savebox)
+ : aux;
+ plt = m_nodes[i].m_palette->clone();
+ gapCheckIndex = plt->addStyle(TPixel::Magenta);
+ if (srcCm && srcCm->getLx() > 0 && srcCm->getLy() > 0) {
+ if (tc & ToonzCheck::eGap)
+ AreaFiller(srcCm).rectFastFill(m_nodes[i].m_savebox, 1);
+ }
if (tc & ToonzCheck::eAutoclose &&
m_nodes[i].m_onionMode == Node::eOnionSkinNone) {
- auto settings = ToonzCheck::instance()->getAutocloseSettings();
+ auto autocloseSettings =
+ ToonzCheck::instance()->getAutocloseSettings();
std::set<int> autoPaints;
- if (settings.m_ignoreAPInks) {
- for (int i = 0; i < plt->getStyleCount(); i++)
- if (plt->getStyle(i)->getFlags() != 0) autoPaints.insert(i);
+ if (autocloseSettings.m_ignoreAPInks) {
+ for (int styleIdx = 0; styleIdx < plt->getStyleCount(); ++styleIdx)
+ if (plt->getStyle(styleIdx)->getFlags() != 0) autoPaints.insert(styleIdx);
+ }
+ TAutocloser ac(srcCm, gapCheckIndex, autocloseSettings,
+ std::move(autoPaints));
+
+ if (srcCm && srcCm->getLx() > 0 && srcCm->getLy() > 0) {
+ bool hasContent = false;
+ srcCm->lock();
+ TPixelCM32 *pix = srcCm->pixels();
+ TPixelCM32 *end = pix + srcCm->getLx() * srcCm->getLy();
+ for (; pix < end; ++pix) {
+ if (pix->getInk() != 0 || pix->getPaint() != 0) {
+ hasContent = true;
+ break;
+ }
+ }
+ srcCm->unlock();
+ if (hasContent) {
+ if (ac.hasSegmentCache(m_currentImageId))
+ ac.draw(ac.getSegmentCache(m_currentImageId));
+ else
+ ac.exec(m_currentImageId);
+ }
}
- TAutocloser ac(srcCm, gapCheckIndex, settings, std::move(autoPaints));
- if (ac.hasSegmentCache(m_currentImageId))
- ac.draw(ac.getSegmentCache(m_currentImageId));
- else
- ac.exec(m_currentImageId);
if (tc & ToonzCheck::eGap) {
- int gapFillIndex =
- plt->addStyle(TPixelRGBM32(244, 186, 148, 0xff)); // orange
+ int gapFillIndex = plt->addStyle(TPixelRGBM32(244, 186, 148, 0xff));
plt->getStyle(gapFillIndex)->setFlags(1);
- AreaFiller(srcCm).rectFastFill(m_nodes[i].m_savebox, gapFillIndex);
+ if (srcCm && srcCm->getLx() > 0 && srcCm->getLy() > 0) {
+ AreaFiller(srcCm).rectFastFill(m_nodes[i].m_savebox,
+ gapFillIndex);
+ }
}
}
srcCm = aux;
- } else
+ } else {
plt = m_nodes[i].m_palette;
+ }
if (tc == 0 || tc == ToonzCheck::eBlackBg ||
- !m_nodes[i].m_isCurrentColumn)
+ !m_nodes[i].m_isCurrentColumn) {
TRop::quickPut(viewedRaster, srcCm, plt, aff, colorscale, inksOnly);
- else {
+ } else {
TRop::CmappedQuickputSettings settings;
- // Default quickPut settings for view checks
settings.m_globalColorScale = colorscale;
settings.m_inksOnly = inksOnly;
settings.m_transparencyCheck =
tc & (ToonzCheck::eTransparency | ToonzCheck::eGap);
settings.m_blackBgCheck = tc & ToonzCheck::eBlackBg;
- // Highlight specific ink/paint only for current column
settings.m_inkIndex = m_nodes[i].m_isCurrentColumn ? index : -1;
- settings.m_paintIndex = m_nodes[i].m_isCurrentColumn
- ? (tc & ToonzCheck::ePaint ? index : -1)
- : -1;
+ settings.m_paintIndex = m_nodes[i].m_isCurrentColumn
+ ? (tc & ToonzCheck::ePaint ? index : -1)
+ : -1;
+
settings.m_inkCheckEnabled = (tc & ToonzCheck::eInk) != 0;
settings.m_ink1CheckEnabled = (tc & ToonzCheck::eInk1) != 0;
settings.m_paintCheckEnabled = (tc & ToonzCheck::ePaint) != 0;
@@ -654,7 +672,7 @@ void RasterPainter::flushRasterImages() {
// Transparency Check: (see helper above)
// Apply high-tone empty pixel fix
// ==============================================================
- TRasterCM32P rasterToUse = srcCm; // default: original raster
+ TRasterCM32P rasterToUse = srcCm;
if (settings.m_transparencyCheck) {
const int threshold = 80; // Minimum tone for "false" high antialias
@@ -673,10 +691,10 @@ void RasterPainter::flushRasterImages() {
plt = TPaletteP();
m_nodes[i].m_palette->setFrame(oldframe);
- } else
+ } else {
assert(!"Cannot use quickput with this raster combination!");
+ }
}
-
if (m_vs.m_colorMask != 0) {
TRop::setChannel(ras, ras, m_vs.m_colorMask, false);
TRop::quickPut(ras2, ras, TAffine());
@@ -688,13 +706,13 @@ void RasterPainter::flushRasterImages() {
glEnable(GL_BLEND);
glBlendFunc(GL_ONE,
GL_ONE_MINUS_SRC_ALPHA); // The raster buffer is intended in
- // premultiplied form - thus the GL_ONE on src
+ // premultiplied form thus the GL_ONE on src
glDisable(GL_DEPTH_TEST);
glDisable(GL_DITHER);
glDisable(GL_LOGIC_OP);
-/* disable, since these features are never enabled, and cause OpenGL to assert
- * on systems that don't support them: see #591 */
+ /* disable, since these features are never enabled, and cause OpenGL to assert
+ * on systems that don't support them: see #591 */
#if 0
#ifdef GL_EXT_convolution
if( GLEW_EXT_convolution ) {
@@ -725,8 +743,8 @@ void RasterPainter::flushRasterImages() {
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glDrawPixels(ras2->getLx(), ras2->getLy(), // Perform the over
- TGL_FMT, TGL_TYPE, ras2->getRawData()); //
+ glDrawPixels(ras2->getLx(), ras2->getLy(), TGL_FMT, TGL_TYPE,
+ ras2->getRawData());
ras->unlock();
glPopMatrix();
@@ -833,10 +851,8 @@ static void drawAutocloses(TVectorImage *vi, TVectorRenderData &rd) {
//-----------------------------------------------------------------------------
/*! Take image from \b Stage::Player \b data and recall the right method for
- this kind of image, for vector image recall \b onVectorImage(),
- for raster
- image recall \b onRasterImage() for toonz image recall \b
- onToonzImage().
+this kind of image, for vector image recall \b onVectorImage(),for raster
+image recall \b onRasterImage() for toonz image recall \b onToonzImage().
*/
void RasterPainter::onImage(const Stage::Player &player) {
if (m_singleColumnEnabled && !player.m_isCurrentColumn) return;
@@ -874,18 +890,16 @@ void RasterPainter::onImage(const Stage::Player &player) {
//-----------------------------------------------------------------------------
/*! View a vector cell images.
\n If onion-skin is active compute \b TOnionFader value.
- Create and boot a \b TVectorRenderData and recall \b tglDraw().
+Create and boot a \b TVectorRenderData and recall \b tglDraw().
*/
void RasterPainter::onVectorImage(TVectorImage *vi,
const Stage::Player &player) {
flushRasterImages();
- // When loaded, vectorimages needs to have regions recomputed, but doing that
- // while loading them
- // is quite slow (think about loading whole scenes!..). They are recomputed
- // the first time they
- // are selected and shown on screen...except when playing back, to avoid
- // slowness!
+ // When loaded, vectorimages needs to have regions recomputed, but doing
+ // that while loading them is quite slow (think about loading whole
+ // scenes!..). They are recomputed the first time they are selected and
+ // shown on screen...except when playing back, to avoid slowness!
// (Daniele) This function should *NOT* be responsible of that.
// It's the *image itself* that should recalculate or initialize
@@ -965,8 +979,8 @@ void RasterPainter::onVectorImage(TVectorImage *vi,
(player.m_isGuidedDrawingEnabled == 2 && // show guides on farthest
(player.m_onionSkinDistance == player.m_onionSkinBackSize ||
player.m_onionSkinDistance == player.m_onionSkinFrontSize)) ||
- (player.m_isEditingLevel && // fix for level editing mode sending extra
- // players
+ (player.m_isEditingLevel && // fix for level editing mode sending
+ // extra players
player.m_isGuidedDrawingEnabled == 2 &&
player.m_onionSkinDistance == player.m_lastBackVisibleSkin)) {
rd.m_showGuidedDrawing = player.m_isGuidedDrawingEnabled > 0;
@@ -1396,8 +1410,8 @@ TStageObject *plasticDeformedObj(const Stage::Player &player,
}; // locals
if (pvs.m_applyPlasticDeformation && player.m_column >= 0) {
- // Check whether the player's column is a direct stage-schematic child of a
- // mesh object
+ // Check whether the player's column is a direct stage-schematic child of
+ // a mesh object
TStageObject *playerObj =
player.m_xsh->getStageObject(TStageObjectId::ColumnId(player.m_column));
assert(playerObj);
@@ -1632,8 +1646,8 @@ void onPlasticDeformedImage(TStageObject *playerObj,
const DrawableTextureDataP &texData = player.texture();
if (!texData) return;
- // Retrieve the associated plastic deformers data (this may eventually update
- // the deforms)
+ // Retrieve the associated plastic deformers data (this may eventually
+ // update the deforms)
const PlasticDeformerDataGroup *dataGroup =
PlasticDeformerStorage::instance()->process(
sdFrame, mi.getPointer(), deformation.getPointer(),
@@ -1663,8 +1677,7 @@ void onPlasticDeformedImage(TStageObject *playerObj,
glBlendFunc(GL_ONE, GL_ONE);
// Add Onion skin color. Observe that this way we don't consider blending
- // with the texture's
- // alpha - to obtain that, there is no simple way...
+ // with the texture's alpha to obtain that, there is no simple way...
double k = (1.0 - pixScale[3]);
glColor4d(k * pixScale[0], k * pixScale[1], k * pixScale[2], 0.0);