CardStackView icon indicating copy to clipboard operation
CardStackView copied to clipboard

Crash from CardStackLayoutManager.updateScale: Cannot set `scaleX` to Float.NaN

Open damien5314 opened this issue 6 years ago โ€ข 11 comments

Hi, sorry if this has been logged before, but I couldn't find it in search ๐Ÿ˜„ We're seeing crash reports with the following stack trace:

Fatal Exception: java.lang.IllegalArgumentException: Cannot set 'scaleX' to Float.NaN
       at android.view.View.sanitizeFloatPropertyValue(View.java:16979)
       at android.view.View.sanitizeFloatPropertyValue(View.java:16953)
       at android.view.View.setScaleX(View.java:16342)
       at com.yuyakaido.android.cardstackview.CardStackLayoutManager.updateScale(CardStackLayoutManager.java:411)
       at com.yuyakaido.android.cardstackview.CardStackLayoutManager.update(CardStackLayoutManager.java:338)
       at com.yuyakaido.android.cardstackview.CardStackLayoutManager.onLayoutChildren(CardStackLayoutManager.java:50)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
       at androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1858)
       at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5044)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
       at android.view.Choreographer.doCallbacks(Choreographer.java:761)
       at android.view.Choreographer.doFrame(Choreographer.java:693)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:6981)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)

The integration with CardStackView & CardStackLayoutManager is not too complex:

swipeLayoutManager = new CardStackLayoutManager(requireContext(), this);
swipeLayoutManager.setStackFrom(StackFrom.Top);
swipeLayoutManager.setMaxDegree(30.0f);
swipeRecyclerView.setLayoutManager(swipeLayoutManager);

if (savedInstanceState != null) {
    final int currentPosition = savedInstanceState.getInt(STATE_CARD_POSITION);
    swipeLayoutManager.scrollToPosition(currentPosition);
}

I don't know if I can post the full layout for our ViewHolders, but based on the stacktrace it doesn't seem like anything in our layout would be causing this? Let me know if you think that would be helpful and I'll see what I can do ๐Ÿ‘

The line causing the crash is here:

https://github.com/yuyakaido/CardStackView/blob/b1b6053b7d0649189a1443fded2d7df70e7e4527/cardstackview/src/main/java/com/yuyakaido/android/cardstackview/CardStackLayoutManager.java#L420

Somehow targetScale is being calculated to Float.NaN. It's not really clear to me how that's possible. Does it make sense to sanitize the value calculated before passing into setScaleX?

damien5314 avatar May 13 '19 17:05 damien5314

P.S. I can give this fix a try if you think that's a good approach ๐Ÿ˜„

damien5314 avatar May 13 '19 17:05 damien5314

Update: It seems this crash is specific to Android 9 devices ๐Ÿค”

damien5314 avatar May 15 '19 15:05 damien5314

Sorry, one more update, but good news ๐Ÿ˜… I figured out that this happens when triggering smooth scroll on a CardStackView that isn't actually visible (View.GONE). This wasn't something we did intentionally, and so fixed it.

That said, the possibility of Float.NaN in the setScaleX call might be something we can guard against in this library. I'll let you decide if that makes sense ๐Ÿ‘ If not, we can probably close this.

damien5314 avatar May 15 '19 17:05 damien5314

I'm having this issue as well

olucurious avatar Jun 06 '19 19:06 olucurious

I met this error now. I using an old version 1.0.0-beta5. Is this error appear on latest version @damien5314 ?

trunghdo avatar Jun 24 '19 09:06 trunghdo

The same issue facing with AndroidX Dependency,

java.lang.IllegalArgumentException: Cannot set 'scaleX' to Float.NaN at android.view.View.sanitizeFloatPropertyValue(View.java:15446) at android.view.View.sanitizeFloatPropertyValue(View.java:15420) at android.view.View.setScaleX(View.java:14809) at com.yuyakaido.android.cardstackview.CardStackLayoutManager.updateScale(CardStackLayoutManager.java:433) at com.yuyakaido.android.cardstackview.CardStackLayoutManager.update(CardStackLayoutManager.java:348) at com.yuyakaido.android.cardstackview.CardStackLayoutManager.onLayoutChildren(CardStackLayoutManager.java:51) at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4115) at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3832) at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4385) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) at android.widget.LinearLayout.onLayout(LinearLayout.java:1565) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1801) at android.widget.LinearLayout.onLayout(LinearLayout.java:1567) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) at android.widget.LinearLayout.onLayout(LinearLayout.java:1565) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) at android.widget.LinearLayout.onLayout(LinearLayout.java:1565) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) at android.widget.LinearLayout.onLayout(LinearLayout.java:1565) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656) at android.widget.LinearLayout.onLayout(LinearLayout.java:1565) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:757) at android.view.View.layout(View.java:20699) at android.view.ViewGroup.layout(ViewGroup.java:6198)

masheransari avatar Aug 27 '19 16:08 masheransari

@yuyakaido any chance to look at this? I can make a pull request if needed.

@damien5314 I had something similar, was wrapping the size of CardStackView, that obviously wouldn't inflate anything and thus, will return 0 value dimensions.

GitMoDu avatar Feb 28 '20 16:02 GitMoDu

Hi Guys,

I'm having the same issue when trying to press like or dislike button rapidly. This crash is causing a bad user experience for my application. Any suggestions regarding the fix?

Thanks in advance

deepakthumbmunkeys avatar Jun 19 '20 05:06 deepakthumbmunkeys

Hi Guys,

I'm having the same issue when trying to press like or dislike button rapidly. This crash is causing a bad user experience for my application. Any suggestions regarding the fix?

Thanks in advance

You can try setting a definite layout_width and layout_height. Don't use wrap_content. Fixed the issue in my case.

anubhav11march avatar Jun 26 '20 18:06 anubhav11march

I have the same error

akerimtay avatar May 23 '22 09:05 akerimtay

Try to use match_parent for the layout_width and layout_height of the card stack view.

JMS1208 avatar Aug 06 '22 12:08 JMS1208