<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.E-MailFormatvorlage17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE-AT" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US">Hi Developers,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">We use OpenLayers V2.13.1 in several projects. It works well in most cases,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">but in one case it throws<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">TypeError: this.layer is null<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">during loading layers. It occurs in FF and IE.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The error rises in OpenLayers.Tile.shouldDraw in line 228:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">maxExtent = this.layer.maxExtent;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I have found a similar phenomenon here:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">https://github.com/openlayers/openlayers/pull/1064/files<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">where one corrects the bug by not drawing the already destroyed tiles.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">However, this solution does not corrects the root of the problem. My solution<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">below may be not optimal, too, since we do not have time to dig deep in the<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">event-based tile management architecture, but is probably closer. This<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">solution also prohibits a memory leak.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The problem occurs this way:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">OpenLayers performs Map layout calculations. First it requests a tile (one WMS<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">layer with singleTile = true), it draws it, then it realises the viewport<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">layout is changed, and calls OpenLayers.Tile.destroy. This function makes the<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Tile instance practically unusable by setting all important properties to<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">null. Further operations on this instance ar not feasible any more.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">After it (probably after several other calculations) it calls<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">OpenLayers.TileManager.clearTileQueue to delete all tiles of this layer.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Since the queue contains tiles for all layers in a map, it checks each tile<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">if it belongs to the layer in question. This check takes place in line 441.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">if (tileQueue[i].layer === layer) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">In our case, the layer property of the tile is null, so the invalidated tile<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">instance escapes from deleting. Later, in a new viewport layout step OpenLayers<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">wants to draw it, which is not possible any more.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">My idea is to delete tile instances with layer===null, too:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">if (tileQueue[i].layer === null || tileQueue[i].layer === layer) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">If we let them gather, and somehow OpenLayers won't draw them (as usually<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">there is no problem), they result in a memory leak.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Best regards: <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> Balázs Bámer<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"></span>GRINTEC GmbH<o:p></o:p></p>
<p class="MsoNormal">Anzengrubergasse 6, 8010 Graz, Austria<o:p></o:p></p>
<p class="MsoNormal">Tel: +43(316)383706-0<o:p></o:p></p>
<p class="MsoNormal"><a href="mailto:balazs.bamer@grintec.com"><span style="color:blue">balazs.bamer@grintec.com</span></a><o:p></o:p></p>
<p class="MsoNormal"><a href="http://www.grintec.com/"><span style="color:blue">http://www.grintec.com</span></a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">FN 47845k Handelsgericht Graz<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>