wxWidget::wxWebView->查找wxWEBVIEW_FIND_HIGHLIGHT_RESULT段错误

wxWidget::wxWebView->Find wxWEBVIEW_FIND_HIGHLIGHT_RESULT Segmentation Fault

wxWidget::wxWebView->查找 - https://docs.wxwidgets.org/3.0/classwx_web_view.html#ad85a7aa0351b6e6a6bffd4220f9758ee

示例代码

wxWebView *webView;
webView = wxWebView::New(this, wxID_ANY);
webView->SetPage("<html><head><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no' /><meta content='en-us' http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><title>Demo App</title><style type=\"text/css\">.auto-style8 {font-family: \"Bookman Old Style\";font-weight:bold;color:#734024;}.underline{color:#ff0000;}.text {color:#230fd2;}#wrapper1 {    width: 100% ; display: table;}#wrapper {width: 100% ; display: table;}#header1 {color: #E6F0F1;    display: table;    background-color: #0000ff;width: 100% ; text-align: center;height: 50px;font-size: 105% ; font-weight: bold;}#header2 {background-color: #B98264;display: table;    width: 100% ; height: 40px;text-align: center;color: #FFFFFF;    font-size: 75% ; font-weight: bold;}.auto-style13 {text-decoration: underline;}.text2{color:#000000;text-align: justify;}</style></head> <body style=\"color:#000000;background-color:#FFFFFF\"><div id=\"header2\"><p style=\"font-size: x-medium\" class=\"auto-style13\">Demo Page<br></p></div> <p class=\"auto-style8\" style=\"width: 100%;\">To Start  - <br/><br/>STEP 1. Select data</p></body></html>","");
long lMatchCount = webView->Find("a",wxWEBVIEW_FIND_HIGHLIGHT_RESULT  );
        if(lMatchCount == wxNOT_FOUND){
            wxMessageBox("Search not found");
        }else{
            //wxMessageBox("Search found" + lMatchCount);
            wxLogMessage("Matches: %s ",std::to_string(lMatchCount));
        }

以上代码工作正常并且“a”的出现次数 returns。

当 webview->SetPage 使用大文本再次动态更新时(任何虚拟内容都可以)并且如果再次调用 find 调用它因分段错误而崩溃

如果 SetPage 在第一个实例中加载了大文本,它本身也会崩溃,因此排除了更新导致崩溃的可能性。

还尝试从本地文件加载大文件(default.html 包含上面的 html 代码 - 替换任何长字符串并且它崩溃并得到相同的结果)

wxFile fFileIn("default.html", wxFile::read); 
wxFileInputStream in(fFileIn);
webView->SetPage(in,"");
fFileIn.Close();

这里报告了类似的问题http://trac.wxwidgets.org/ticket/15207

根据对此线程的讨论 http://trac.wxwidgets.org/ticket/15207。 我们有解决这个问题的方法(仍然不知道为什么会这样,根本原因是什么)

  1. 使用 PR https://github.com/wxWidgets/wxWidgets/pull/2626 中提到的代码。

  2. 在setPage之前调用Find

    wxFile fFileIn("default.html", wxFile::read);

    wxFileInputStream in(fFileIn);

    webView->Find("");

    webView->SetPage(in,"");

    fFileIn.Close();