Updating a Graphic in GraphicsLayer / thread safeness

1869
3
Jump to solution
02-15-2016 12:20 AM
ChristianEhrlicher
New Contributor II

Hi,

we add a EsriRuntimeQt::Graphic to a EsriRuntimeQt::GraphicsLayer with GraphicsLayer::addGraphic(m_graphicPtr). Now we want to change the graphic (e.g. the line color). What's the recommended way to do this? The documentation does not say anything about this:

  • simply modify m_graphicPtr (and hope the GraphicsLayer notices the change and updates it's graphical representation)
    • this would mean that all Functions for EsriRuntimeQt::Graphic must be thread-safe
    • or is there another synchronization mechanism
    • using updateGraphic with the same pointer used by addGraphic will lead to a crash (afaics addGraphic() moves ownership and updateGraphic() will delete the old graphic - at least this is what I'm seeing, the documentation only express this indirect with)
  • create a new Graphic and replace the current one with EsriRuntimeQt::GraphicsLayer::updateGraphic()
  • other ways I'm not aware of

Thx,

Christian

0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

Christian-

If you are wanting to update the symbol of a particular graphic, can you just use updateGraphic that takes in the graphic's ID and the new symbol? ArcGIS Runtime SDK for Qt C++ API: EsriRuntimeQt::GraphicsLayer Class Reference

Otherwise, you can create a new Graphic, and update the existing one with updateGraphic ArcGIS Runtime SDK for Qt C++ API: EsriRuntimeQt::GraphicsLayer Class Reference

That would be the recommended approach. I would need to see your code to get a hint at why it might be crashing.

-Luke

View solution in original post

0 Kudos
3 Replies
ChristianEhrlicher
New Contributor II

Ok, it looks like my assumption about ownership is wrong. I moved the code into a small testcase and calling updateGraphic() in a loop (via timer every 10ms) it's crashing now and then but everytime with a similar backtrace. If you're interested in this backtrace or the testcase, please let me know.

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Christian-

If you are wanting to update the symbol of a particular graphic, can you just use updateGraphic that takes in the graphic's ID and the new symbol? ArcGIS Runtime SDK for Qt C++ API: EsriRuntimeQt::GraphicsLayer Class Reference

Otherwise, you can create a new Graphic, and update the existing one with updateGraphic ArcGIS Runtime SDK for Qt C++ API: EsriRuntimeQt::GraphicsLayer Class Reference

That would be the recommended approach. I would need to see your code to get a hint at why it might be crashing.

-Luke

View solution in original post

0 Kudos
ChristianEhrlicher
New Contributor II

What we're doing is more or less something like

qid = GraphicsLayer::addGraphic(m_graphicPtr);

...

modify m_graphicPtr (change geometry or smth. else)

...

GraphicsLayer::updateGraphic(gid, m_graphicPtr);

...

do more modifications

...

GraphicsLayer::updateGraphic(gid, m_graphicPtr);

...

This does lead to race conditions because the render thread is accessing attributes of m_grpahicPtr  while we're modifying those attributes.

Our solution is exactly what you're proposed - using addGraphic(), working on a new (cloned) graphic for hte changes and then call updateGraphic() with new graphic.

Thx,

Christian

0 Kudos