QML based app crashing with drag/drop

879
6
09-25-2019 07:41 AM
JeremyRoberts2
New Contributor III

Hello.  We are seeing an issue with a QML based app crashing.  When we allow for dragging and dropping of a feature, if you drag the feature around long enough, eventually the app completely crashes.  We are using runtimes 100.5.  This happens on both Mac and Win PCs.  We are using the basic ArcGIS template when creating a new application and slightly modifying it to allow for drag and drop.  Please see the attached project.  Any suggestions as to why this is happening?  It takes me about 50 seconds of dragging to get it to crash but our other developers have it happen much sooner.

0 Kudos
6 Replies
LucasDanzinger
Esri Frequent Contributor

Hi Jeremy-

I think I know what is going on here. Can you try switching out your onIdentifyLayerStatusChanged signal handler to this and see if it works?

onIdentifyLayerStatusChanged: {
    if (identifyLayerStatus === Enums.TaskStatusCompleted) {
        featureLayer.clearSelection();

        for (var i = 0; i < identifyLayerResult.geoElements.length; i++) {
            selectedFeatures.push(identifyLayerResult.geoElements[i]);
        }
        
        featureLayer.selectFeatures(selectedFeatures);
    }
}

I think your direct assigning of `selectedFeatures = identifyLayerResult.geoElements;` is the problem. This is now assigning selectedFeatures to the list of GeoElements, but nothing is specifically holding on a reference to the GeoElements in that list, so they go out of scope and get garbage collected after a random amount of time. On Windows, for me it was between 15-20 seconds. Whenever things randomly stop working, garbage collection is a likely culprit. I ran the below code to force garbage collection, and reliably, the selectedfeatures.length is 0.

onMousePositionChanged: {
   if (selectedFeatures.length > 0) {
       mouse.accepted = true;
       // force garbage collection
       gc();
       for (var i = 0; i < selectedFeatures.length; i++) {
           selectedFeatures[i].geometry = mouse.mapPoint;
       }
       if (featureLayer.featureTable.updateFeaturesStatus !== Enums.TaskStatusInProgress) {
           featureLayer.featureTable.updateFeatures(selectedFeatures);
       }
   } else {
       // this prints out right away
       console.log("no features in selectedFeatures list");
       mouse.accepted = false;
   }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

If you can confirm that this matches with your findings, then please proceed with changing your code to directly store references to the Feature(s) you want. One way to do that is how I have it in the first snippet. 

0 Kudos
JeremyRoberts2
New Contributor III

It still crashes for us.  One time I ran it and 90 seconds went by and it never crashed.  Then I restarted and it crashed within 30 seconds.  We had another dev on a Win machine try it and it crashed within 30 seconds.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Hmm, that's strange. Can you upload your updated project so I can re-test please?

0 Kudos
JeremyRoberts2
New Contributor III

Here is the updated app to retest.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Thanks Jeremy. I was testing with 100.6 and couldn't repro with the updated code, but can with 100.5. Is 100.6 an option? Even if it is just to validate that the issue is indeed fixed with 100.6? I tried to find a workaround for 100.5 but haven't been able to come up with anything yet.

0 Kudos
JeremyRoberts2
New Contributor III

100.6 is an option eventually but I don't think we can get to it immediately.  In the meantime, we have implemented a work-around.  We pull the symbol from the feature, create a temporary graphic matching the symbol and place in same location, hide the feature, and let the user drag the graphic around.  This does not crash.

0 Kudos