Hello, the terrain generator works well when the game start, when the game change the terrain (so it generate a new terrain removing the old one) it give an error (it worked fine with old scripts.
To replicate the error press M key and click on the town upper the shield Vigo
https://playcanvas.com/editor/scene/898756
Code:
Terrain.prototype.createTerrainFromHeightMap= function (img,subd) {
var canvas = document.createElement("canvas");
var context = canvas.getContext("2d");
var bufferWidth = img.width;
var bufferHeight = img.height;
canvas.width = bufferWidth;
canvas.height = bufferHeight;
context.drawImage(img, 0, 0); (line that give error)
var buffer = context.getImageData(0, 0, bufferWidth, bufferHeight).data;
var vertexData = this.createTerrainVertexData({
width: this.width,
height: this.depth,
subdivisions: subd,
minHeight: this.minHeight,
maxHeight: this.maxHeight,
buffer: buffer,
bufferWidth: bufferWidth,
bufferHeight: bufferHeight
});
var node = new pc.GraphNode();
var material = this.material[this.lM].resource;
var mesh = pc.createMesh(this.app.graphicsDevice, vertexData.positions, {
normals: vertexData.normals,
uvs: vertexData.uvs,
indices: vertexData.indices
});
var meshInstance = new pc.MeshInstance(node, mesh, material);
var model = new pc.Model();
model.graph = node;
model.meshInstances.push(meshInstance);
return model;
};