Unverified Commit a69567a3 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Asserts if a `TextPainter` gets disposed more than once (#145124)

The overflow indicator was sharing the same `TextPainter`.
parent 51d59a7d
...@@ -1659,6 +1659,7 @@ class TextPainter { ...@@ -1659,6 +1659,7 @@ class TextPainter {
/// ///
/// After disposal this painter is unusable. /// After disposal this painter is unusable.
void dispose() { void dispose() {
assert(!debugDisposed);
assert(() { assert(() {
_disposed = true; _disposed = true;
return true; return true;
......
...@@ -109,9 +109,10 @@ mixin DebugOverflowIndicatorMixin on RenderObject { ...@@ -109,9 +109,10 @@ mixin DebugOverflowIndicatorMixin on RenderObject {
); );
static final Paint _labelBackgroundPaint = Paint()..color = const Color(0xFFFFFFFF); static final Paint _labelBackgroundPaint = Paint()..color = const Color(0xFFFFFFFF);
final List<TextPainter> _indicatorLabel = List<TextPainter>.filled( final List<TextPainter> _indicatorLabel = List<TextPainter>.generate(
_OverflowSide.values.length, _OverflowSide.values.length,
TextPainter(textDirection: TextDirection.ltr), // This label is in English. (int i) => TextPainter(textDirection: TextDirection.ltr), // This label is in English.
growable: false,
); );
@override @override
......
...@@ -1429,6 +1429,12 @@ void main() { ...@@ -1429,6 +1429,12 @@ void main() {
expect(painter.debugDisposed, true); expect(painter.debugDisposed, true);
}); });
test('TextPainter - asserts if disposed more than once', () {
final TextPainter painter = TextPainter()..dispose();
expect(painter.debugDisposed, isTrue);
expect(painter.dispose, throwsAssertionError);
});
test('TextPainter computeWidth', () { test('TextPainter computeWidth', () {
const InlineSpan text = TextSpan(text: 'foobar'); const InlineSpan text = TextSpan(text: 'foobar');
final TextPainter painter = TextPainter(text: text, textDirection: TextDirection.ltr); final TextPainter painter = TextPainter(text: text, textDirection: TextDirection.ltr);
......
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