Skip to content

Commit 457709d

Browse files
authored
Merge pull request #5173 from nyalldawson/model_crash_win
[processing] Fix crash in modeler on Windows
2 parents 9b8fad5 + cf16a82 commit 457709d

File tree

4 files changed

+36
-35
lines changed

4 files changed

+36
-35
lines changed

python/core/conversions.sip

100644100755
+16-12
Original file line numberDiff line numberDiff line change
@@ -1213,38 +1213,42 @@ template<TYPE2>
12131213
if (!d)
12141214
return NULL;
12151215

1216-
const sipMappedType *qlist_type = sipFindMappedType("QList<TYPE2>");
1217-
12181216
// Set the dictionary elements.
12191217
QMap<QString, QList< TYPE2 > >::const_iterator i;
12201218

12211219
for (i = sipCpp->constBegin(); i != sipCpp->constEnd(); ++i)
12221220
{
12231221
QString *t1 = new QString(i.key());
1224-
12251222
PyObject *t1obj = sipConvertFromNewType(t1, sipType_QString, sipTransferObj);
12261223

1227-
QList< TYPE2 > *t2 = new QList< TYPE2 >( i.value() );
1228-
1229-
PyObject *t2obj = sipConvertFromMappedType(t2, qlist_type, sipTransferObj);
1224+
// build list for dictionary value
1225+
QList< TYPE2 > sourceList = i.value();
1226+
PyObject *t2list = PyList_New( sourceList.size() );
1227+
if ( t2list )
1228+
{
1229+
for ( int j = 0; j < sourceList.size(); j++ )
1230+
{
1231+
TYPE2 *t = new TYPE2(sourceList.at(j));
1232+
PyObject *lobj = sipConvertFromNewType(t, sipType_TYPE2, sipTransferObj);
1233+
PyList_SetItem( t2list, j, lobj );
1234+
}
1235+
}
12301236

1231-
if (t1obj == NULL || t2obj == NULL || PyDict_SetItem(d, t1obj, t2obj) < 0)
1237+
if (t1obj == NULL || t2list == NULL || PyDict_SetItem(d, t1obj, t2list) < 0)
12321238
{
12331239
Py_DECREF(d);
12341240

12351241
if (t1obj)
12361242
Py_DECREF(t1obj);
12371243

1238-
if (t2obj)
1239-
Py_DECREF(t2obj);
1240-
else
1241-
delete t2;
1244+
if (t2list)
1245+
Py_DECREF(t2list);
12421246

12431247
return NULL;
12441248
}
12451249

12461250
Py_DECREF(t1obj);
1247-
Py_DECREF(t2obj);
1251+
Py_DECREF(t2list);
12481252
}
12491253

12501254
return d;

python/plugins/processing/modeler/ModelerDialog.py

100644100755
+8-8
Original file line numberDiff line numberDiff line change
@@ -588,17 +588,17 @@ def _addAlgorithm(self, alg, pos=None):
588588
pass
589589
if not dlg:
590590
dlg = ModelerParametersDialog(alg, self.model)
591-
dlg.exec_()
592-
if dlg.alg is not None:
591+
if dlg.exec_():
592+
alg = dlg.createAlgorithm()
593593
if pos is None:
594-
dlg.alg.setPosition(self.getPositionForAlgorithmItem())
594+
alg.setPosition(self.getPositionForAlgorithmItem())
595595
else:
596-
dlg.alg.setPosition(pos)
596+
alg.setPosition(pos)
597597
from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
598-
for i, out in enumerate(dlg.alg.modelOutputs()):
599-
dlg.alg.modelOutput(out).setPosition(dlg.alg.position() + QPointF(ModelerGraphicItem.BOX_WIDTH, (i + 1.5) *
600-
ModelerGraphicItem.BOX_HEIGHT))
601-
self.model.addChildAlgorithm(dlg.alg)
598+
for i, out in enumerate(alg.modelOutputs()):
599+
alg.modelOutput(out).setPosition(alg.position() + QPointF(ModelerGraphicItem.BOX_WIDTH, (i + 1.5) *
600+
ModelerGraphicItem.BOX_HEIGHT))
601+
self.model.addChildAlgorithm(alg)
602602
self.repaintModel()
603603
self.hasChanged = True
604604

python/plugins/processing/modeler/ModelerGraphicItem.py

100644100755
+4-4
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ def editElement(self):
210210
pass
211211
if not dlg:
212212
dlg = ModelerParametersDialog(self.element.algorithm(), self.model, self.element.childId())
213-
dlg.exec_()
214-
if dlg.alg is not None:
215-
dlg.alg.setChildId(self.element.childId())
216-
self.updateAlgorithm(dlg.alg)
213+
if dlg.exec_():
214+
alg = dlg.createAlgorithm()
215+
alg.setChildId(self.element.childId())
216+
self.updateAlgorithm(alg)
217217
self.scene.dialog.repaintModel()
218218

219219
def updateAlgorithm(self, alg):

python/plugins/processing/modeler/ModelerParametersDialog.py

100644100755
+8-11
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ def __init__(self, alg, model, algName=None):
7070
self.setModal(True)
7171
# The algorithm to define in this dialog. It is an instance of GeoAlgorithm
7272
self._alg = alg
73-
# The resulting algorithm after the user clicks on OK. it is an instance of the container Algorithm class
74-
self.alg = None
7573
# The model this algorithm is going to be added to
7674
self.model = model
7775
# The name of the algorithm in the model, in case we are editing it and not defining it for the first time
@@ -348,21 +346,20 @@ def createAlgorithm(self):
348346
dep_ids.append(availableDependencies[selected].childId()) # spellok
349347
alg.setDependencies(dep_ids)
350348

351-
try:
352-
self._alg.processBeforeAddingToModeler(alg, self.model)
353-
except:
354-
pass
349+
#try:
350+
# self._alg.processBeforeAddingToModeler(alg, self.model)
351+
#except:
352+
# pass
355353

356354
return alg
357355

358356
def okPressed(self):
359-
self.alg = self.createAlgorithm()
360-
if self.alg is not None:
361-
self.close()
357+
alg = self.createAlgorithm()
358+
if alg is not None:
359+
self.accept()
362360

363361
def cancelPressed(self):
364-
self.alg = None
365-
self.close()
362+
self.reject()
366363

367364
def openHelp(self):
368365
algHelp = self._alg.help()

0 commit comments

Comments
 (0)