-
Notifications
You must be signed in to change notification settings - Fork 396
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 in ParticleField.onDraw #19
Comments
Thanks for the heads up. Surprisingly enough I have never seen this crash myself, but by looking at the stack trace and your explanation I must have just been lucky. How do you manage to replicate it? It may be dependant on the Android version. |
No problem. It's a great library and really saved me some time apart from this small issue. My test device is running 4.4.2. I'm creating the ParticleSystem like so...
In my parent view's onSizeChanged function I do the following to ensure the particles emit from the center on the view...
I'm also running some other animations within the parent view which cause frequent invalidates. All I have to do to see the crash is sit and let it run. Sometimes it happens immediately, sometimes it takes a couple minutes. It seems to happen a bit faster if I change the orientation (landscape<>portrait) of the device a few times to cause the view to resize & invalidate. I quickly worked around it by adding a synchronized(mActiveParticles) {} block in ParticleSystem.onUpdate, and a synchronized (mParticles) {} in ParticleField.onDraw. No more crashes. |
It could be that on rotation some particles are "lost" but definitely, I'm Thanks for the heads up! On Fri, 24 Apr 2015 6:13 pm kibantony notifications@github.com wrote:
|
There is a concurrency problem that is causing constant repeatable crashes. I've traced the issue to the fact that ParticleSystem.onUpdate is called via a Timer on a non-UI thread where it changes the contents of the mActiveParticles array. Meanwhile, the ParticleField view is accessing the same array to draw the particles on the UI thread, leading to the crash. A quick fix would be synchronize on the array to alleviate the contention, or use a Handler or similar mechanism to schedule the onUpdate operation on the UI thread.
The text was updated successfully, but these errors were encountered: