Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"resultIndex is -1, the polygon must be invalid!" after addView()

I get an exception after calling addView() method on ViewGroup (FrameLayout).

public final View createView(Context context, Property property, ViewGroup parent) {
        mView = LayoutInflater.from(context).inflate(getLayout(), null);
        mContext = context;
        mProperty = property;
        processBaseViews(mView, property);
        processViews(mView, property);
        parent.addView(mView);
        return mView;
    }

Exception:

10-17 18:39:40.060: E/OpenGLRenderer(511): resultIndex is -1, the polygon must be invalid!
10-17 18:39:40.061: A/libc(511): Fatal signal 7 (SIGBUS), code 1, fault addr 0x136 in tid 726 (hwuiTask1)

This code works normally on Android Lollipop (SDK <= 22), but closes with error on Android Marshmallow (SDK 23). How can I solve this problem?

like image 309
Ivan Sadovyi Avatar asked Oct 17 '15 15:10

Ivan Sadovyi


Video Answer


2 Answers

I was receiving the same error also same case, the code works fine in api<23 only crashes on api 23 what I found is in my code i was setting custom animation to a fragment BEFORE replace.() but after FIRST replacing and THEN setting custom animation just worked for me. here is my code snippet

    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.replace(R.id.fragment_container, fragment);
    transaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
    transaction.commit();
like image 183
Kalpit Champanery Avatar answered Nov 15 '22 04:11

Kalpit Champanery


This bug happens when you try to start animating a view that isn't attached to the layout yet.

However, there seems to be a missed corner where in certain cases in API 23 (Marshmellow), when you try to animate a certain views with elevation set, it will close the app no matter what.

Let's say the following is your current code:

<FrameLayout
   android:id="@+id/container"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:elevation="@dimen/custom_elevation" />
   container.animate()
            .scaleX(1f)
            .scaleY(1f)
            .setListener(null)
            .start();

In that case, you have couple options for the workaround:

  1. Remove elevation from the view
  2. Remove animation that contains elevation
  3. Remove elevation just for API 23
  4. Remove animation just for API 23
  5. Remove elevation temporarily and add the elevation back after the animation finishes:
<FrameLayout
   android:id="@+id/container"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content" />
   container.animate()
            .scaleX(1f)
            .scaleY(1f)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    final float elevation = container.getDimension(R.dimen.custom_elevation);
                    container.setElevation(elevation);
                }
            })
            .start();
like image 26
Jaden Avatar answered Nov 15 '22 03:11

Jaden