google / blockly-android

Blockly for Android
Apache License 2.0
672 stars 209 forks source link

Crash-Connect block from left to right, more than 8 will crash #681

Closed stronger1990 closed 6 years ago

stronger1990 commented 6 years ago

Connect block from left to right, if blocks more than 8 will crash. 10-25 21:16:30.366 14006-14006/com.strong E/AndroidRuntime: FATAL EXCEPTION: main Process: com.strong, PID: 14006 java.lang.StackOverflowError at java.lang.String._getChars(String.java:942) at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:148) at java.lang.StringBuilder.append(StringBuilder.java:216) at android.view.View.getDisplayList(View.java:13508) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3070) at com.google.blockly.android.ui.vertical.BlockView.dispatchDraw(BlockView.java:145) at android.view.View.draw(View.java:14750) at android.view.View.getDisplayList(View.java:13599) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3090) at android.view.View.getDisplayList(View.java:13591) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3070) at android.view.View.getDisplayList(View.java:13591) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3070) at com.google.blockly.android.ui.vertical.BlockView.dispatchDraw(BlockView.java:145) at android.view.View.draw(View.java:14750) at android.view.View.getDisplayList(View.java:13599) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3090) at android.view.View.getDisplayList(View.java:13591) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3070) at android.view.View.getDisplayList(View.java:13591) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3070) at com.google.blockly.android.ui.vertical.BlockView.dispatchDraw(BlockView.java:145) at android.view.View.draw(View.java:14750) at android.view.View.getDisplayList(View.java:13599) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3090) at android.view.View.getDisplayList(View.java:13591) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3070) at android.view.View.getDisplayList(View.java:13591) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3070) at com.google.blockly.android.ui.vertical.BlockView.dispatchDraw(BlockView.java:145) at android.view.View.draw(View.java:14750) at android.view.View.getDisplayList(View.java:13599) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3090) at android.view.View.getDisplayList(View.java:13591) at android.view.View.getDisplayList(View.java:13646) at android.view.View.draw(View.java:14441) at android.view.ViewGroup.drawChild(ViewGroup.java:3252) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3070) at android.view.View

AnmAtAnm commented 6 years ago

@stronger1990 What device and OS version is this? I was able to chain 19 blocks from left to right and never saw a crash or any other error message in logcat.

Did any of your blocks also belong to a vertical group? That would also affect the view depth.

Can you try it with some simple block like the math square root block? It both inputs and outputs a number, so a good example for this test.

Possibly related to #179, though the forty block limit there is still much larger than the 8 listed here.

AnmAtAnm commented 6 years ago

Okay. I've been able to recreate this on KitKat API 19 emulator, but was not able to reproduce this on Lollipop API 22 (29 blocks and counting). Since KitKat is when ART was introduced and Lollipop is when it was made standard, I believe this is a case of #179 but we have somehow made the method stack larger per block, thus reducing the possible block stack.

Unfortunately, this is not a bug I can prioritize at this point. If you want to attempt to address this, I would focus identifying the depth early and just don't allow stacks that deep (with some user notification).

The correct solution is to flatten the view hierarchy by parenting all blocks directly to the workspace (or temporary draggable views). This is a major rewrite of our code to support this, with limited benefit given the vast majority of users are on ART capable devices.

stronger1990 commented 6 years ago

Dear Andrew n marshall, I was busy before, so I didn't respond to you in time, I'm sorry for that. Now I kown the reason. Thank you very much for your answer.