Open NagisaKaworu opened 6 years ago
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
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.
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: https://github.com/bgogetap/StickyHeaders/issues/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.