leanflutter / window_manager

This plugin allows Flutter desktop apps to resizing and repositioning the window.
https://pub.dev/packages/window_manager
MIT License
701 stars 193 forks source link

Resolve crash after deconstruction #423

Closed ljnhst closed 4 months ago

ljnhst commented 10 months ago

在WindowManagerPlugin析构时应将channel置为空指针。在析构之后还传递窗口消息,在invokeMethod方法内会出现messenger_指针异常问题。复现方法为在退出应用前调用关闭窗口的方法,再退出应用。

下面为我解决该问题添加的指针处理:

WindowManagerPlugin::~WindowManagerPlugin() {
  registrar->UnregisterTopLevelWindowProcDelegate(window_proc_id);
  channel = nullptr;
}

void WindowManagerPlugin::_EmitEvent(std::string eventName) {
  if (channel) {
    flutter::EncodableMap args = flutter::EncodableMap();
    args[flutter::EncodableValue("eventName")] =
        flutter::EncodableValue(eventName);
    channel->InvokeMethod("onEvent",
                          std::make_unique<flutter::EncodableValue>(args));
  }
}
lijy91 commented 4 months ago

Fixed in this commit https://github.com/leanflutter/window_manager/commit/8fa23db7f4c2cf8cf3085d5fc06e4ceb7857a2f5