beetrood February 2016

Bug causes that nothing is shown on Konva.js stage only from time to time. What to do?

I have a very strange behaviour of my script: only from time to time (seldom 3-4 times at one time right after each other, but more likely every 7th to 150th trial) the skript loads, but I only see a white canvas and get the error message:

Uncaught TypeError: Cannot read property 'getParent' of undefinedKonva.Util.addMethods.add @ konva.min.js:44draw @ floorplansurvey.php:950(anonymous function) @ floorplansurvey.php:985images.(anonymous function).onload @ floorplansurvey.php:390

On reload it often works again... I just have no idea at all what is happening here, the bug can't be forced/reproduced, I thank you so much, if you have anything you can help me with. Even a strategy for a clearer analysis would be helpful, sorry for being that unspecific and the long code

edit: I've made a jsfiddle under: https://jsfiddle.net/17548hmv/1/

run it several times, until the error occures these are the code snippets at:

@ floorplansurvey.php:390:

function loadImages(sources, draw) {
    //window.location.reload(true);
    var images = {};
    var loadedImages = 0;
    var numImages = 0;
    // get num of sources
    for(var src in sources) {
        numImages++;
    }
    for(var src in sources) {
        images[src] = new Image();
        images[src].onload = function() {
            if(++loadedImages >= numImages) {
                draw(images);
            }
        };
        images[src].src = sources[src];
    }
    delete (loadedImages);
    delete (numImages);
};

@ floorplansurvey.php:985images.(anonymous function).onload:

loadImages(sources, function(images) {
    draw(images);
});

@ floorplansurvey.php:950(anonymous function):

bglayer.add(plan);

Answers


beetrood February 2016

OK, sorry that it took me so long:

the solution wasn't that easy to find. I found that the script was loaded asynchronously and the png wasn't yet available by using chromes timeline analysis. so i went to my code and had to distinguish between the things, that really should be in the draw function and which not. i added the plan to the array of images (sources) that is loaded (src= ...) before executing draw() and then added

sources.onload= loadImages(sources, function(images) {
    draw(images);
});

at the end of my file... no it works without any problem. konva.js had nothing to do with it and is up to now (I'm almost ready) like designed for my project

thanks for the tip @lavrton, it took me on the right way

Post Status

Asked in February 2016
Viewed 3,307 times
Voted 5
Answered 1 times

Search




Leave an answer