Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

应用闪退 #96

Open
Crush-star opened this issue Dec 27, 2023 · 6 comments
Open

应用闪退 #96

Crush-star opened this issue Dec 27, 2023 · 6 comments

Comments

@Crush-star
Copy link

我用overlay展示了这个webview,第一个打开没问题,关闭后第二次打开应用闪退
调试模式下报错为断开设备连接,代码会debug到
WebviewHandler::WebviewHandler() {
DCHECK(!g_instance);
g_instance = this;
}
FATAL:webview_handler.cc(35)] Check failed: !g_instance.
帮看看,我的老哥

@Crush-star
Copy link
Author

是macos下的

@SinyimZhi
Copy link
Collaborator

因为现在这个插件还不支持多实例,你在使用overlay的时候第一次关闭的时候是销毁了webviewhandler,但是Webviewhandler本身是单例的。所以这里判空会报错,如果你想支持多实例使用的话,目前这个插件还有一段路要走,我个人的fork上有个试验性的分支,但是依然面临着很多问题,尤其是面对多窗口时。

@SinyimZhi
Copy link
Collaborator

SinyimZhi commented Dec 30, 2023

尤其是mac上面问题更多,实在是之前没有macos的技术栈,一直做的很慢 /笑哭

@alldev
Copy link

alldev commented Jan 19, 2024

Hey, @SinyimZhi, I also faced that "!g_instance" problem and probably found the solution to solve it. In our case it's not about WebView multi instance, but about same instance reinitialization. We have separate screen deep inside our application which contains WebView, the business logic is to open/close it time to time. Also it seems similar problem was already mentioned in prevoius issue which was closed as not reproducible.

I think I figured out the solution. Please chech the webview_plugin.cc file. In Dec 26 2023 commit this file was changed, but not drastically. However, these changes cause error.

I am on the recent (i.e. Jan 15 2024) commit and changed few things.

This part of handler & app initialization:

CefRefPtr<WebviewHandler> handler;
CefRefPtr<WebviewApp> app;

Was changed by me to this one:

CefRefPtr<WebviewHandler> handler(new WebviewHandler());
CefRefPtr<WebviewApp> app(new WebviewApp(handler));

And this part of CEF initialization:

void initCEFProcesses(CefMainArgs args){
	mainArgs = args;
	initCEFProcesses();
}

void initCEFProcesses(){
#ifdef OS_MAC
	CefScopedLibraryLoader loader;
	if(!loader.LoadInMain()) {
		printf("load cef err");
	}
#endif
	handler = new WebviewHandler();
	app = new WebviewApp(handler);
	CefExecuteProcess(mainArgs, app, nullptr);
}

To this one:

void initCEFProcesses(CefMainArgs args){
	mainArgs = args;
	CefExecuteProcess(mainArgs, app, nullptr);
 }

void initCEFProcesses(){
#ifdef OS_MAC
	CefScopedLibraryLoader loader;
	if(!loader.LoadInMain()) {
		printf("load cef err");
	}
#endif
	CefExecuteProcess(mainArgs, app, nullptr);
}

Now everything seems working fine and I do not face any issue.

Hope this stuff can be helpful to be implemented in update and/or will be useful for further understanding.

@SinyimZhi
Copy link
Collaborator

@alldev In fact, the
CefRefPtr<WebviewHandler> handler(new WebviewHandler()); CefRefPtr<WebviewApp> app(new WebviewApp(handler));
is not quite correct because variables are initialized once on the main thread during program execution, but when initCEFProcesses are executed, they may be initialized again because initCEFProcesses may not be executed on the main thread under different operating systems.That's why i changed the code to initialized WebviewHandler、WebviewApp when initCEFProcesses is called(In fact, it is also to prepare for multiple instantiation).
However, this brings another issue, when you dispose WebViewController at dart side. CefShutdown() was called.Due to the intelligent pointer,the singleton WebviewHandler was released. And when you guys called WebViewController::initialize() again, it will try to get WebviewHandler and will not pass null checker. That's why "!g_instance" assert is Thrown out.
Above all, there is currently no good way to balance the contradiction between multiple component page instances you want and the existing single instance mode of plugins support. What can i do is try to build correct multi instance mode as fast as i can.

@SinyimZhi
Copy link
Collaborator

Hi, every one. I've merged multi instance and multi window support branch to main. There is a lot of problems might have been resloved. Could you guys help us to verify what we did success and what new problem brought in? @alldev @Crush-star @

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants