0

In my code, I have this workflow:

  1. When user wants to see some things, add Sprites using 'DataVizCore.addViewables()'
  2. Use 'viewer.addEventListener(DataVizCore.MOUSE_CLICK, onDotClick)' to show info bubble
  3. When user wants to show other things, call 'DataVizCore.removeAllViewables()' to clear Sprites
  4. Repeat from step 1

This sequence works OK except in one situation.

If a sprite was selected (by clicking on it) before removeAllViewables() is called, I don't get MOUSE_CLICK event for newly added Sprites. In browser console, I see following error is thrown.

CustomViewables.js:318 Uncaught TypeError: Cannot read property 'style' of undefined at ViewableData.getViewableUV (developer.api.autodesk.com/modelderivative/v2/viewers/7.*/extensions/DataVisualization/DataVisualization.js:454)

As a workaround, I added 'event.hasStopped = true' to click event handler to prevent Sprite getting selected internally. That seems to work.

This seems like a bug in DataVizExtension to me. Or, my workflow is wrong?

Thanks
Bandu

Bandu W
  • 99
  • 8

1 Answers1

1

Bandu. Thanks for the detailed steps to reproduce this issue. I tried with v7.46.0 version of the DataVisualization.js (latest as of my message) but was not seeing the same issue. I'd be curious if you are using this same version of the Forge Viewer (you can figure that out by looking at the viewer3D.js fetched under the Network tab of Chrome DevTools).

Setting event.hasStopped = true works because it internally avoided the code path calls into getViewableUV that threw the exception, but the flag is meant for other use cases (e.g. overriding default sprite selection behavior).

In any case, I've just tweaked our internal code to make use-cases like yours more robust. The changes will be released with the upcoming v7.47.0. Thank you for your feedback

Ben Goh
  • 107
  • 1
  • 3
  • 11
  • Thanks Ben. Yes, I am using v7.46 (default that got loaded with v7.*). One thing I forgot to mention that I am making a new Style for each Sprint because color is user defined per sprint (which is not how your sample code recommends). Not sure if that has an impact here. Thanks for the fix, and I will try that when I get 7.47. Bandu – Bandu W Jun 28 '21 at 04:20
  • 1
    Sure Bandu, from the way you got the exception, the new code should make it to not dereferene the invalid `viewableData` (among other stuff). I do recreate new `ViewableStyle`, `ViewableData`, `SpriteViewable` and `addViewables`, so should be pretty similar to your scenario. Let's see if the new version improves things for you. :) – Ben Goh Jun 28 '21 at 05:42