Tracktion / choc

A collection of header only classes, permissively licensed, to provide basic useful tasks with the bare-minimum of dependencies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

webview - crash when viewing local server content?

rorywalsh opened this issue · comments

I'm trying to display some content running on a local server (via python http>server, or VSCode's liver-server extensions). The html couldn't be simpler:

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js"></script>
    <meta charset="utf-8" />
</head>
<body>
    <main>
    </main>
    <script>
       function setup(){
        print("test")
       }
    </script>
</body>
</html>

It runs fine in all of the browsers I've installed, but it causes an exception with choc_WebView.h here:

image

I'm just using the demo code with navigate() instead of setHTML() Any ideas? I'm well out of my depth here. Am I correct in assuming that if it runs in Edge it should run fine?

[edit] It seems that it might be something unique to p5js that causes this problem. If I try with another js library, it works fine. I'd still love to know if it could be resolved...

Hmm - we just had a go at recreating this and couldn't get it to fail.

a) Does the unmodified choc test app also crash?
b) Does it crash if you navigate to a normal site, e.g. google.com?
c) Exactly what have you modified in your code? It kind of looks like a dangling pointer error, so perhaps you've accidentally deleted the webview somehow...?

a) Does the unmodified choc test app also crash?

Not, it works fine.

b) Does it crash if you navigate to a normal site, e.g. google.com?

No, all good there:

c) Exactly what have you modified in your code? It kind of looks like a dangling pointer error, so perhaps you've accidentally deleted the webview somehow...?

static int openDemoWebViewWindow()
{
    choc::ui::setWindowsDPIAwareness(); // For Windows, we need to tell the OS we're high-DPI-aware

    choc::ui::DesktopWindow window ({ 100, 100, 800, 600 });

    window.setWindowTitle ("Hello");
    window.setResizable (true);
    window.setMinimumSize (300, 300);
    window.setMaximumSize (1500, 1200);
    window.windowClosed = [] { choc::messageloop::stop(); };

    choc::ui::WebView webview;

    window.setContent (webview.getViewHandle());

    // webview.bind ("eventCallbackFn", [] (const choc::value::ValueView& args) -> choc::value::Value
    // {
    //     auto message = "eventCallbackFn() called with args: " + choc::json::toString (args);

    //     // This just shows how to invoke an async callback
    //     choc::messageloop::postMessage ([message]
    //     {
    //         std::cout << "WebView callback message: " << message << std::endl;
    //     });

    //     return choc::value::createString (message);
    // });

    // webview.bind ("loadCHOCWebsite", [&webview] (const choc::value::ValueView&) -> choc::value::Value
    // {
    //     webview.navigate ("https://github.com/Tracktion/choc");
    //     return {};
    // });

webview.navigate("http://127.0.0.1:56278/index.html");
    // webview.setHTML (R"xxx(
    //   <!DOCTYPE html> <html>
    //     <head> <title>Page Title</title> </head>
    //     <script>
    //       var eventCounter = 0;

    //       // invokes a call to eventCallbackFn() and displays the return value
    //       function sendEvent()
    //       {
    //         // When you invoke a function, it returns a Promise object
    //         eventCallbackFn({ counter: ++eventCounter }, "Hello World")
    //           .then ((result) => { document.getElementById ("eventResultDisplay").innerText = result; });
    //       }
    //     </script>

    //     <body>
    //       <h1>CHOC WebView Demo</h1>
    //       <p>This is a demo of a choc::webview::WebView window</p>
    //       <p><button onclick="sendEvent()">Click to invoke an event callback</button></p>
    //       <p><button onclick="loadCHOCWebsite()">Click to visit the CHOC github repo</button></p>
    //       <p id="eventResultDisplay"></p>
    //     </body>
    //   </html>
    // )xxx");

    window.toFront();
    choc::messageloop::run();
    return 0;
}

I'm trying various other js libraries and they seem to work fine. It's very odd..

Pretty sure we've fixed this, so going to close the issue - thanks for reporting, and let us know if you spot any other oddities!

Nice one. 👍