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

Crash when mutating SquaringDrawable (getConstantState is not overridden) - v3.5.2 #349

Closed
alex2069 opened this issue Feb 23, 2015 · 2 comments
Labels
Milestone

Comments

@alex2069
Copy link

If an ImageView has something that has its (internal) mColorMod field set to true (i.e. there is an alpha or color filter set - see ImageView.applyColorMod()), then when Glide updates the image view providing the TransitionDrawable (the current drawable + SquaringDrawable), the image view attempts to mutate it and crashes (NPE) when calling SquaringDrawable.getConstantState().

Trace from Genymotion v4.4.2

    java.lang.NullPointerException
            at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:671)
            at android.graphics.drawable.TransitionDrawable$TransitionState.<init>(TransitionDrawable.java:249)
            at android.graphics.drawable.TransitionDrawable.createConstantState(TransitionDrawable.java:101)
            at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:608)
            at android.widget.ImageView.applyColorMod(ImageView.java:1216)
            at android.widget.ImageView.updateDrawable(ImageView.java:716)
            at android.widget.ImageView.setImageDrawable(ImageView.java:421)
            at com.bumptech.glide.request.target.ImageViewTarget.setDrawable(ImageViewTarget.java:37)
            at com.bumptech.glide.request.animation.DrawableCrossFadeViewAnimation.animate(DrawableCrossFadeViewAnimation.java:49)
            at com.bumptech.glide.request.animation.DrawableCrossFadeViewAnimation.animate(DrawableCrossFadeViewAnimation.java:14)
            at com.bumptech.glide.request.target.ImageViewTarget.onResourceReady(ImageViewTarget.java:75)
            at com.bumptech.glide.request.target.GlideDrawableImageViewTarget.onResourceReady(GlideDrawableImageViewTarget.java:66)
            at com.bumptech.glide.request.target.GlideDrawableImageViewTarget.onResourceReady(GlideDrawableImageViewTarget.java:12)
            at com.bumptech.glide.request.GenericRequest.onResourceReady(GenericRequest.java:499)
            at com.bumptech.glide.request.GenericRequest.onResourceReady(GenericRequest.java:486)
            at com.bumptech.glide.load.engine.EngineJob.handleResultOnMainThread(EngineJob.java:158)
            at com.bumptech.glide.load.engine.EngineJob.access$100(EngineJob.java:22)
            at com.bumptech.glide.load.engine.EngineJob$MainThreadCallback.handleMessage(EngineJob.java:202)
            at android.os.Handler.dispatchMessage(Handler.java:98)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
@alex2069 alex2069 changed the title Crash when mutating SquaringDrawable (getConstantState is not overridden correclty) - v3.5.2 Crash when mutating SquaringDrawable (getConstantState is not overridden) - v3.5.2 Feb 23, 2015
@sjudd
Copy link
Collaborator

sjudd commented Feb 23, 2015

Thanks for the report, any chance you can add a few lines of example code that will reproduce the problem?

@sjudd sjudd added the bug label Feb 24, 2015
@alex2069
Copy link
Author

MainActivity

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        final ImageView imgView = (ImageView) findViewById(R.id.main_img);
        imgView.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY));

        findViewById(R.id.main_click_to_crash).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uri = Uri.parse("http://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Square_-_black_simple.svg/200px-Square_-_black_simple.svg.png");
                Glide.with(MainActivity.this)
                        .load(uri)
                        .placeholder(R.drawable.glide_logo)
                        .into(imgView);
            }
        });
    }

Layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:paddingLeft="@dimen/activity_horizontal_margin"
              android:paddingRight="@dimen/activity_horizontal_margin"
              android:paddingTop="@dimen/activity_vertical_margin"
              android:paddingBottom="@dimen/activity_vertical_margin"
              tools:context=".MainActivity"
              android:orientation="vertical">

    <Button
            android:id="@+id/main_click_to_crash"
            android:layout_width="100dp"
            android:text="Click to crash"
            android:layout_height="wrap_content"
            tools:ignore="HardcodedText"/>

    <ImageView
            android:id="@+id/main_img"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:contentDescription="@null"/>

</LinearLayout>

The R.drawable.glide_logo was just the logo in the Glide read me heh.

Here is a demo project: https://www.dropbox.com/s/6yg6zk5qt3ibp95/glide-mutate-crash.zip?dl=0

@sjudd sjudd closed this as completed in 4a8c58f Mar 2, 2015
@sjudd sjudd added this to the 3.6.0 milestone Mar 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants