wuxudong/react-native-charts-wrapper

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

kyle-ssg opened this issue ยท 8 comments

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

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.

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

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

@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..)

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

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

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

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

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

react-native 0.63.4

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

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