sidorares / ntk

node.js desktop UI toolkit
91 stars 12 forks source link

Cannot read property 'id' of undefined #29

Open RossComputerGuy opened 7 years ago

RossComputerGuy commented 7 years ago
const FontManager = require("font-manager");
const ntk = require("ntk");
const x11 = require("x11");

function setFont(i,ctx) {
    var fnt = FontManager.getAvailableFontsSync()[i];
    var font = ctx.loadFont(fnt.path,fnt.weight,10,10);
    ctx.setFont(font);
    return ctx;
}

function draw(ctx,wnd) {
    setFont(0,ctx);
    ctx.fillStyle = "blue";
    ctx.fillRect(0,0,wnd.width,wnd.height);
    var txt = "Unfortunately, TGAC has stopped working!";
    ctx.fillText(txt,(wnd.width/2)-(ctx.measureText(txt).width/2),(wnd.height/2)-(ctx.measureText(txt).height/2));
}

ntk.createClient( (err, app) => {
    var window = app.createWindow({ width: 500, height: 300, title: "TGAC" });
    var ctx = window.getContext("2d");
    window.on("resize",(ev) => {
        draw(ctx,window);
    });
    window.map();
    draw(ctx,window);
});

This code results in this error:

/home/spaceboyross/Documents/TGAC/node_modules/ntk/lib/glyphset.js:13
    X.FreeGlyphSet(obj.id);
                      ^

TypeError: Cannot read property 'id' of undefined
    at EventEmitter.<anonymous> (/home/spaceboyross/Documents/TGAC/node_modules/ntk/lib/glyphset.js:13:23)
    at emitNone (events.js:86:13)
    at EventEmitter.emit (events.js:188:7)
    at callback (/home/spaceboyross/Documents/TGAC/node_modules/weak/lib/weak.js:108:11)
sidorares commented 7 years ago

thanks @SpaceboyRoss01 , I'll have a look later today when I'm at linux desktop

not sure exactly why obj can be undefined here https://github.com/sidorares/ntk/blob/e57066fe4679a6457e4cea39b3170299d6ce6a18/lib/glyphset.js#L12

you cat temporarily try to comment out X.FreeGlyphSet(obj.id); line that causes error

RossComputerGuy commented 7 years ago

I patched it myself by changing the code to

var ref = weak(this,() => {
    X.FreeGlyphSet(this.id);
});