plattysoft / Leonids

A Particle System for standard Android UI: http://plattysoft.github.io/Leonids/
Apache License 2.0
2.28k stars 398 forks source link

NPE #99

Open ryust opened 6 years ago

ryust commented 6 years ago

Is this library being maintained? It seems issues are reported, but not fixed. Every once in awhile my app gets a NPE with the library.

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.postInvalidate()' on a null object reference at com.plattysoft.leonids.ParticleSystem.onUpdate(ParticleSystem.java:683) at com.plattysoft.leonids.ParticleSystem.access$100(ParticleSystem.java:38) at com.plattysoft.leonids.ParticleSystem$ParticleTimerTask.run(ParticleSystem.java:82) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505)

plattysoft commented 6 years ago

It is watched, but so far there has been no need to maintain it. It seems that every crash report on something like that was a misuse coming for a misunderstanding of how it should be used (and I do agree that it is lacking detailed documentation)

Fell free to fix it and submit a PR.

ryust commented 6 years ago

So an NPE within the library's internal code is considered a misuse? How can that be? What is the misuse in the above stacktrace?

plattysoft commented 6 years ago

Maybe I did not express myself correctly.

As far as I know, all the logged issues on github are linked to wrong usage of the library.

I can not tell what you are doing from a stacktrace, without steps to replicate I can't really find or solve the issue.

You can get plenty of NPE on Android and that is not an issue of the framework (i.e. calling getActivity on a detached fragment)

If you give me steps to replicate, I can look into it, just with a stack trace there's not much I can do.

And finally, as I said, I am happy to accept contributions, so if you want to dig into it and submit a PR with a fix I'll be happy to merge it in.

ryust commented 6 years ago

As I indicated, the NPE is random and rare... similar to previous reports. The problem was already documented in issue #43 with a user supplied fix. Since the stacktrace (supplied by Crashlytics) doesn't go deep enough to highlight where in my code it starts, I cannot give a reliable example. The app just has a couple simple onetime particle emits... and the same code works most of the time except for a rare NPE.

Maybe at a minimum wrap the onUpdate in a try/catch to more gracefully handle the NPE regardless of the cause?

plattysoft commented 6 years ago

Feel free to do a patch, try it and it resolved the problem we can integrate it. As you can see in the code https://github.com/plattysoft/Leonids/blob/fa10427528adb6810540eb3524f61feffbce4e48/LeonidsLib/src/main/java/com/plattysoft/leonids/ParticleSystem.java#L78

The particle system weak reference is only accessed if it is not null, even more, the fact that the previous line executes means that the reference is not null.

Can the reference be turned null between those 2 lines? I can't see how, but as I said, feel free to wrap it on a try/catch and see if that solves the problem. I am reluctant to add something like that to a release just for you to try it out without being sure what is causing it. It may as well surface somewhere else.