window_manager
window_manager copied to clipboard
Resolve crash after deconstruction
在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));
}
}