Skip to content

Commit

Permalink
[#4340] Fixes possible access to undefined object (#4431)
Browse files Browse the repository at this point in the history
* [#4340] Fixes possible access to undefined object

* CHANGELOG update

* Adds the test
  • Loading branch information
birdofpreyru authored Jul 22, 2024
1 parent c01e231 commit 52e7962
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
### 🐞 Bug fixes

- Fix lag on fast map zoom ([#4366](https://github.com/maplibre/maplibre-gl-js/pull/4366))
- Fix unguarded read access to possibly undefined object ([#4431](https://github.com/maplibre/maplibre-gl-js/pull/4431))
- Fix remove hash string when map is removed ([#4427](https://github.com/maplibre/maplibre-gl-js/pull/4427))
- _...Add new stuff here..._

Expand Down
51 changes: 51 additions & 0 deletions src/render/painter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {TerrainSpecification} from '@maplibre/maplibre-gl-style-spec';

import {Painter} from './painter';
import {Transform} from '../geo/transform';
import {Style} from '../style/style';
import {Evented} from '../util/evented';
import {RequestManager} from '../util/request_manager';

class StubMap extends Evented {
style: Style;
transform: Transform;
private _requestManager: RequestManager;
_terrain: TerrainSpecification;

constructor() {
super();
this.transform = new Transform();
this._requestManager = new RequestManager();
}

_getMapId() {
return 1;
}

getPixelRatio() {
return 1;
}

setTerrain(terrain) { this._terrain = terrain; }
getTerrain() { return this._terrain; }
}

const getStubMap = () => new StubMap() as any;

test('Render must not fail with incompletely loaded style', () => {
const gl = document.createElement('canvas').getContext('webgl');
const transform = new Transform(0, 22, 0, 60, true);
const painter = new Painter(gl, transform);
const map = getStubMap();
const style = new Style(map);
style._updatePlacement(transform, false, 0, false);
painter.render(style, {
fadeDuration: 0,
moving: false,
rotating: false,
showOverdrawInspector: false,
showPadding: false,
showTileBoundaries: false,
zooming: false,
});
});
2 changes: 1 addition & 1 deletion src/render/painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export class Painter {
this.clearStencil();

// draw sky first to not overwrite symbols
if (this.style.stylesheet.sky) drawSky(this, this.style.sky);
if (this.style.stylesheet?.sky) drawSky(this, this.style.sky);

this._showOverdrawInspector = options.showOverdrawInspector;
this.depthRangeFor3D = [0, 1 - ((style._order.length + 2) * this.numSublayers * this.depthEpsilon)];
Expand Down

0 comments on commit 52e7962

Please sign in to comment.