Skip to content

Commit

Permalink
Don't throw when native pointers have long values < 0 (#2217)
Browse files Browse the repository at this point in the history
* Don't throw when native pointers have long values < 0

Android 11 and certain ROMs use "tagged pointers" that set the high bits on pointers, causing them to become negative as a long.

* Fix more pointer check comparisons in MapController
  • Loading branch information
matteblair authored Dec 14, 2020
1 parent 589667e commit 434f27a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ public MapData addDataLayer(final String name, final boolean generateCentroid) {
return mapData;
}
final long pointer = nativeMap.addClientDataSource(name, generateCentroid);
if (pointer <= 0) {
if (pointer == 0) {
throw new RuntimeException("Unable to create new data source");
}
mapData = new MapData(name, pointer, this);
Expand All @@ -684,7 +684,9 @@ public MapData addDataLayer(final String name, final boolean generateCentroid) {
*/
void removeDataLayer(@NonNull final MapData mapData) {
clientTileSources.remove(mapData.name);
checkPointer(mapData.pointer);
if (mapData.pointer == 0) {
throw new RuntimeException("Tried to remove a MapData that was already disposed");
}
nativeMap.removeClientDataSource(mapData.pointer);
}

Expand Down Expand Up @@ -1083,14 +1085,6 @@ void onLowMemory() {
nativeMap.onLowMemory();
}

void checkPointer(final long ptr) {
if (ptr <= 0) {
throw new RuntimeException("Tried to perform an operation on an invalid pointer!"
+ " This means you may have used an object that has been disposed and is no"
+ " longer valid.");
}
}

void checkId(final long id) {
if (id <= 0) {
throw new RuntimeException("Tried to perform an operation on an invalid id!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void clear() {
}

private void checkPointer(final long ptr) {
if (ptr <= 0) {
if (ptr == 0) {
throw new RuntimeException("Tried to perform an operation on an invalid pointer!"
+ " This means you may have used a MapData that has already been removed.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class NativeMap {

NativeMap(MapController mapController, AssetManager assetManager) {
nativePointer = init(mapController, assetManager);
if (nativePointer <= 0) {
if (nativePointer == 0) {
throw new RuntimeException("Unable to create a native Map object! There may be insufficient memory available.");
}
}
Expand Down

0 comments on commit 434f27a

Please sign in to comment.