Unverified Commit f57fcac7 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Clear the static _debugDoingBaseline flag if baseline calculation throws (#110387)

parent 728bd65b
......@@ -2191,8 +2191,12 @@ abstract class RenderBox extends RenderObject {
return false;
}());
assert(_debugSetDoingBaseline(true));
final double? result = getDistanceToActualBaseline(baseline);
assert(_debugSetDoingBaseline(false));
final double? result;
try {
result = getDistanceToActualBaseline(baseline);
} finally {
assert(_debugSetDoingBaseline(false));
}
if (result == null && !onlyReal) {
return size.height;
}
......
......@@ -36,6 +36,18 @@ class MissingSetSizeRenderBox extends RenderBox {
void performLayout() { }
}
class BadBaselineRenderBox extends RenderBox {
@override
void performLayout() {
size = constraints.biggest;
}
@override
double? computeDistanceToActualBaseline(TextBaseline baseline) {
throw Exception();
}
}
void main() {
TestRenderingFlutterBinding.ensureInitialized();
......@@ -1196,6 +1208,27 @@ void main() {
),
);
});
test('debugDoingBaseline flag is cleared after exception', () {
final BadBaselineRenderBox badChild = BadBaselineRenderBox();
final RenderBox badRoot = RenderBaseline(
child: badChild,
baseline: 0.0,
baselineType: TextBaseline.alphabetic,
);
final List<dynamic> exceptions = <dynamic>[];
layout(badRoot, onErrors: () {
exceptions.addAll(TestRenderingFlutterBinding.instance.takeAllFlutterExceptions());
});
expect(exceptions, isNotEmpty);
final RenderBox goodRoot = RenderBaseline(
child: RenderDecoratedBox(decoration: const BoxDecoration()),
baseline: 0.0,
baselineType: TextBaseline.alphabetic,
);
layout(goodRoot, onErrors: () { assert(false); });
});
}
class _DummyHitTestTarget implements HitTestTarget {
......
Markdown is supported
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