Pregunta

I'm trying to understand why the error in the title occurs in my script. I tried to match every bracket in sublime and it seems fine.

Here is the code

<script>

window.onload = function(){
var socket = io.connect("http://localhost:1337");
socket.on("drawn_complete",function(data){
    imgData = ctx.getImageData(data.width, data.height);
    for (var i = 0; i < data.raw.length) {
        imgData.data[i] = data.raw[i];
    }
ctx.putImageData(imgData, 0, 0);
});


var c = document.getElementById("myCanvas");
var moving = false;
console.log(c);
 var ctx = c.getContext("2d");
c.onmousedown = function(evt){
moving = true
};
c.onmousemove = function(evt){
    if(moving == true)
    {
        console.log("holding and moving");

        var x = evt.clientX - rect.left;
        var y = evt.clientY - rect.top;
        console.log("X: " + x + " Y: " + y);
        ctx.fillRect(x,y,1,1);
        canvasData = ctx.getImageData(0,0,200,100)
        myData = {
        height : canvasData.height,
        width : canvasData.width,
        raw : canvasData.data
};
socket.emit("drawing",{"image": myData});

    }
};
c.onmouseup = function(evt){
    moving = false;
};
};

</script>

Am I missing a ")" or a "}" ? Might this error be thrown in my nodejs? If so shouldn't my console which runs nodejs stop? The console doesn't log any error nor does it stop.

¿Fue útil?

Solución

for (var i = 0; i < data.raw.length) {

You're missing the increment part (i++) for this for loop.

Otros consejos

on line no 5:

for (var i = 0; i < data.raw.length; i++){
imgData.data[i] = data.raw[i];
}

you forgot to increment i++

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top