trodi / electron-splashscreen

Simple splashscreen for electron applications.
MIT License
170 stars 29 forks source link

`Error: Object has been destroyed` #19

Closed jgierer12 closed 5 years ago

jgierer12 commented 5 years ago

Description

Occasionally, an error Object has been destroyed is thrown on window startup, preventing the application from launching:

Full error

Environment

Steps to Reproduce

I have not yet been able to reproduce this consistently. The app in question is jgierer12/pocket-casts-linux.

Expected behaviour

The application launches correctly without errors.

Actual behaviour

The above Object has been destroyed error is thrown and the application does not launch.

Related issues

Related discussions are in jgierer12/pocket-casts-linux#3, jgierer12/pocket-casts-linux#4, and jgierer12/pocket-casts-linux#7

trodi commented 5 years ago

It looks like the error is thrown when attempting to close the splashscreen app and the app object has already been destroyed. Possibly if the splashscreen took too long to load. I'm looking into it. Thanks.

saurabhabh commented 5 years ago

Hello @trodi I am getting the same error when I created the setup of my electron app via electron-winstaller and tried installing the application. I am using : "electron": "2.0.7"

[Window Title] Error

[Main Instruction] A JavaScript error occurred in the main process

[Content] Uncaught Exception: Error: Object has been destroyed at Timeout._onTimeout (C:\Users\Saurabh Abhyankar\AppData\Local\dentchat\app-1.1.0\resources\app.asar\node_modules\@trodi\electron-splashscreen\index.js:41:30) at ontimeout (timers.js:475:11) at tryOnTimeout (timers.js:310:5) at Timer.listOnTimeout (timers.js:270:5)

[OK]

Below is the setup for the splash screen window.

const windowOptions = {
    width: 1000,//size.width/3,
     height: 1000,//size.height/5 * 3,
    minWidth:600,
    minHeight:600,
    frame:true, 
    resizable:true,
    show: false,
  };
  win = Splashscreen.initSplashScreen({
    windowOpts: windowOptions,
    templateUrl: path.join(__dirname, 'dist/assets/splash.svg'),
    delay: 0, // force show immediately since example will load fast
    minVisible: 5000, // show for 1.5s so example is obvious
    splashScreenOpts: {
        width: 500,//size.width/3,y
        height: 500,//size.height/5 * 3,
        transparent: true
    },
});

And my electron-winstaller setup is default as they have suggested handling-squirrel-events

Also it runs fine showing the splash screen on app start up after install. I get this issue only when installing. I think it is because electron-winstaller using squirrel quits the app and relaunches it.

trodi commented 5 years ago

I think it is because electron-winstaller using squirrel quits the app and relaunches it.

@saurabhabh You are correct, this error will occur if squirrel is quitting from under us, but this is easily avoided. You should inspect the squirrel flags and shouldn't attempt to load your main app (which is tied to your splashscreen) when installing, rather you should handle any installer tasks (e.g., adding a short cut to the desktop), and then quit the app. You wouldn't initialize the splashscreen in this use case. Did you want to run the splashscreen in this squirrel run?

From handling-squirrel-events:

it is very important that your app handle these events as early as possible, and quit immediately after handling them

@jgierer12 Are you seeing this only on squirrel installer runs as well or also on normal app runs?

I can always catch any errors when attempting to close the splashscreen to avoid this if there are valid use cases where we can't successfully close it.

jgierer12 commented 5 years ago

I am on Linux so I don't even have the possibility to run the squirrel installer :wink:

This occurred occasionally when running the app normally. I have since removed the splashscreen from my app in order to avoid these errors, as they prevented the app from launching. So unfortunately I don't have enough experience with the bug to tell exactly how often and under which circumstances it happens.

All I know is that both me and one of my users noticed the error after I applied a patch (jgierer12/pocket-casts-linux#4). Whether the patch really was the cause of the issue, I don't know. Since the error didn't happen regularly, it could have also been caused by a prior change (I upgraded electron from v3.0.13 to v4.1.0 not long before).

The weird thing is that even after I checked out a branch without the change, the error kept occurring (I yarn installed and rebuilt the project after the checkout of course). After that I tried everything, clearing caches, clearing app data etc. etc. but nothing worked. Only removing the splash screen resolved the issue.

trodi commented 5 years ago

@jgierer12 I've made a change which I believe will fix your issue. I'm not sure why you were able to get into this situation, however, I can artificially create it and see the fix avoids your error. I don't have a linux test environment to do more testing however. If you'd like to test with the fix, let me know if you no longer see the error. FYI, I've not published the update to npm yet.

trodi commented 4 years ago

FYI, I was able to reproduce this error being thrown on windows by closing the app while the splashscreen was still running (without the fix). Testing with the fix, the issue was indeed resolved.

This fix is now published as part of v1.0.0.