Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] close second window during "blur" event will also close the main window in Windows #3893

Closed
jwu opened this issue Dec 22, 2015 · 1 comment · Fixed by #5131
Closed

Comments

@jwu
Copy link

jwu commented Dec 22, 2015

This problem only happen in Windows platform. When I try to close a second window in its "blur" event, it will lead to close all other window which make the app quit.

I paste the sample code below for this bug. I also create a simple project to quick access the problem: https://github.com/jwu/electron-close-blur-window .

I test this in Windows 10, with electron 0.34.3 and 0.36.1. Both of them have the same problem.

The code lead to this strange thing is:

 ...
 ...
 aboutWindow.on('blur',function () {
    aboutWindow.close();
 });
 ...
 ...

If I comment out the above code, and close the about window manually, it will not make main-window closed.

And here is the full main.js:

'use strict';

const Electron = require('electron');
const BrowserWindow = Electron.BrowserWindow;
const app = Electron.app;

// quit when all windows are closed.
app.on('window-all-closed', () => {
  app.quit();
});

app.on('ready', () => {
  // main window
  let mainWindow = new BrowserWindow( {
    title: 'Main',
    width: 800,
    height: 600,
  });

  mainWindow.loadUrl(`file://${__dirname}/page/index.html`);
  mainWindow.show();
  // mainWindow.openDevTools();

  // about window
  let postion_ = mainWindow.getPosition();
  let size_ = mainWindow.getSize();
  let x = (postion_[0] + size_[0]/2 - 200);
  let y = (postion_[1] + size_[1]/2 - 90);

  let aboutWindow = new BrowserWindow({
    'title': 'about',
    'x': Math.floor(x),
    'y': Math.floor(y),
    'width': 400,
    'height': 200,
    'always-on-top': true,
    'show': false,
    'resizable': false,
  });

  aboutWindow.loadUrl(`file://${__dirname}/page/index.html`);
  aboutWindow.setMenuBarVisibility(false);
  aboutWindow.show();
  aboutWindow.on('blur',function () {
    aboutWindow.close();
  });

});
@zcbenz
Copy link
Contributor

zcbenz commented Dec 23, 2015

The main process crashed when calling win.close(), stack trace:

0:000> k
Child-SP          RetAddr           Call Site
00000068`3e2abd20 00007ff6`23bfa86e electron!atom::NativeWindow::RequestToClosePage+0x119 [c:\cygwin\home\zcbenz\codes\electron\atom\browser\native_window.cc @ 357]
00000068`3e2abdd0 00007ffe`58ade6ee electron!atom::`anonymous namespace'::NativeWindowClientView::CanClose+0x6e [c:\cygwin\home\zcbenz\codes\electron\atom\browser\native_window_views.cc @ 114]
00000068`3e2abe20 00007ff6`23bfa9a9 views!views::MenuItemView::GetMenuController+0xa5e80
00000068`3e2abf90 00007ff6`23ab3c24 electron!atom::NativeWindowViews::Close+0x49 [c:\cygwin\home\zcbenz\codes\electron\atom\browser\native_window_views.cc @ 292]
00000068`3e2abfd0 00007ff6`23abe1c1 electron!atom::api::Window::Close+0x44 [c:\cygwin\home\zcbenz\codes\electron\atom\browser\api\atom_api_window.cc @ 285]
00000068`3e2ac010 00007ff6`23aba87a electron!base::internal::RunnableAdapter<void (__cdecl atom::api::Window::*)(void) __ptr64>::Run+0x41 [c:\cygwin\home\zcbenz\codes\electron\vendor\brightray\vendor\download\libchromiumcontent\src\base\bind_internal.h @ 177]
00000068`3e2ac040 00007ff6`23abd50d electron!base::internal::InvokeHelper<0,void,base::internal::RunnableAdapter<void (__cdecl atom::api::Window::*)(void) __ptr64>,base::internal::TypeList<atom::api::Window * __ptr64 const & __ptr64> >::MakeItSo+0x3a [c:\cygwin\home\zcbenz\codes\electron\vendor\brightray\vendor\download\libchromiumcontent\src\base\bind_internal.h @ 294]
00000068`3e2ac070 00007ff6`23abc169 electron!base::internal::Invoker<base::IndexSequence<>,base::internal::BindState<base::internal::RunnableAdapter<void (__cdecl atom::api::Window::*)(void) __ptr64>,void __cdecl(atom::api::Window * __ptr64),base::internal::TypeList<> >,base::internal::TypeList<>,base::internal::InvokeHelper<0,void,base::internal::RunnableAdapter<void (__cdecl atom::api::Window::*)(void) __ptr64>,base::internal::TypeList<atom::api::Window * __ptr64 const & __ptr64> >,void __cdecl(atom::api::Window * __ptr64 const & __ptr64)>::Run+0x5d [c:\cygwin\home\zcbenz\codes\electron\vendor\brightray\vendor\download\libchromiumcontent\src\base\bind_internal.h @ 347]
00000068`3e2ac0d0 00007ff6`23ab814b electron!base::Callback<void __cdecl(atom::api::Window * __ptr64)>::Run+0x59 [c:\cygwin\home\zcbenz\codes\electron\vendor\brightray\vendor\download\libchromiumcontent\src\base\callback.h @ 397]
00000068`3e2ac110 00007ff6`23ab6220 electron!mate::internal::Invoker<mate::internal::IndicesHolder<0>,atom::api::Window * __ptr64>::DispatchToCallback+0x3b [c:\cygwin\home\zcbenz\codes\electron\vendor\native_mate\native_mate\function_template.h @ 194]
00000068`3e2ac150 00007ffe`5de5c96b electron!mate::internal::Dispatcher<void __cdecl(atom::api::Window * __ptr64)>::DispatchToCallback+0x1b0 [c:\cygwin\home\zcbenz\codes\electron\vendor\native_mate\native_mate\function_template.h @ 228]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants