From 130e789d690a2d302d85f0e4a4058364707ead22 Mon Sep 17 00:00:00 2001 From: Grigory Pomadchin Date: Wed, 11 Mar 2020 15:19:26 -0400 Subject: [PATCH] Allocate rasterized buffer on heap --- CHANGELOG.md | 8 +++++++- examples/pdal-jni/build.sbt | 2 +- native/src/io_pdal_PointView.cpp | 15 ++++++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a92ff46..117e4e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.1.5-RC2] - 2020-03-11 + +### Changed +- Allocate rasterized buffer on heap [#37](https://github.com/PDAL/java/pull/37) + ## [2.1.5-RC1] - 2020-03-09 ### Added - Add a native mesh rasterization [#36](https://github.com/PDAL/java/pull/36) @@ -93,7 +98,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Moved from the PDAL repo and established own lifecycle. -[Unreleased]: https://github.com/PDAL/java/compare/2.1.5-RC1...HEAD +[Unreleased]: https://github.com/PDAL/java/compare/2.1.5-RC2...HEAD +[2.1.5-RC2]: https://github.com/PDAL/java/compare/2.1.5-RC1...2.1.5-RC2 [2.1.5-RC1]: https://github.com/PDAL/java/compare/2.1.4...2.1.5-RC1 [2.1.4]: https://github.com/PDAL/java/compare/2.1.3...2.1.4 [2.1.3]: https://github.com/PDAL/java/compare/2.1.2...2.1.3 diff --git a/examples/pdal-jni/build.sbt b/examples/pdal-jni/build.sbt index 6325a9d..2f412f8 100644 --- a/examples/pdal-jni/build.sbt +++ b/examples/pdal-jni/build.sbt @@ -21,7 +21,7 @@ resolvers ++= Seq( fork := true -val pdalVersion = "2.1.5-RC1" +val pdalVersion = "2.1.5-RC2" libraryDependencies ++= Seq( "io.pdal" %% "pdal" % pdalVersion, diff --git a/native/src/io_pdal_PointView.cpp b/native/src/io_pdal_PointView.cpp index 15d45d0..ff1e9bb 100644 --- a/native/src/io_pdal_PointView.cpp +++ b/native/src/io_pdal_PointView.cpp @@ -64,8 +64,10 @@ using pdal::pdal_error; /// \param[in] dims JavaArray of DimTypes /// \param[in] bufSize Dims sum size /// \param[in] dimTypes Vector of DimTypes -void convertDimTypeJavaArrayToVector(JNIEnv *env, jobjectArray dims, std::size_t *pointSize, DimTypeList *dimTypes, PointLayoutPtr pl) { - for (jint i = 0; i < env->GetArrayLength(dims); i++) { +void convertDimTypeJavaArrayToVector(JNIEnv *env, jobjectArray dims, std::size_t *pointSize, DimTypeList *dimTypes, PointLayoutPtr pl) +{ + for (jint i = 0; i < env->GetArrayLength(dims); i++) + { jobject jDimType = reinterpret_cast(env->GetObjectArrayElement(dims, i)); jclass cDimType = env->GetObjectClass(jDimType); jfieldID fid = env->GetFieldID(cDimType, "id", "Ljava/lang/String;"); @@ -192,7 +194,8 @@ JNIEXPORT jbyteArray JNICALL Java_io_pdal_PointView_getPackedPoints std::size_t bufSize = pointSize * pv->size(); char *buf = new char[bufSize]; - for (PointId idx = 0; idx < pv->size(); idx++) { + for (PointId idx = 0; idx < pv->size(); idx++) + { appendPackedPoint(pv, dimTypes, idx, pointSize, buf); } @@ -269,8 +272,8 @@ JNIEXPORT jdoubleArray JNICALL Java_io_pdal_PointView_rasterizeTriangularMesh jdoubleArray result = env->NewDoubleArray(length); - double buffer[length]; - std::fill(buffer, buffer + sizeof(buffer) / sizeof(double), strtod("NaN", NULL)); + double *buffer = new double[length]; + std::fill(buffer, buffer + length, strtod("NaN", NULL)); for (int id = 0; id < size; id++) { @@ -391,6 +394,8 @@ JNIEXPORT jdoubleArray JNICALL Java_io_pdal_PointView_rasterizeTriangularMesh env->SetDoubleArrayRegion(result, 0, length, buffer); + delete[] buffer; + return result; }