CardStackView
CardStackView copied to clipboard
Crash from CardStackLayoutManager.updateScale: Cannot set `scaleX` to Float.NaN
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?
P.S. I can give this fix a try if you think that's a good approach ๐
Update: It seems this crash is specific to Android 9 devices ๐ค
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.
I'm having this issue as well
I met this error now. I using an old version 1.0.0-beta5. Is this error appear on latest version @damien5314 ?
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)
@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.
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
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.
I have the same error
Try to use match_parent for the layout_width and layout_height of the card stack view.