jprichardson/electron-window

Error message when closing window

Closed this issue · 3 comments

As of Electron v0.35.4, the following error message is shown within an alert dialog whenever a window is closed that was created with ElectronWindow.

Uncaught Exception:
Error: Object has been destroyed
at Error (native)
at BrowserWindow._unref (/Users/adamdrago/Documents/git/negative/node_modules/electron-window/lib/main.js:25:23)
at BrowserWindow.g (events.js:260:16)
at emitOne (events.js:82:20)
at BrowserWindow.emit (events.js:169:7)

screen shot 2015-12-05 at 8 15 04 am

I haven't had time to look into the actual cause of the issue. Will update once I know more.

The problem is that this within the closed event still references the BrowserWindow, but the BrowserWindow no longer has an id property. https://github.com/jprichardson/electron-window/blob/master/lib/main.js#L25

Even just referencing this.id within _unref() causes the above error message. The id is only used to remove the reference to the window from _windows so this could be changed.

I found this, which could be related, but I'm no C++ expert:
electron/electron@973ae06

This may be more of an Electron issue than an ElectronWindow issue. However, if not, the following could be used to remove the reference.:

function _unref () {
    for (var id in _windows) {
        if (_windows.hasOwnProperty(id)) {
            if (Object.is(_windows[id], this)) {
                delete _windows[id];
                break;
            }
        }
    }
    // delete _windows[this.id]
}

I suspect just changing https://github.com/jprichardson/electron-window/blob/0.6.0/lib/main.js#L46 'closed' to 'close' will fix it.