From cd73f4378c66a220b26cf38e68e5d2ba29d82cdb Mon Sep 17 00:00:00 2001 From: ColdPaleLight Date: Mon, 18 Jul 2022 13:00:04 +0800 Subject: [PATCH] Tweak the condition of 'FML_DCHECK' to solve the issue caused by round-off error (flutter/engine#34660) --- engine/src/flutter/flow/raster_cache.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/flow/raster_cache.cc b/engine/src/flutter/flow/raster_cache.cc index 74bdd619b04..e603a37d766 100644 --- a/engine/src/flutter/flow/raster_cache.cc +++ b/engine/src/flutter/flow/raster_cache.cc @@ -34,8 +34,17 @@ void RasterCacheResult::draw(SkCanvas& canvas, const SkPaint* paint) const { SkRect bounds = RasterCacheUtil::GetDeviceBounds(logical_rect_, canvas.getTotalMatrix()); - FML_DCHECK(std::abs(bounds.width() - image_->dimensions().width()) <= 1 && - std::abs(bounds.height() - image_->dimensions().height()) <= 1); +#ifndef NDEBUG + // The image dimensions should always be larger than the device bounds and + // smaller than the device bounds plus one pixel, at the same time, we must + // introduce epsilon to solve the round-off error. The value of epsilon is + // 1/512, which represents half of an AA sample. + float epsilon = 1 / 512.0; + FML_DCHECK(image_->dimensions().width() - bounds.width() > -epsilon && + image_->dimensions().height() - bounds.height() > -epsilon && + image_->dimensions().width() - bounds.width() < 1 + epsilon && + image_->dimensions().height() - bounds.height() < 1 + epsilon); +#endif canvas.resetMatrix(); flow_.Step(); canvas.drawImage(image_, bounds.fLeft, bounds.fTop, SkSamplingOptions(),