cesium icon indicating copy to clipboard operation
cesium copied to clipboard

DeveloperError: normalized result is not a number

Open grmc144 opened this issue 7 years ago • 53 comments

ipmsgclip_r_1484313212_0

grmc144 avatar Jan 13 '17 13:01 grmc144

@grmc144 I wasn't able to reproduce this. Could you please provide more information? Thanks!

hpinkos avatar Jan 13 '17 17:01 hpinkos

I also came across this recently but haven't been able to reproduce it on Sandcastle. I was able to get around it by setting scene3DOnly: true after seeing that mentioned in the forums.

ketulm avatar Jan 19 '17 02:01 ketulm

This seems to happen when your cartesian coordinate is 0,0,0. The resulting magnitude then is also 0 which results in a division by 0 in the normalize function. (see https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/Cartesian3.js#L408)

It happens a lot with us when transforming our data to a custom cartesian tiling grid where the lower left vertex usually falls on 0,0,0.

tomvantilburg avatar Jan 19 '17 08:01 tomvantilburg

@ketulm @tomvantilburg do either of you have sample code or sample data to reproduce this? Cesium shouldn't be trying to normalize the zero vector. This case should be caught further up the pipeline before this error is thrown.

hpinkos avatar Jan 19 '17 14:01 hpinkos

This should do the trick: Cesium.Cartesian3.normalize({x: 0, y: 0, z: 0},{x: 0, y: 0, z: 0})

tomvantilburg avatar Jan 19 '17 17:01 tomvantilburg

Thanks @tomvantilburg, but I know that's what is causing the developer error to be thrown. The error is in place so we can catch bad data coming in from other parts of the code, so it is expected to be thrown when you're trying to normalize the zero vector. It would be helpful if you could give me an example of a polygon or something higher level that's causing the error to be thrown.

hpinkos avatar Jan 19 '17 17:01 hpinkos

Thanks for looking into this @hpinkos and sorry for being not verbose. Here's the full story:

We are trying to convert a set of obj files to a gltf file with the help of obj2gltf. The error message shows up in obj2gltf but originates from cesium (see stack below). Oddly enough, there are no vector normals in the obj file, so I can't see where this goes wrong along the way. Worth noting: We did translate all coordinates to a 0 0 based grid first, so some lower left coordinates are very close to 0, 0, 0

Here is the defaulting obj file: ~~http://research.geodan.nl/sites/cesium/data/object.tar.gz~~ http://research.geodan.nl/sites/cesium/data/object2.tar.gz

And here the corresponding code calling for obj2gltf: https://github.com/Geodan/3dfier-tiles/blob/master/src/obj2gltf.js

Error Stack:

{ [DeveloperError: normalized result is not a number]
  name: 'DeveloperError',
  message: 'normalized result is not a number',
  stack: 'Error\n    at new DeveloperError (/var/data/git_repos/3dfier-tiles/node_modules/cesium/Source/Core/DeveloperError.js:44:19)\n    at Function.Cartesian3.normalize (/var/data/git_repos/3dfier-tiles/node_modules/cesium/Source/Core/Cartesian3.js:422:19)\n    at Object.GeometryPipeline.computeNormal (/var/data/git_repos/3dfier-tiles/node_modules/cesium/Source/Core/GeometryPipeline.js:1176:28)\n    at generateNormals (/var/data/git_repos/3dfier-tiles/node_modules/gltf-pipeline/lib/generateNormals.js:57:34)\n    at Function.Pipeline.processJSONWithExtras (/var/data/git_repos/3dfier-tiles/node_modules/gltf-pipeline/lib/Pipeline.js:91:5)\n    at /var/data/git_repos/3dfier-tiles/node_modules/gltf-pipeline/lib/Pipeline.js:194:29\n    at tryCatcher (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/promise.js:510:31)\n    at Promise._settlePromise (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/promise.js:567:18)\n    at Promise._settlePromise0 (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/promise.js:612:10)\n    at Promise._settlePromises (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/promise.js:691:18)\n    at Async._drainQueue (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/async.js:133:16)\n    at Async._drainQueues (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/async.js:143:10)\n    at Immediate.Async.drainQueues [as _onImmediate] (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/async.js:17:14)\n    at processImmediate [as _immediateCallback] (timers.js:383:17)' }

tomvantilburg avatar Jan 20 '17 09:01 tomvantilburg

It looks like the error is coming from the part of the glTF pipeline that generates vertex normals, it might be trying to generate normals for a triangle that has two or more identical positions, hence the divide by zero error.

I'm not getting any problems with the linked file and the obj2gltf command line tool, though. You mentioned translating all coordinates to a 0, 0 based grid, any chance there's something going wrong in that stage?

On Fri, Jan 20, 2017 at 4:04 AM, Tom van Tilburg [email protected] wrote:

Thanks for looking into this @hpinkos https://github.com/hpinkos and sorry for being not verbose. Here's the full story:

We are trying to convert a set of obj files to a gltf file with the help of obj2gltf. The error message shows up in obj2gltf but originates from cesium (see stack below). Oddly enough, there are no vector normals in the obj file, so I can't see where this goes wrong along the way. Worth noting: We did translate all coordinates to a 0 0 based grid first, so some lower left coordinates are very close to 0, 0, 0

Here is the defaulting obj file: http://research.geodan.nl/ sites/cesium/data/object.tar.gz And here the corresponding code calling for obj2gltf: https://github.com/Geodan/3dfier-tiles/blob/master/src/obj2gltf.js

Error Stack:

{ [DeveloperError: normalized result is not a number] name: 'DeveloperError', message: 'normalized result is not a number', stack: 'Error\n at new DeveloperError (/var/data/git_repos/3dfier-tiles/node_modules/cesium/Source/Core/DeveloperError.js:44:19)\n at Function.Cartesian3.normalize (/var/data/git_repos/3dfier-tiles/node_modules/cesium/Source/Core/Cartesian3.js:422:19)\n at Object.GeometryPipeline.computeNormal (/var/data/git_repos/3dfier-tiles/node_modules/cesium/Source/Core/GeometryPipeline.js:1176:28)\n at generateNormals (/var/data/git_repos/3dfier-tiles/node_modules/gltf-pipeline/lib/generateNormals.js:57:34)\n at Function.Pipeline.processJSONWithExtras (/var/data/git_repos/3dfier-tiles/node_modules/gltf-pipeline/lib/Pipeline.js:91:5)\n at /var/data/git_repos/3dfier-tiles/node_modules/gltf-pipeline/lib/Pipeline.js:194:29\n at tryCatcher (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/util.js:16:23)\n at Promise._settlePromiseFromHandler (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/promise.js:510:31)\n at Promise._settlePromise (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/promise.js:567:18)\n at Promise._settlePromise0 (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/promise.js:612:10)\n at Promise._settlePromises (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/promise.js:691:18)\n at Async._drainQueue (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/async.js:133:16)\n at Async._drainQueues (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/async.js:143:10)\n at Immediate.Async.drainQueues [as _onImmediate] (/var/data/git_repos/3dfier-tiles/node_modules/bluebird/js/release/async.js:17:14)\n at processImmediate [as _immediateCallback] (timers.js:383:17)' }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AnalyticalGraphicsInc/cesium/issues/4863#issuecomment-274016146, or mute the thread https://github.com/notifications/unsubscribe-auth/AFJTN_ComS75gm2mR0WV-NY8gZQh50D_ks5rUHiGgaJpZM4Li3so .

likangning93 avatar Jan 20 '17 13:01 likangning93

that error came on angular js error.now its fix

error

grmc144 avatar Jan 20 '17 13:01 grmc144

It seems I gave the wrong example file, apologies. Here is one that goes wrong: http://research.geodan.nl/sites/cesium/data/object2.tar.gz

tomvantilburg avatar Jan 24 '17 15:01 tomvantilburg

I'm not getting errors from the obj2gltf command line tool with this one as-is either, so I think it might be the translation thing. Have you considered using the node transform https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#transforms attribute in glTF instead of translating the points in the obj file? This might get around the problem if it's with translating obj positions.

On Tue, Jan 24, 2017 at 10:29 AM, Tom van Tilburg [email protected] wrote:

It seems I gave the wrong example file, apologies. Here is one that goes wrong: http://research.geodan.nl/sites/cesium/data/object2.tar.gz

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/AnalyticalGraphicsInc/cesium/issues/4863#issuecomment-274836821, or mute the thread https://github.com/notifications/unsubscribe-auth/AFJTN6c2aho5I7F7HYcmaLdiIgxdOq74ks5rVhj1gaJpZM4Li3so .

likangning93 avatar Jan 27 '17 14:01 likangning93

problem_obj.zip

I ran into this same problem, using the obj in the zip and obj2gltf as well. I haven't modified it at all.

JakeDluhy avatar Feb 10 '17 23:02 JakeDluhy

Looks like it's happening at line 1178 of GeometryPipeline:

Cartesian3.clone(Cartesian3.ZERO, normal);
for (j = 0; j < vertexNormalData.count; j++) {
    Cartesian3.add(normal, normalsPerTriangle[normalIndices[vertexNormalData.indexOffset + j]], normal);
}
Cartesian3.normalize(normal, normal);

In my case vertexNormalData.count is 2, but both of the normalsPerTriangle values are also 0,0,0 so it all adds up to 0,0,0.

JakeDluhy avatar Feb 11 '17 02:02 JakeDluhy

@JakeDluhy sorry for the extremely slow response. This case can happen if your model's winding order is inconsistent, see here: https://github.com/AnalyticalGraphicsInc/gltf-pipeline/issues/242#issuecomment-280711872

For now, if you can get your model imported into blender and then re-exported with normals, it should be able to go through obj2gltf without having to compute new normals. We're working on a fix in the meantime.

likangning93 avatar Feb 22 '17 14:02 likangning93

Hi Guys, this is a little off topic, but same error. Looks like if you have a polygon covering the poles that has a fill a DeveloperError: normalized result is not a number error is thrown.

The following code gives an example.

var viewer = new Cesium.Viewer('cesiumContainer');

var hierarchy = [ -180,90,-180,50,180,50,180,90];

viewer.entities.add({
    polygon: {
        hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(hierarchy)),
        outline: true,
        outlineColor: Cesium.Color.YELLOW,
        fill: true,
        //fill: false,
        material: Cesium.Color.RED,
        outlineWidth: 10
    }
})

Setting fill to false results in no error being thrown.

normalizeissue

cfickler avatar Jun 16 '17 00:06 cfickler

Thanks @cfickler! We have an issue written up for that as well in #4801

hpinkos avatar Jun 19 '17 14:06 hpinkos

I get this while drawing walls. Here is sandcastle working and not working data example:

var viewer = new Cesium.Viewer('cesiumContainer');

var dataOk = [{"x":4275945.9824068565,"y":1107800.9025642173,"z":4587695.880722421},{"x":4275942.364458469,"y":1107810.0271602964,"z":4587697.218922266},{"x":4275939.159145871,"y":1107819.8152021402,"z":4587699.22238232},{"x":4275935.301931963,"y":1107826.779722856,"z":4587702.506606695},{"x":4275932.072016638,"y":1107833.9067606523,"z":4587703.787370615},{"x":4275927.503940587,"y":1107840.687092489,"z":4587703.622741782},{"x":4275926.76592329,"y":1107841.8396275593,"z":4587703.553797735}];

var dataFail = [{"x":4275839.559924875,"y":1108128.491490115,"z":4587218.256350457},{"x":4275839.560187584,"y":1108128.4915581993,"z":4587218.255867044},{"x":4275839.560187584,"y":1108128.4915581993,"z":4587218.255867044},{"x":4275839.560187584,"y":1108128.4915581993,"z":4587218.255867044},{"x":4275839.560187584,"y":1108128.4915581993,"z":4587218.255867044},{"x":4275839.560187584,"y":1108128.4915581993,"z":4587218.255867044},{"x":4275839.559983776,"y":1108128.4926396976,"z":4587218.25594444}];

var wall = {
  wall: {
    // positions: dataOk, // works
    positions: dataFail, // does not work: DeveloperError: normalized result is not a number
    material: Cesium.Color.fromCssColorString('red').withAlpha(0.2),
    outline: true,
    outlineColor: Cesium.Color.fromCssColorString('red').withAlpha(0.2)
  }
};
 
viewer.entities.add(wall);

viewer.scene.camera.flyTo({
    destination: new Cesium.Cartesian3(4275945.9824068565, 1107800.9025642173, 4587695.880722421),
});

primozs avatar Dec 14 '17 11:12 primozs

Thanks for reporting this @primozs! I opened a new issue for this because it's not the same problem as the other issues reported in this issue: #6050

hpinkos avatar Dec 14 '17 15:12 hpinkos

You can reproduce this problem in the billboard sandcastle:

https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Billboards.html&label=

Zoom in close-ish to the Cesium billboard and hold the mousewheel down to rotate. If you rotate over and over in random directions (basically spinning around) then the normalize error will occur.

error

DustinPham avatar Apr 24 '18 22:04 DustinPham

Hi! I have this same problem, and I can reproduce it. Just use this code:

console.log("teste");
var x = new Cesium.Cartesian3(0.0, 0.0, 0.0);
var r = new Cesium.Cartesian3();
console.log(x);
console.log(r);
Cesium.Cartesian3.normalize(x, r);
console.log("FIM Teste");

I use the code on https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Billboards.html&label= and add this code in line 17.

the function became

function addBillboard() { Sandcastle.declare(addBillboard);

viewer.entities.add({
    position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
    billboard :{
        image : '../images/Cesium_Logo_overlay.png'
    }
});

console.log("teste");
var x = new Cesium.Cartesian3(0.0, 0.0, 0.0);
var r = new Cesium.Cartesian3();
console.log(x);
console.log(r);
Cesium.Cartesian3.normalize(x, r);
console.log("FIM Teste");

}

The problem really happens on normalize with (0,0,0)

Its easy to correct the Cesium code.

Just verify 3258 of Cesiun.js var magnitude = Cartesian3.magnitude(cartesian);

before calc result, verify if magnitude is 0; or to be more smart, verify before to call normalize, because normalizing a vector with zeros is everytime zero.

gtzaniboni avatar May 16 '18 23:05 gtzaniboni

@gtzaniboni It is expected that Cartesian3.normalize throws if you try to normalize the zero vector. The zero vector doesn't have a direction, so we can't create a vector with a magnitude of 1 in the direction of that vector.

hpinkos avatar May 21 '18 15:05 hpinkos

image Hi! I have this same problem, and I can reproduce it. code:`var viewer = new Cesium.Viewer('cesiumContainer');

var greenPolygon = viewer.entities.add({ name : 'Green extruded polygon', polygon : { hierarchy:{ positions:[ {x:-1282429.5526432437,y:5188158.424384381,z:3469566.094463261}, {x:-1282588.3417658736,y:5188166.113893098,z:3469496.3696201444}, {x:-1282690.3232170227,y:5188085.603724499,z:3469578.504749636}, {x:-1282441.982679572,y:5188092.993331375,z:3469658.715187507}, {x:-1282927.91953463,y:5190058.841008679,z:3470982.2823311253} ] }, extrudedHeight:2423.0, material:Cesium.Color.GREEN.withAlpha(0.3), outline:true, outlineColor:Cesium.Color.WHITE, outlineWidth:2.0, closeTop:false, closeBottom:false } });

viewer.zoomTo(viewer.entities);`

chenluweixi avatar Jun 25 '18 07:06 chenluweixi

What you have is a polygon with a duplicate point in latitude/longitude, differing only in height.

(103.88428702847558, 33.16795772591805, 0) (103.88591985578114, 33.16720668602253, 0) (103.88718838345685, 33.1680914037599, 0) (103.8845847278203, 33.16895539819639, 0) (103.8845847278203, 33.16895539819639, 2419.198565875114)

This will work if perPositionHeight: true is specified when you define the polygon.

GatorScott avatar Jun 25 '18 12:06 GatorScott

Thanks for reporting that @chenluweix! We should be removing those duplicate positions to avoid that crash. I open up this pull request to fix that problem: #6731

