Skip to content

Commit

Permalink
Fixing potential crashes.
Browse files Browse the repository at this point in the history
Based on crash reports.
  • Loading branch information
pascalhorton committed Jun 6, 2024
1 parent 854171f commit 51e8aba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/gis/tmeditmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,9 @@ bool tmEditManager::FlipLine() {
for (unsigned int f = 0; f < mySelected->GetCount(); f++) {
OGRFeature* myFeature = mySelLayer->GetFeatureByOID(mySelected->Item(f));
wxASSERT(myFeature);
if (myFeature == nullptr) {
continue;
}

// don't delete, internally geometry.
OGRLineString* myOGRSelLine = (OGRLineString*)myFeature->GetGeometryRef();
Expand Down
4 changes: 3 additions & 1 deletion src/gis/tmgisdatavector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ OGRGeometry* tmGISDataVector::CreateOGRGeometry(const wxRealPoint& pt) {
bool tmGISDataVector::CutLineAtVertex(long oid, const wxRealPoint& clickedpt, int searchRadius, int layertype) {
// get the line
OGRFeature* myFeature = GetFeatureByOID(oid);
wxASSERT(myFeature);
if (myFeature == nullptr) {
return false;
}
OGRLineString* myLine = (OGRLineString*)myFeature->GetGeometryRef();

// create search buffer
Expand Down
1 change: 1 addition & 0 deletions src/gis/tmimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ bool tmImport::SetAttributes(DataBaseTM* database, PrjDefMemManage* prj, const w
wxArrayLong& oids) {
// Get layer
ProjectDefMemoryLayers* layer = prj->FindLayer(m_LayerName);
if (layer == nullptr) return false;

// Get field names
wxArrayString fields;
Expand Down
5 changes: 5 additions & 0 deletions src/gis/tmimportgis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ bool tmImportGIS::Import(DataBaseTM* database, PrjDefMemManage* prj, wxProgressD
}

OGRGeometry* myGeom = myFeature->GetGeometryRef();
if (myGeom == nullptr) {
OGRFeature::DestroyFeature(myFeature);
wxLogWarning(_("Empty geometry in feature %ld"), myFeature->GetFID());
continue;
}
wxASSERT(myGeom);
wxArrayLong oids;

Expand Down
6 changes: 5 additions & 1 deletion src/gis/tmlayermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,11 @@ bool tmLayerManager::_ReplaceLayer(const wxFileName& filename, const wxString& o
// need to create an attribut index ?
if (myLayerToReplace->GetSymbolRuleManagerRef()->GetRulesRef()->GetCount() > 0 &&
myLayerToReplace->GetSymbolRuleManagerRef()->IsUsingRules()) {
tmGISDataVectorSHP* myGISData = (tmGISDataVectorSHP*)tmGISData::LoadLayer(myLayerToReplace);
auto myGISData = (tmGISDataVectorSHP*)tmGISData::LoadLayer(myLayerToReplace);
if (myGISData == nullptr) {
wxLogError(_("Unable to load layer : %s"), myLayerToReplace->GetName().GetName());
return false;
}
wxString myQuery2 = wxString::Format(_T("DROP INDEX on %s"), myLayerToReplace->GetName().GetName());
myGISData->ExecuteSQLQuery(myQuery2);
wxString myFieldName = myLayerToReplace->GetSymbolRuleManagerRef()->GetFieldName();
Expand Down

0 comments on commit 51e8aba

Please sign in to comment.