]> khamidou — GitHub mirrors - electron.git/commitdiff
Don't send ATOM_BROWSER_DEREFERENCE message if context is already gone.
authorCheng Zhao <zcbenz@gmail.com>
Sat, 4 May 2013 15:00:57 +0000 (23:00 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sat, 4 May 2013 15:00:57 +0000 (23:00 +0800)
It's possible that the object gets destructed after reloading, however
since we already released all objects in browser when unloading, it
would cause troubles when sending message in an unexist context. We just
rely on the closure to mark whether the context is gone.

A more suitable solution, however, is to restart renderer process when
doing reloading.

renderer/api/lib/remote.coffee

index 8e99e0c2f2487959fddda7a79deb60e078f952f5..8416fd8a8ea9f70c61fd4dbde815d5b4ffadc55c 100644 (file)
@@ -1,6 +1,8 @@
 ipc = require 'ipc'
 v8_util = process.atomBinding 'v8_util'
 
+currentContextExist = true
+
 class CallbacksRegistry
   @nextId = 0
   @callbacks = {}
@@ -73,6 +75,7 @@ metaToValue = (meta) ->
       # Track delegate object's life time, and tell the browser to clean up
       # when the object is GCed.
       v8_util.setDestructor ret, ->
+        return unless currentContextExist
         ipc.sendChannel 'ATOM_BROWSER_DEREFERENCE', meta.storeId
 
       # Mark this is a remote object.
@@ -90,6 +93,7 @@ ipc.on 'ATOM_RENDERER_RELEASE_CALLBACK', (id) ->
 
 # Release all resources of current render view when it's going to be unloaded.
 window.addEventListener 'unload', (event) ->
+  currentContextExist = false
   ipc.sendChannelSync 'ATOM_BROWSER_RELEASE_RENDER_VIEW'
 
 # Get remote module.