Skip to content

Commit

Permalink
Fix memory leakage for CutAlongPolyline
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenherje committed Mar 11, 2024
1 parent 639f9d0 commit f5dbee7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void RivPolylineIntersectionGeometryGenerator::generateIntersectionGeometry( cvf
//--------------------------------------------------------------------------------------------------
void RivPolylineIntersectionGeometryGenerator::calculateArrays( cvf::UByteArray* visibleCells )
{
if ( m_hexGrid.isNull() || m_polylineSegmentsMeshData.size() != 0 ) return;
if ( m_hexGrid == nullptr || m_polylineSegmentsMeshData.size() != 0 ) return;

// Mesh data per polyline segment
std::vector<PolylineSegmentMeshData> polylineSegmentMeshData = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class RivPolylineIntersectionGeometryGenerator
static std::vector<cvf::Vec3d> initializePolylineUtmFromPolylineUtmXy( const std::vector<cvf::Vec2d>& polylineUtmXy );

private:
cvf::ref<RivIntersectionHexGridInterface> m_hexGrid;
const std::vector<cvf::Vec3d> m_polylineUtm;
RivIntersectionHexGridInterface* m_hexGrid = nullptr;
const std::vector<cvf::Vec3d> m_polylineUtm;

// Output
std::vector<PolylineSegmentMeshData> m_polylineSegmentsMeshData;
Expand Down
34 changes: 17 additions & 17 deletions GrpcInterface/RiaGrpcGridGeometryExtractionService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,38 +194,38 @@ grpc::Status RiaGrpcGridGeometryExtractionService::CutAlongPolyline( grpc::Serve
polylineUtmXy.push_back( cvf::Vec2d( xValue, yValue ) );
}

RigActiveCellInfo* activeCellInfo = nullptr; // No active cell info for grid
const bool showInactiveCells = true;
RivEclipseIntersectionGrid* eclipseIntersectionGrid =
new RivEclipseIntersectionGrid( m_eclipseView->mainGrid(), activeCellInfo, showInactiveCells );
RigActiveCellInfo* activeCellInfo = nullptr; // No active cell info for grid
const bool showInactiveCells = true;
auto eclipseIntersectionGrid =
RivEclipseIntersectionGrid( m_eclipseView->mainGrid(), activeCellInfo, showInactiveCells );

auto* polylineIntersectionGenerator =
new RivPolylineIntersectionGeometryGenerator( polylineUtmXy, eclipseIntersectionGrid );
auto polylineIntersectionGenerator =
RivPolylineIntersectionGeometryGenerator( polylineUtmXy, &eclipseIntersectionGrid );

// Handle cell visibilities
const int firstTimeStep = 0;
cvf::UByteArray* visibleCells = new cvf::UByteArray( m_eclipseView->mainGrid()->cellCount() );
m_eclipseView->calculateCurrentTotalCellVisibility( visibleCells, firstTimeStep );
const int firstTimeStep = 0;
cvf::UByteArray visibleCells = cvf::UByteArray( m_eclipseView->mainGrid()->cellCount() );
m_eclipseView->calculateCurrentTotalCellVisibility( &visibleCells, firstTimeStep );

// Loop to count number of visible cells
int numVisibleCells = 0;
for ( size_t i = 0; i < visibleCells->size(); ++i )
for ( size_t i = 0; i < visibleCells.size(); ++i )
{
if ( ( *visibleCells )[i] != 0 )
if ( ( visibleCells )[i] != 0 )
{
++numVisibleCells;
}
}

// Generate intersection
polylineIntersectionGenerator->generateIntersectionGeometry( visibleCells );
if ( !polylineIntersectionGenerator->isAnyGeometryPresent() )
polylineIntersectionGenerator.generateIntersectionGeometry( &visibleCells );
if ( !polylineIntersectionGenerator.isAnyGeometryPresent() )
{
return grpc::Status( grpc::StatusCode::INVALID_ARGUMENT, "No intersection geometry present" );
}

// Add fence mesh sections
const auto& polylineSegmentsMeshData = polylineIntersectionGenerator->polylineSegmentsMeshData();
const auto& polylineSegmentsMeshData = polylineIntersectionGenerator.polylineSegmentsMeshData();
for ( const auto& segment : polylineSegmentsMeshData )
{
auto* fenceMeshSection = response->add_fencemeshsections();
Expand Down Expand Up @@ -272,7 +272,7 @@ grpc::Status RiaGrpcGridGeometryExtractionService::CutAlongPolyline( grpc::Serve
rips::PolylineTestResponse* polylineTestResponse = new rips::PolylineTestResponse;

// Polygon vertices
const auto& polygonVertices = polylineIntersectionGenerator->polygonVxes();
const auto& polygonVertices = polylineIntersectionGenerator.polygonVxes();
if ( polygonVertices->size() == 0 )
{
return grpc::Status( grpc::StatusCode::NOT_FOUND, "No polygon vertices found for polyline" );
Expand All @@ -286,14 +286,14 @@ grpc::Status RiaGrpcGridGeometryExtractionService::CutAlongPolyline( grpc::Serve
}

// Vertices per polygon
const auto& verticesPerPolygon = polylineIntersectionGenerator->vertiesPerPolygon();
const auto& verticesPerPolygon = polylineIntersectionGenerator.vertiesPerPolygon();
for ( const auto& elm : verticesPerPolygon )
{
polylineTestResponse->add_verticesperpolygonarr( static_cast<google::protobuf::uint32>( elm ) );
}

// Polygon to cell indices
const auto& polygonCellIndices = polylineIntersectionGenerator->polygonToCellIndex();
const auto& polygonCellIndices = polylineIntersectionGenerator.polygonToCellIndex();
for ( const auto& elm : polygonCellIndices )
{
polylineTestResponse->add_sourcecellindicesarr( static_cast<google::protobuf::uint32>( elm ) );
Expand Down

0 comments on commit f5dbee7

Please sign in to comment.