Calling .dispose() on map shortly after it's creation leads to an error RRS feed

  • Question

  • Hello,

    in our project we are using combination of Angular 6 and bing maps. User can create multiple maps on fly. In the angular component which is holding the map, in method ngOnDestroy we are disponsing the map (calling dispose() method). The problem is that in a case that user quickly navigates to different part of the application (the component which is holding the map is destroyed) he get following error


    Unhandled error occurred! TypeError: Cannot read property 'width' of null    at t.beginFrame (,nj/1e86640b/4d9d0761.js?bu=A-8E1gf0BA:1:11958)    at n._render (,nj/f0484318/8d2d6907.js?bu=Fe8EqAWuBcgFwAXLBc4F0QXUBdcF3QXaBeAF4wXmBekF7AXvBfIFqwX0BA:1:18465)    at,nj/f0484318/8d2d6907.js?bu=Fe8EqAWuBcgFwAXLBc4F0QXUBdcF3QXaBeAF4wXmBekF7AXvBfIFqwX0BA:1:18147    at t._tick (,nj/49b10c39/57e218fc.js?bu=B-8EnQWfBaEF4QSkBfQE:1:264878)    at,nj/49b10c39/57e218fc.js?bu=B-8EnQWfBaEF4QSkBfQE:1:265156    at,nj/49b10c39/57e218fc.js?bu=B-8EnQWfBaEF4QSkBfQE:1:14388    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2743:31)    at Object.onInvokeTask (http://localhost:4200/vendor.js:55261:33)    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2742:36)    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.js:2510:47)

    So it seems that the bing map is trying to run some methods even though the map is already gone??

    My question is: is it necessary to call dispose() method when used inside angular app? And if yes, is there some point after which is calling of this method safe? E.g the map object already exists but internally there are still some unfinished callbacks, which needs to be finished, otherwise disposing of map in such state will lead to an error.

    I can create a stackblitz demo to demonstrate this behavior if somebody finds it useful to track this down.

    Thank you

    • Edited by TomasDSG Wednesday, January 23, 2019 11:37 AM
    Wednesday, January 23, 2019 11:37 AM

All replies

  • Hi Tomas,

    I am afraid I am not familiar with Angular.  Can you reproduce the issue from outside that environment?  My suspicion is that you should follow up with whomever is providing you with the Angular environment for support.



    Friday, January 25, 2019 6:06 AM
  • Thank you.

    Ouk will try to reproduce it outside the Angular to see if it happens.

    Friday, January 25, 2019 9:01 AM
  • Here is a simple code pen to illustrate the issue (only html/js).. (Open the browser dev tools and hit refresh, and you should see an error in console)

    2 seconds after the map is created method dispose() is called upon it.. This plus minus simulates our situation when on the initial screen is displayed a map, and when user navigates elsewhere the map is destroyed. And if he does it quickly enough he will get an exception.

    The exceptions are usually either "Cannot read property 'hasUserLayers' of null" or "this._map.getAllLayers(...) is null"

    mapcontrol?key=AlrvKTtJqlmyYG-FWboUfK8tsBCU_Qqk9LPcQr77okoyvMYlvknVUKEvigrS-SSs:16 Uncaught TypeError: Cannot read property 'hasUserLayers' of null
        at t._getKey (4d9d0761.js?bu=A-8E1gf0BA:1)
        at t.getTile (4d9d0761.js?bu=A-8E1gf0BA:1)
        at i.getTile (4d9d0761.js?bu=A-8E1gf0BA:1)
        at i._render (4d9d0761.js?bu=A-8E1gf0BA:1)
        at i.update (4d9d0761.js?bu=A-8E1gf0BA:1)
        at r.prefetchBackgroundGrids (4d9d0761.js?bu=A-8E1gf0BA:1)
        at n._onFrameManagerFrameRendered (62f6e79b.js?bu=Fe8EqAWuBcgFwAXLBc4F0QXUBdcF3QXaBeAF4wXmBekF7AXvBfIFqwX0BA:1)
        at 62f6e79b.js?bu=Fe8EqAWuBcgFwAXLBc4F0QXUBdcF3QXaBeAF4wXmBekF7AXvBfIFqwX0BA:1
        at mapcontrol?key=AlrvKTtJqlmyYG-FWboUfK8tsBCU_Qqk9LPcQr77okoyvMYlvknVUKEvigrS-SSs:3
     TypeError: this._map.getAllLayers(...) is null[Learn More] 4d9d0761.js:1:23021


    Friday, January 25, 2019 5:40 PM
  • Hi Tomas,

    I have sent this to the V8 Team for review.  They work on an Agile schedule so I can't give you a timeline for that review.



    Tuesday, January 29, 2019 6:21 PM
  • Thank you :)
    Tuesday, January 29, 2019 8:57 PM