Coder Social home page Coder Social logo

Comments (9)

tekblom avatar tekblom commented on June 22, 2024

I can't get when it happends and it happends rarely. It seems to be randomly, but could happen when I open poups that not are on the map but is placed on top of it. These ones also get some data.

Sometimes it just crashes when I have it open. It feels like the views has been garbage collected or something. I have a lot of markers on my map, at least 100. And some objects that are moving on it.

from tileview.

tekblom avatar tekblom commented on June 22, 2024

Done some more digging.

I think the problem is when I remove a marker. My theory is that onMeasure in TranslationLayout is running and the view is removed while it is running measureChildren and then it have a discapency between mChildrenCount and the actual number of children (see http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/view/ViewGroup.java#ViewGroup.measureChildren%28int%2Cint%29).

Possible? I'm gonna look deeper into it tomorrow.

from tileview.

moagrius avatar moagrius commented on June 22, 2024

Hm... Of course I can't tell without seeing the code and debugging myself, but I'd be surprised if that were the issue. Almost all overridden onLayout/onMeasure methods I've seen do the same basic loop. Should be easy to tell, though - just wrap it in a try/catch or add a null check:

for (int i = 0; i < count; i++) {
  View child = getChildAt(i);
  if (child == null) continue;
  ...

or

for (int i = 0; i < count; i++) {
  try {
    View child = getChildAt(i);
    ...

Or maybe test the count in the evaluation expression, so instead of:

int count = getChildCount();
for (int i = 0; i < count; i++) {

You could try

for (int i = 0; i < getChildCount(); i++) {

I'd be interested to hear what you discover.

from tileview.

tekblom avatar tekblom commented on June 22, 2024

Yeah, I feel the same way. It feels a bit strange that there could be a syncronization problem there. Just a note, it mostly happends in:

TranslationLayout.java - onMeasure:

measureChildren(widthMeasureSpec, heightMeasureSpec);

ViewGroup.java

  protected void measureChildren(int widthMeasureSpec, int heightMeasureSpec) {
        final int size = mChildrenCount; // This one could be out of sync
        final View[] children = mChildren;
        for (int i = 0; i < size; ++i) {
            final View child = children[i]; // This probably returns null
            if ((child.mViewFlags & VISIBILITY_MASK) != GONE) {
                measureChild(child, widthMeasureSpec, heightMeasureSpec);
            }
        }
    }

I'm gonna do some testing now!

from tileview.

tekblom avatar tekblom commented on June 22, 2024

I'm not any closer.

I catch the NPE with a try around all code in onMeasure but then it fails in onLayout :/ And the state of the NPE didn't give me that much.. But I'm gonna try to write out the index of the child that is null.

Unfortunately I can't reproduce the error so it is really hard debugging.

New day tomorrow... Any ideas?

And I'm thinking, I have 150+ children. Does it not take relatively long time to loop them and couldn't one get removed and cause that nullpointer.. ? Feels unlikeley but a possability..

Thanks.

from tileview.

moagrius avatar moagrius commented on June 22, 2024

If wrapping onMeasure with try/catch pushed the NPE off to onLayout, it sounds like you're on the right track at least. I'd try those simple tricks above in both, and see what happens.

That said - notice that your stack trace shows the error on line 46 - line 46 is the call to measureChildren, which makes me think the NPE is not in the loop directly...

Regarding this:

And I'm thinking, I have 150+ children. Does it not take relatively long time to loop them and couldn't one get removed and cause that nullpointer.. ? Feels unlikeley but a possability..

I don't think so. I'm not 100% sure, but AFAIK, that could only happen if the two actions (onMeasure, and removal) happened in different threads.

To clarify: the NPE only happens when you remove markers?

from tileview.

tekblom avatar tekblom commented on June 22, 2024

I am actually not sure when it happends. It was my theory that it happened when I removed a marker.

I havn't yet found a way to trigger the error. That's the key. Will try removing add adding a lot tomorrow.

No, normally it is not direct in the loop. It is in the ViewGroup.java method measureChildren but if it passes that (for example with try catch) it causes the error in the loop.

I'm still confused how a child can be null...

from tileview.

moagrius avatar moagrius commented on June 22, 2024

post back if i can help

from tileview.

moagrius avatar moagrius commented on June 22, 2024

@tekblom did you get this worked out? or should i leave this issue open?

from tileview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.