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

(Android) RN 0.54 Exception "local reference table overflow (max=512)" #229

Closed
kyle-ssg opened this issue Mar 8, 2018 · 8 comments
Closed

Comments

@kyle-ssg
Copy link

kyle-ssg commented Mar 8, 2018

Getting the above error using React Native Version 0.54 when rendering over 512 points on a LineChart.

I can confirm that this does not happen on react-native 0.53.0

@kyle-ssg kyle-ssg changed the title (Android) RN 0.54 - Rendering over 512 points - local reference table overflow (max=512) (Android) RN 0.54 Exception "local reference table overflow (max=512)" Mar 8, 2018
@wuxudong
Copy link
Owner

wuxudong commented Mar 9, 2018

It is react-native related.

It crash at if (ReadableType.Map.equals(values.getType(index))) in LineDataExtract.createEntry

 @Override
    Entry createEntry(ReadableArray values, int index) {
        float x = index;

        Entry entry;
        if (ReadableType.Map.equals(values.getType(index))) {
            ReadableMap map = values.getMap(index);
            if (map.hasKey("x")) {
                x = (float) map.getDouble("x");
            }
            entry = new Entry(x, (float) map.getDouble("y"), ConversionUtil.toMap(map));
        } else if (ReadableType.Number.equals(values.getType(index))) {
            entry = new Entry(x, (float) values.getDouble(index));
        } else {
            throw new IllegalArgumentException("Unexpected entry type: " + values.getType(index));
        }

        return entry;
    }

ReadableNativeArray.getType is totally different between 0.53.0 and 0.54.0 .

here is 0.53.0 , it only care the type at the index.

ReadableNativeArray.java

 public native ReadableType getType(int index);

ReadableNativeArray.cpp

local_ref<ReadableType> ReadableNativeArray::getType(jint index) {
  return ReadableType::getType(array_.at(index).type());
}

ReadableType.cpp

local_ref<ReadableType> ReadableType::getType(folly::dynamic::Type type) {
  switch (type) {
    case folly::dynamic::Type::NULLT: {
      static alias_ref<ReadableType> val = getTypeField("Null");
      return make_local(val);
    }
    case folly::dynamic::Type::BOOL: {
      static alias_ref<ReadableType> val = getTypeField("Boolean");
      return make_local(val);
    }
    case folly::dynamic::Type::DOUBLE:
    case folly::dynamic::Type::INT64: {
      static alias_ref<ReadableType> val = getTypeField("Number");
      return make_local(val);
    }
    case folly::dynamic::Type::STRING: {
      static alias_ref<ReadableType> val = getTypeField("String");
      return make_local(val);
    }
    case folly::dynamic::Type::OBJECT: {
      static alias_ref<ReadableType> val = getTypeField("Map");
      return make_local(val);
    }
    case folly::dynamic::Type::ARRAY: {
      static alias_ref<ReadableType> val = getTypeField("Array");
      return make_local(val);
    }
    default:
      throwNewJavaException(exceptions::gUnexpectedNativeTypeExceptionClass, "Unknown type");
  }
}

but in 0.54.0

ReadableNativeArray.java

@Override
public ReadableType getType(int index) {
  if (mUseNativeAccessor) {
    jniPassCounter++;
    return getTypeNative(index);
  }
  return getLocalTypeArray()[index];
}


private ReadableType[] getLocalTypeArray() {
  // Fast, non-blocking check for the common case
  if (mLocalTypeArray != null) {
    return mLocalTypeArray;
  }
  synchronized (this) {
    // Make sure no concurrent call already updated
    if (mLocalTypeArray == null) {
      jniPassCounter++;
      Object[] tempArray = Assertions.assertNotNull(importTypeArray());
      mLocalTypeArray = Arrays.copyOf(tempArray, tempArray.length, ReadableType[].class);
    }
  }
  return mLocalTypeArray;
}

ReadableNativeArray.cpp

local_ref<JArrayClass<jobject>> ReadableNativeArray::importTypeArray() {
  jint size = array_.size();
  auto jarray = JArrayClass<jobject>::newArray(size);
  for (jint i = 0; i < size; i++) {
    jarray->setElement(i, ReadableNativeArray::getType(i).release());
  }
  return jarray;

It will get the type of every element then return the type at index, but it crash.....

I will post an issue there.

@zhangshenjie
Copy link

zhangshenjie commented Mar 27, 2018

In my project. I use this code to avoid the crash.

ReadableNativeArray.setUseNativeAccessor(true);
ReadableNativeMap.setUseNativeAccessor(true);

@hugows
Copy link

hugows commented Apr 26, 2018

@zhangshenjie I'm using RN 0.55.3 and adding those two lines to MainApplication.java's onCreate method makes the app crash when starting up. (instead of crashing when rendering the chart..)

@hugows
Copy link

hugows commented Apr 26, 2018

Those lines stopped crashing the app when I also pasted this there:

SoLoader.init(this, /* native exopackage */ false); // ???

@HsuWeiYu666
Copy link

Do I import something?
It say
cannot find symbol
ReadableNativeMap.setUseNativeAccessor(true);
^

@JoseVf
Copy link

JoseVf commented Jun 13, 2018

@HsuWeiYu666 Try to add
import com.facebook.react.bridge.ReadableNativeArray;
import com.facebook.react.bridge.ReadableNativeMap;
on top of your MainApplication.java

@ammoradi
Copy link

ammoradi commented Sep 4, 2018

@wuxudong please update installation_guide/README.MD aacording to @JoseVf 's amendment.

@ashrystein
Copy link

ashrystein commented Sep 9, 2021

react-native 0.63.4

import com.facebook.react.bridge.ReadableNativeArray;
import com.facebook.react.bridge.ReadableNativeMap;

cannot find symbol
setUseNativeAccessor(true);
^
Any help ?

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

8 participants