diff --git a/lib.go b/lib.go index 0f57850..f03166d 100644 --- a/lib.go +++ b/lib.go @@ -228,6 +228,10 @@ func _startCwtch(appDir string, torPath string) { LaunchServers() // Send global settings to the UI... + if application == nil { + log.Errorf("startCwtch: primary application object has gone away. assuming application is closing.") + return + } application.GetPrimaryBus().Publish(event.NewEvent(utils.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)})) log.Infof("libcwtch-go application launched") application.GetPrimaryBus().Publish(event.NewEvent(utils.CwtchStarted, map[event.Field]string{})) diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 9593cf3..e69ac2d 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -88,6 +88,10 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { case event.NewPeer: onion := e.Data[event.Identity] profile := eh.app.GetPeer(e.Data[event.Identity]) + if profile == nil { + log.Errorf("NewPeer: skipping profile initialization. this should only happen when the app is rapidly opened+closed (eg during testing)") + break + } log.Debug("New Peer Event: %v", e) if e.Data["Reload"] != event.True { @@ -426,6 +430,10 @@ func unwrap(original *EventProfileEnvelope) *event.Event { func (eh *EventHandler) startHandlingPeer(onion string) { eventBus := eh.app.GetEventBus(onion) + // if eventBus == nil { + // log.Errorf("startHandlingPeer: eventBus was nil; skipping contact initialization. this should only happen when the app is rapidly opened+closed (eg during testing)") + // return + // } q := event.NewQueue() // eventBus.Subscribe(event.NetworkStatus, q)