Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table is stuck in an infinite loop sometimes #27083

Closed
MihaMarkic opened this issue Jan 25, 2019 · 14 comments · Fixed by #27112
Closed

Table is stuck in an infinite loop sometimes #27083

MihaMarkic opened this issue Jan 25, 2019 · 14 comments · Fixed by #27112
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Comments

@MihaMarkic
Copy link

MihaMarkic commented Jan 25, 2019

Steps to Reproduce

  1. Create a Table with two rows and 6 columns, all containing a Text widget.
  2. When it is supposed to be displayed as child of a DefaultTabController->Scaffold->TabBarView it might get stuck in an infinite loop.
  3. I'll describe where and how it is stuck below

It gets stuck in RenderTable._computeColumnWidths method, specifically in this while loop:

int availableColumns = columns;
      while (deficit > 0.0 && totalFlex > 0.0) {
        double newTotalFlex = 0.0;
        for (int x = 0; x < columns; x += 1) {
          if (flexes[x] != null) {
            final double newWidth = widths[x] - deficit * flexes[x] / totalFlex;
            assert(newWidth.isFinite);
            if (newWidth <= minWidths[x]) {
              // shrank to minimum
              deficit -= widths[x] - minWidths[x];
              widths[x] = minWidths[x];
              flexes[x] = null;
              availableColumns -= 1;
            } else {
              deficit -= widths[x] - newWidth;
              widths[x] = newWidth;
              newTotalFlex += flexes[x];
            }
            assert(widths[x] >= 0.0);
          }
        }
        totalFlex = newTotalFlex;
      }

The problem is that deficit is a really small value 2.842170943040401e-14 and it won't get to or below 0.
Other values are:

widths: [65.9047619047619, 65.9047619047619, 65.90476190476191, 65.90476190476191, 65.90476190476191, 65.90476190476191]
minWidths: [0, 0, 0, 0, 0, 0]
flexes: [1, 1, 1, 1, 1, 1]
totalFlex: 6

Basically newWidth <= minWidths[x] is always false and deficit doesn't decrease because widths[x] - newWidth is always 0.

This problem happens only on some screens and it is consistent when it starts (i.e. works on emulator and not on device - Nexus 6, or the other way round).

Logs

No useful logs (when it gets stuck nothing is reported).

No issues found! (ran in 3.4s)

[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.17763.253], locale sl-SI)  
    • Flutter version 1.0.0 at D:\SDK\flutter                                                      
    • Framework revision 5391447fae (8 weeks ago), 2018-11-29 19:41:26 -0800                       
    • Engine revision 7375a0f414                                                                   
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)                                          
                                                                                                   
[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)                           
    • Android SDK at C:\Users\miha\AppData\Local\Android\sdk                                       
    • Android NDK location not configured (optional; useful for native profiling support)          
    • Platform android-28, build-tools 28.0.3                                                      
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java                         
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)                  
    • All Android licenses accepted.                                                               
                                                                                                   
[√] Android Studio (version 3.3)                                                                   
    • Android Studio at C:\Program Files\Android\Android Studio                                    
    X Flutter plugin not installed; this adds Flutter specific functionality.                      
    X Dart plugin not installed; this adds Dart specific functionality.                            
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)                  
                                                                                                   
[√] VS Code (version 1.30.2)                                                                       
    • VS Code at C:\Users\miha\AppData\Local\Programs\Microsoft VS Code                            
    • Flutter extension version 2.21.1                                                             
                                                                                                   
[√] Connected device (2 available)                                                                 
    • Nexus 6                   • ZX1G4256JM    • android-arm • Android 7.1.1 (API 25)             
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)  
                                                                                                   
• No issues found!                                                                                 
@MihaMarkic MihaMarkic changed the title TableView is stuck in an infinite loop sometimes Table is stuck in an infinite loop sometimes Jan 25, 2019
@MihaMarkic
Copy link
Author

Looks similar to #23723
Hopefully additional data (variables values) I provided will help

@zoechi
Copy link
Contributor

zoechi commented Jan 25, 2019

Do you also get an exception?

@zoechi zoechi added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jan 25, 2019
@zoechi zoechi added this to the Goals milestone Jan 25, 2019
@MihaMarkic
Copy link
Author

MihaMarkic commented Jan 25, 2019

@zoechi No, it just loops infinitely because the condition is never satisfied (rounding with doubles problem, I guess).

@MihaMarkic
Copy link
Author

And of course, app becomes unresponsive due to this loop.

@MihaMarkic
Copy link
Author

Also, I'd push fix for this one sooner, not just "Goals" in coming years. Not because of me, well, also, but because this bug is insidious and happens only on certain screen size combinations. Imagine having an app in production and it becomes unresponsive for random customers/devices without any feedback.

@zoechi
Copy link
Contributor

zoechi commented Jan 25, 2019

@jason-simmons ?

@jason-simmons
Copy link
Member

@Hixie

@jonahwilliams
Copy link
Member

We've had similar rounding issues in slivers, we should use a small delta for our while-loop

@jonahwilliams
Copy link
Member

I was able to reproduce this almost immediately, will have PR up shortly

@MihaMarkic
Copy link
Author

Instead of using a small delta (how small should be the challenge - are you sure it will cover all values?), perhaps you might consider checking whether deficit changed in a last loop, or something slightly more reliable.

@jonahwilliams
Copy link
Member

Feel free to comment on PR

@zoechi
Copy link
Contributor

zoechi commented Jan 29, 2019

Looks similar to #23723

Seems different because #27112 doesn't fix it.

@MihaMarkic
Copy link
Author

@zoechi You're right, that's different.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants