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 with NullPointerException when soft keyboard is shown or hidden while animation is running #91

Open
NagisaKaworu opened this issue Feb 1, 2018 · 2 comments

Comments

@NagisaKaworu
Copy link

The app I'm working on crashes with NullPointerException with no links to the code in the app when soft keyboard is shown or hidden while the animation is running. The stacktrace starts from android.widget.FrameLayout.layoutChildren(FrameLayout.java:405).

The animation is bound to a RecyclerView.ViewHolder, and the RecyclerView is in a RelativeLayout.

When I googled the issue the closest cases I found were these:
bgogetap/StickyHeaders#23
https://stackoverflow.com/questions/21864041/calling-viewgroupaddview-and-viewgroupremoveview-causes-nullpointerexception

At the moment I cancel animation in onClick on an EditView (the only case when the keyboard is shown) and onBackPressed, but that is a crutch and I'd like to have a permanent solution if that's possible.

@plattysoft
Copy link
Owner

cancel does stop and delete all the resources, if you try to start the animation again without creating the ParticleSystem again, you'll get a NPE

Maybe try calling "stopEmitting" instead

@NagisaKaworu
Copy link
Author

Cancel isn't the problem, it's the temporary solution, exactly because it stops and deletes everything before it can crash. NPE happens when soft keyboard is shown or hidden while the animation is running.

For a better context. I'm using ParticleSystem in a chat application as an Ester Egg attached to specific stickers. The chat component is a RecyclerView, and the specific messages are in RecyclerView.ViewHolders, to which I attach an object with an array of ParticleSystems and configs. When the ViewHolder is bound I check if the configs correspond to the specific message and initialise the animation if necessary. I never restart it. The number of ViewHolders used by the system is limited, so although all or most of them have the animation handler objects I have to feed them new configs and init the ParticleSystems from scratch every time a holder of particular kind is bound. All I consciously do to the running animation is update emit point on scroll.

Now, NPE happens when a user triggers soft keyboard. So either they scrolled the chat so some of the animated stickers got bound and started emitting or someone sent them an animated sticker, and the user tapped the input field within 2000 ms after that, or they sent a sticker and then closed the keyboard within 2000 ms. Then the app crashes with NPE with only system classes in the stacktrace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants