Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cwise-compiler >1.1.0] cwise: Arrays do not all have the same shape (ao 34**3 but array 36**3) #11

Open
deathcap opened this issue Dec 30, 2015 · 3 comments

Comments

@deathcap
Copy link
Member

Uncaught Error: cwise: Arrays do not all have the same shape!
calcAO_cwise_thunk @ VM8501:8
computeMesh @ mesh.js:502
createVoxelMesh @ mesh-buffer.js:13
MesherPlugin.createVoxelMesh @ mesh-plugin.js:41
Game.showChunk @ index.js:645(anonymous function) @ land.js:134

on vmv with dev versions of voxel-decals, voxel-engine-stackgl, voxel-webview.

// cwise:
if (!(array1.shape[shapeIndex+0]===array2.shape[shapeIndex+0] && array1.shape[shapeIndex+0]===array3.shape[shapeIndex+0] && array1.shape[shapeIndex+0]===array4.shape[shapeIndex+0])) throw new Error('cwise: Arrays do not all have the same shape!')

//voxel-mesher mesh.js
  //Calculate ao fields
  surfaceStencil(ao0, ao1, ao2, array)

ao0, ao1, ao2 are all Int32Array[39304] (34^3 = 39304, chunk size 32x32x32 + 2 for padding) but array is Uint16Array[46656] (36^3 = 46656), passed in from:

//voxel-mesher mesh-buffer.js:

//Creates a mesh from a set of voxels
function createVoxelMesh(gl, voxels, voxelSideTextureIDs, voxelSideTextureSizes, position, pad, that) {
  //Create mesh
  var vert_data = createAOMesh(voxels, voxelSideTextureIDs, voxelSideTextureSizes)

//voxel-mesher mesh-plugin.js
MesherPlugin.prototype.createVoxelMesh = function(gl, voxels, voxelSideTextureIDs, voxelSideTextureSizes, position, pad) {
  var porousMesh = this.splitVoxelArray(voxels);

  var mesh = createVoxelMesh(gl, this.solidVoxels, voxelSideTextureIDs, voxelSideTextureSizes, position, pad, this);

//voxel-engine-stackgl
  var voxelArray = isndarray(chunk) ? chunk : ndarray(chunk.voxels, chunk.dims) 
 // voxelArray = View3duint16 {data: Uint16Array[46656], shape: Array[3], stride: Array[3], offset: 0, position: Array[3]}, chunk = View3duint16  ...
  var mesh = this.mesherPlugin.createVoxelMesh(this.shell.gl, voxelArray, this.stitcher.voxelSideTextureIDs, this.stitcher.voxelSideTextureSizes, chunk.position, this.chunkPad)
@deathcap deathcap changed the title cwise: Arrays do not all have the same shape cwise: Arrays do not all have the same shape (ao 34**3 but array 36**3) Dec 30, 2015
@deathcap
Copy link
Member Author

Reproduced with isolated voxel-example: https://github.com/deathcap/voxel-example/tree/5e8ed535f8418e816001c8f14d4f3dcb858360aa

previously was using cwise 1.0.4 circa 2014, https://github.com/scijs/cwise/commits/master - https://github.com/scijs/cwise#notes documents "All input arrays must have the same shape. If not, then the library will throw an error". Exception is thrown in generated code: https://github.com/scijs/cwise-compiler/blob/master/lib/thunk.js#L61

   code.push("if (!(" + shapeConditions.join(" && ") + ")) throw new Error('cwise: Arrays do not all have the same shape!')")

this is a recent message, changed in scijs/cwise-compiler@8f881ce from "Generic arrays not supported in combination with blocks" which was added Jun 20th 2015 in scijs/cwise-compiler@77fc925 "Implemented array shape equality test.". Using cwise-compiler 1.0.0, also 1.1.0 does not have this check, but 1.1.2 does.

@deathcap
Copy link
Member Author

Pinning cwise-compiler to 1.0.0 (package.json: "cwise-compiler": "1.0.0" — instead of "^1.0.0") gets past this error, but then the same problem occurs in ops.assign() in voxel-mesher splitVoxelArray(). ndarray-ops 1.2.2, but then ndarray-fill 1.0.1 depends on cwise-compiler, rolling back to ^0.1.0 hits the esprima-six unpublishing issue (voxel/voxelmetaverse#60)

--- a/package.json
+++ b/package.json
@@ -8,18 +8,18 @@
   },
   "dependencies": {
     "block-models": "^0.1.0",
-    "cwise-compiler": "^1.0.0",
+    "cwise-compiler": "1.0.0",
     "gl-buffer": "^2.0.8",
     "gl-mat4": "^1.1.2",
     "gl-vao": "^1.1.3",
     "greedy-mesher": "^1.0.2",
     "inherits": "^2.0.1",
     "ndarray": "^1.0.15",
-    "ndarray-ops": "^1.2.2",
+    "ndarray-ops": "1.2.2",
     "typedarray-pool": "^1.0.2"
   },
   "devDependencies": {
-    "ndarray-fill": "^1.0.1",
+    "ndarray-fill": "1.0.1",
     "ndarray-segment": "0.0.0",
     "tap": "^0.6.0",
     "voxel": "^0.5.0"

@deathcap deathcap changed the title cwise: Arrays do not all have the same shape (ao 34**3 but array 36**3) [cwise-compiler >1.1.0] cwise: Arrays do not all have the same shape (ao 34**3 but array 36**3) Dec 30, 2015
deathcap added a commit that referenced this issue Dec 30, 2015
Versions after 1.1.0 added array shape equality test:
scijs/cwise-compiler@77fc925
which fails in voxel-mesher because of chunk padding (34**3 vs 36**3).
Stay on the older version for now, until #11
@deathcap
Copy link
Member Author

cwise-compiler 1.1.0 is compatible, sticking on it for now (voxel-mesher 0.14.3 bugfix release), but may want to revisit to upgrade to a newer version. The problem is voxel-mesher relies on unequal array sizes in order to add padding between the chunks, maybe could instead use .subarray() to get an equally-sized ndarray before passing to cwise. @jaspervdg any possibility the check added in scijs/cwise-compiler@77fc925 could be made optional?

deathcap referenced this issue in scijs/cwise-compiler Dec 30, 2015
deathcap added a commit to voxel/voxel-engine-stackgl that referenced this issue Dec 30, 2015
voxel/voxel-mesher#11 cwise: Arrays do not all have the same shape
voxel/voxel-shader#10 Broken dependency: glslify (esprima-six unpublished)
voxel/voxel-shader#11 gl-shader: Error compling vertex shader: ERROR: 0:18: '=' : global variable initializers must be constant expressions

Note that semver would have pulled in the voxel-mesher fix (^0.14.0 matches 0.14.3), but
since these fixes are all very important (either cannot run on modern browsers or build
in development environment, due to unpublished dependency), making the requirements explicit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant