Tastenkunst / brfv4_javascript_examples

BRFv4 - HTML5/Javascript - examples project. Reference implementation for all other platform example packages.
463 stars 148 forks source link

Integer overflow #32

Closed AlbertoConchasJ closed 6 years ago

AlbertoConchasJ commented 6 years ago

i am doing an application that detects facial artributes using as core brfv4, but after a while of working correctly, the aplication throws the exception:

RuntimeError: integer overflow BRFv4_JS_TK190218_v4.0.5_trial.js:325848:1 wasm-function[792] file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:325848:1 wasm-function[331] file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:124486:1 wasm-function[763] file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:288875:1 wasm-function[767] file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:291957:1 wasm-function[768] file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:294163:1 wasm-function[333] file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:128272:1 wasm-function[349] file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:141683:1 wasm-function[867] file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:378388:1 wasm-function[602] file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:214167:1 brfv4SDK/Module.__brf_update file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:4:43219 initializeBRF/</lib.BRFv4Context/_this.update file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:23:405 initializeBRF/</lib.BRFv4ContextManager/_this.update file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/js/libs/brf_wasm/BRFv4_JS_TK190218_v4.0.5_trial.js:43:168 trackFaces file:///home/user/Documentos/Desarrollo/DEMO/MiDEMO_face/index.html:530:4

this is my trackFaces function:

function trackFaces() {

            if (stats.start) stats.start();

            imageDataCtx.setTransform(-1.0, 0, 0, 1, resolution.width, 0); // mirrored for draw of video
            imageDataCtx.drawImage(webcam, 0, 0, resolution.width, resolution.height);
            imageDataCtx.setTransform( 1.0, 0, 0, 1, 0, 0); // unmirrored for draw of results

            brfManager.update(imageDataCtx.getImageData(0, 0, resolution.width, resolution.height).data); //line 530

            var faces = brfManager.getFaces();

            for(var i = 0; i < faces.length; i++) {

                var face = faces[i];
                //console.log("facestate: "+face.state+" Lastfacestate: "+lastFaceState );
                //console.log(face.state);
                if(face.state === brfv4.BRFState.FACE_TRACKING_START || face.state === brfv4.BRFState.FACE_TRACKING) {
                    //console.log("Cara detectada");
                    if (face.state === brfv4.BRFState.FACE_TRACKING_START && lastFaceState) {

                        //console.log("Se detecto una nueva cara");
                        readImg();
                        lastFaceState=false;

                    }
                    if (face.state === brfv4.BRFState.FACE_TRACKING){
                        lastFaceState=true;

                    }

                    imageDataCtx.strokeStyle="#00a0ff";

                    for(var k = 0; k < face.vertices.length; k += 2) {
                        imageDataCtx.beginPath();
                        imageDataCtx.arc(face.vertices[k], face.vertices[k + 1], 2, 0, 2 * Math.PI);
                        imageDataCtx.stroke();
                    }

                    // Set position to be nose top and calculate rotation.

                    function toDegree(x) {
                        return x * 180.0 / Math.PI;
                    }

                    var x = face.points[27].x;
                    var y = face.points[27].y;
                    var scaleX = (face.scale / 480) * (1 - toDegree(Math.abs(face.rotationY)) / 110.0) * 2.5;
                    var scaleY = (face.scale / 480) * (1 - toDegree(Math.abs(face.rotationX)) / 110.0) * 2.5;

                    mask.style.transform = "matrix("+scaleX+",0.0,0.0,"+scaleY+","+x+","+y+") rotate("+face.rotationZ+"rad)";
                    mask.style.opacity = "0.66";
                }
                else {
                    mask.style.opacity = "0.0";
                    //console.log("Cara no  detectada");

                }

            }

            if (stats.end) stats.end();

            requestAnimationFrame(trackFaces);
        }

and this is the line 530:
brfManager.update(imageDataCtx.getImageData(0, 0, resolution.width, resolution.height).data);

anyone knows what i am doing wrong?

thanks in advance

MarcelKlammer commented 6 years ago

file:/// means that you are not running this app on a server, no localhost etc.?

Would you be able to upload your app to a web server, so I could take a look?

AlbertoConchasJ commented 6 years ago

yes, you can check the app in this link:

https://aioxxo.inbest.cloud/index.html

greetings

MarcelKlammer commented 6 years ago

What browser brings up this error?

AlbertoConchasJ commented 6 years ago

Firefox

AlbertoConchasJ commented 6 years ago

i changed the url to: https://aioxxo.inbest.cloud/camera.html

MarcelKlammer commented 6 years ago

Seems to be related to: https://kripken.github.io/emscripten-site/docs/compiling/WebAssembly.html#trap-mode

The current release was exported with trap mode clamp.