hpinkos avatar Jun 25 '18 17:06 hpinkos

@hpinkos just downloaded the 1.5 Cesium version and this error is still happening.

img_0638

p

andreddosantos avatar Oct 09 '18 14:10 andreddosantos

@andreddosantos can you please paste a code example to reproduce the issue?

hpinkos avatar Oct 09 '18 15:10 hpinkos

Yup! So i'm loading a tile from a local nodejs server running in iOS from the ionic framework.

const viewer = new Cesium.Viewer(this.el.nativeElement, {
  scene3DOnly: true,
  selectionIndicator: false,
  animation: true,
  timeline: false,

  baseLayerPicker: false,
  fullscreenButton: false,
  vrButton: false
});

const tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ url: 'http://localhost:3000/tileset.json' }));


viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0, -0.5, 0));

I can't send you the tileset that i'm working on :( ... but is a city being rendered... I hope this helps. Let me know if can help with anything else ...

Well i could try to load the samples in here "https://github.com/AnalyticalGraphicsInc/3d-tiles-samples", and see if the error is only happening on my tileset files

andreddosantos avatar Oct 09 '18 15:10 andreddosantos

DEBUG :

 Cartesian3.normalize = function(cartesian, result) {
                Check.typeOf.object('cartesian', cartesian);
        Check.typeOf.object('result', result);

        var magnitude = Cartesian3.magnitude(cartesian);

        result.x = cartesian.x / magnitude;
        result.y = cartesian.y / magnitude;
        result.z = cartesian.z / magnitude;

        if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {
            console.log("magnitude " + 0)
            console.log("cartesian --> x: " + cartesian.x + " y: " + cartesian.y + " z: " + cartesian.z)
            console.log("Result --> x: " + result.x + " y: " + result.y + " z: " + result.z)
            throw new DeveloperError('normalized result is not a number');
        }

            return result;
        };

Result:

 magnitude : 0
 cartesian --> x: NaN y: NaN z: NaN
 Result --> x: NaN y: NaN z: NaN

This happens when doing the following gesture

image

andreddosantos avatar Oct 10 '18 01:10 andreddosantos

I dont know if its works, reply by the email.... André,

a função normalize não espera nunca um vetor nulo. Todavia, o próprio canvas, quando movimentamos, pode ocasionar isso. Já tentei falar, mas não aceitaram.

Faz assim, se a magnitude == 0 retorna o proprio vetor... isso resolve esse bug.

ABraço,

Em ter, 9 de out de 2018 às 22:58, André dos Santos < [email protected]> escreveu:

DEBUG :

Cartesian3.normalize = function(cartesian, result) { Check.typeOf.object('cartesian', cartesian); Check.typeOf.object('result', result);

    var magnitude = Cartesian3.magnitude(cartesian);

    result.x = cartesian.x / magnitude;
    result.y = cartesian.y / magnitude;
    result.z = cartesian.z / magnitude;

    if (isNaN(result.x) || isNaN(result.y) || isNaN(result.z)) {
        console.log("cartesian --> x: " + cartesian.x + " y: " + cartesian.y + " z: " + cartesian.z)
        console.log("Result --> x: " + result.x + " y: " + result.y + " z: " + result.z)
        throw new DeveloperError('normalized result is not a number');
    }

        return result;
    };

Result:

cartesian --> x: NaN y: NaN z: NaN Result --> x: NaN y: NaN z: NaN

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AnalyticalGraphicsInc/cesium/issues/4863#issuecomment-428411685, or mute the thread https://github.com/notifications/unsubscribe-auth/Alh5m1PrAh7Yn9MwiT6BUyL1LHFYYOIrks5ujVQqgaJpZM4Li3so .

gtzaniboni avatar Oct 10 '18 02:10 gtzaniboni

@gtzaniboni thank you for answer, i''ve done a similar local fix myself ahah, and its kind of working, at least the app doesn't crash and i get to see the full tiles. But it would be great if someone from cesium with more context of the code, could solve it.

andreddosantos avatar Oct 10 '18 08:10 andreddosantos