invalid param passed to c runtime

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

invalid param passed to c runtime

Postby nickak2003 » Sat Jan 18, 2020 11:45 am

So I just went through the latest demo code and tried to setup a simple OSR app. When i go to close the app, I've been having problems, and am unsure what they are. When I call TryCloseBrowser, I get an, "invalid param passed to c runtime", and then it occurs a couple more times after that. Note that my program doesn't crash or anything like that, it doesn't always write these messages, and seems to be working OK. I am just concerned about these messages. Here is the code I have figured so far, if you could review and help please!
Code: Select all
class CefAppOther : public CefApp {

    IMPLEMENT_REFCOUNTING(CefAppOther);
    DISALLOW_COPY_AND_ASSIGN(CefAppOther);

public:
    CefAppOther() = default;
    virtual ~CefAppOther() = default;
};

class CefAppRenderer : public CefApp, public CefRenderProcessHandler {

    IMPLEMENT_REFCOUNTING(CefAppRenderer);
    DISALLOW_COPY_AND_ASSIGN(CefAppRenderer);

    CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() { return this; }

public:

    CefAppRenderer() = default;
    virtual ~CefAppRenderer() = default;
};

class SimpleHandler : public CefClient,
    public CefDisplayHandler,
    public CefLifeSpanHandler,
    public CefLoadHandler,
    public CefRenderHandler {

    // Include the default reference counting implementation.
    IMPLEMENT_REFCOUNTING(SimpleHandler);

    CefRefPtr<CefBrowser> mBrowser;

    ManualTexture* mTex{ nullptr };

public:
    SimpleHandler() =default;

    virtual ~SimpleHandler() = default;

    void setTexture(ManualTexture& tex) {
        mTex = &tex;
        mBrowser->GetHost()->WasResized();
    }

    void GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) override {

        if (!mTex)
            rect = CefRect(0, 0, 1, 1);
        else
           rect = CefRect(0, 0, mTex->getImage().getWidth(), mTex->getImage().getHeight());

    }
    void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList& dirtyRects, const void* buffer, int width, int height) override {
        if (!mTex) return;
        mTex->copy(static_cast< const Ogre::uint8*>(buffer) );
        mTex->update();
    }

    CefRefPtr<CefRenderHandler> GetRenderHandler() override { return this; }
    CefRefPtr<CefDisplayHandler> GetDisplayHandler() override {return this;}
    CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override { return this;}
    CefRefPtr<CefLoadHandler> GetLoadHandler() override { return this; }

    void OnAfterCreated(CefRefPtr<CefBrowser> browser) override { mBrowser = browser; }
    bool DoClose(CefRefPtr<CefBrowser> browser) override {return false;}
    void OnBeforeClose(CefRefPtr<CefBrowser> browser) override {}

    void CloseAllBrowsers(bool force_close) {

        mBrowser->GetHost()->TryCloseBrowser();
       
        while (!mBrowser->HasOneRef()) {
            CefDoMessageLoopWork();
        }

        mBrowser = NULL;
    }
};

class CefAppBrowser : public CefApp, public CefBrowserProcessHandler {

    IMPLEMENT_REFCOUNTING(CefAppBrowser);
    DISALLOW_COPY_AND_ASSIGN(CefAppBrowser);

    CefRefPtr<SimpleHandler> handler;

public:
    CefAppBrowser() = default;
    virtual ~CefAppBrowser() = default;

    CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() override { return this; }

    void setTexture(ManualTexture& tex) {
        handler->setTexture(tex);
    }

    void OnContextInitialized() override { };

    void destroyBrowser() {
        handler->CloseAllBrowsers(true);
        handler = NULL;
       
        CefClearSchemeHandlerFactories();
    }

    void createBrowser(std::size_t windowHandle){

        handler = new SimpleHandler();

        std::string url = "www.google.com";

        CefWindowInfo windowInfo;
        windowInfo.SetAsWindowless((HWND)windowHandle);
        windowInfo.windowless_rendering_enabled = true;

        CefBrowserSettings browserSettings;
        browserSettings.background_color = CefColorSetARGB(0, 0, 0, 255);   //make transparent
        browserSettings.windowless_frame_rate = 30;
       
        CefBrowserHost::CreateBrowser(windowInfo, handler.get(), url, browserSettings,
            NULL, NULL);

        CefDoMessageLoopWork();
    }
};


class CefProcess {

    enum class ProcessType {
        BrowserProcess,
        RendererProcess,
        ZygoteProcess,
        OtherProcess,
    };

    ProcessType mProcessType;

    CefProcess::ProcessType GetProcessType(CefRefPtr<CefCommandLine> commandLine) {

        const std::string processTypeID{ "type" };
        const std::string rendererProcessID{ "renderer" };

        // The command-line flag won't be specified for the browser process.
        if (!commandLine->HasSwitch(processTypeID.c_str()))
            return ProcessType::BrowserProcess;

        const std::string& process_type = commandLine->GetSwitchValue(processTypeID.c_str());
        if (process_type == rendererProcessID)
            return ProcessType::RendererProcess;

        return ProcessType::OtherProcess;
    }
    void determineProcessType() {

        CefRefPtr<CefCommandLine> commandLine;
        commandLine = CefCommandLine::CreateCommandLine();
        commandLine->InitFromString(::GetCommandLineW());

        mProcessType = GetProcessType(commandLine);

        switch (mProcessType) {

        case ProcessType::BrowserProcess:
            mApp = new CefAppBrowser();
            break;

        case ProcessType::RendererProcess:
        case ProcessType::ZygoteProcess:
            mApp = new CefAppRenderer();
            break;

        case ProcessType::OtherProcess:
            mApp = new CefAppOther();
            break;

        default:
            EXCEPT << "CefProcess::determineProcessType; invalid type!";
        }
    }

    CefRefPtr< CefApp> mApp;

public:
    ~CefProcess() = default;

    void setManualTexture(ManualTexture& tex) {
        CefAppBrowser* browser = dynamic_cast<CefAppBrowser*>(mApp.get());

        browser->setTexture(tex);
    }

    void createBrowser(std::size_t windowHandle) {
        CefAppBrowser* browser = dynamic_cast<CefAppBrowser*>(mApp.get());
       
        browser->createBrowser(windowHandle);
    }
    void destroyBrowser() {
        CefAppBrowser* browser = dynamic_cast<CefAppBrowser*>(mApp.get());
        browser->destroyBrowser();
    }

    void navigate() {
        CefAppBrowser* browser = dynamic_cast<CefAppBrowser*>(mApp.get());
        browser->navigate();
    }

    void branchProcess() {
       
        CefMainArgs main_args(::GetModuleHandle(NULL));

        determineProcessType();

        void* sandbox_info = NULL;

        int exit_code = CefExecuteProcess(main_args, mApp, sandbox_info);
        if (exit_code >= 0) {
            // The sub-process has completed so exit.
            mApp = NULL;
            exit(exit_code);
        }
           
        // Specify CEF global settings here.
        CefSettings settings;
        settings.windowless_rendering_enabled = true;
        settings.no_sandbox = true;

        std::filesystem::path path = std::filesystem::canonical("..\\resources\\cefcache");
        CefString(&settings.cache_path).FromWString( path.generic_wstring() );

        CefInitialize(main_args, settings, mApp, sandbox_info);
    }

    void doEvents() {
        CefDoMessageLoopWork();
    }

    void shutdown() {
        CefShutdown();
    }
};

the program is as follows:
Code: Select all
      CefProcess cef;
      cef.branchProcess();

      cef.createBrowser(hwnd);
      cef.setManualTexture(tex);

      while (!windowHandler.getQuit()) {

         std::this_thread::sleep_for(std::chrono::milliseconds(150));

         cef.doEvents();
         draw(); // update screen
         poll(); // window events
      }

      cef.destroyBrowser();

      cef.shutdown();
nickak2003
Techie
 
Posts: 43
Joined: Fri Apr 10, 2015 6:53 pm

Re: invalid param passed to c runtime

Postby Czarek » Sat Jan 18, 2020 2:50 pm

Can you paste complete logs from debug.log file?

You should debug app with GDB.

Get rid of this code, it probably doesn't work or may cause inifinite loop:
Code: Select all
while (!mBrowser->HasOneRef()) {
            CefDoMessageLoopWork();
        }
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: invalid param passed to c runtime

Postby nickak2003 » Sat Jan 18, 2020 4:45 pm

the complete debug.log:
Code: Select all
[0118/163158.340:INFO:content_main_runner_impl.cc(976)] Chrome is running in full browser mode.

i also get the following written to the debug output:
[0118/163548.722:INFO:CONSOLE(0)] "Autofocus processing was blocked because a document already has a focused element.", source: https://www.google.com/ (0)

if I remove the wait for one ref code, I end up getting a dangling cef reference on cef shutdown.

If I go about it the way that is in the demo, like the following code, I also get a dangling reference.

Code: Select all
    void OnBeforeClose(CefRefPtr<CefBrowser> browser) override { mBrowser = NULL; }
   void CloseAllBrowsers(bool force_close) {

        mBrowser->GetHost()->CloseBrowser(true);
    }


Also, I just noticed this debug output I sometimes get:
Exception thrown at 0x00007FFC92539159 (KernelBase.dll) in scratch.exe: 0x0000071A: The remote procedure call was canceled, or if a call time-out was specified, the call timed out.
[0118/163951.879:FATAL:plugin_registry.mojom.cc(264)] Check failed: !connected. PluginRegistry::GetPluginsCallback was destroyed without first either being run or its corresponding binding being closed. It is an error to drop response callbacks which still correspond to an open interface pipe.

I think this one must have to do with the other chrome processes being interrupted?

keep in mind the OP code I posted, does not crash or seem to behave incorrectly. I just sometimes get some "invalid parameter passed to c runtime", and I've never really seen this before and it has me wondering what it's about. It is definitely the CEF code, too. I can comment out unrelated code and still get it, that includes actual OSR, the window events polling and rendering.
nickak2003
Techie
 
Posts: 43
Joined: Fri Apr 10, 2015 6:53 pm

Re: invalid param passed to c runtime

Postby Czarek » Sat Jan 18, 2020 6:32 pm

Do the final message loop work after browser closed like it's done in cefclient: https://github.com/chromiumembedded/cef ... win.cc#L91

You don't free CefApp/mApp reference before shutdown. Free all CEF references.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: invalid param passed to c runtime

Postby nickak2003 » Sat Jan 18, 2020 8:55 pm

I have traced down the invalid c param and maybe we can figure it out. Check out the following:
https://ibb.co/4szd9HD
nickak2003
Techie
 
Posts: 43
Joined: Fri Apr 10, 2015 6:53 pm

Re: invalid param passed to c runtime

Postby nickak2003 » Sat Jan 18, 2020 8:57 pm

I tried adding the sleep loop at shutdown, I still get: Exception thrown at 0x00007FFC92539159 (KernelBase.dll) in scratch.exe: 0x0000071A: The remote procedure call was canceled, or if a call time-out was specified, the call timed out.
nickak2003
Techie
 
Posts: 43
Joined: Fri Apr 10, 2015 6:53 pm

Re: invalid param passed to c runtime

Postby Czarek » Sun Jan 19, 2020 3:01 am

That error doesn't seem CEF related. Check your app for memory issues. Make sure you link correct binaries/libraries.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: invalid param passed to c runtime

Postby nickak2003 » Sun Jan 19, 2020 10:55 am

OK, I think the invalid c parameter was due to an outdated manifest. I think that's fixed now>


Nope, looks like it's still there, and it's done on cefclient and cefsimple, too.
Last edited by nickak2003 on Sun Jan 19, 2020 11:39 am, edited 1 time in total.
nickak2003
Techie
 
Posts: 43
Joined: Fri Apr 10, 2015 6:53 pm

Re: invalid param passed to c runtime

Postby nickak2003 » Sun Jan 19, 2020 11:33 am

I guess there's nothing that can be done about the message, rpc cancelled, at cefshutdown, it seems to print on cef client as well. Ok thanks for your help, I think my issues are resolved!
nickak2003
Techie
 
Posts: 43
Joined: Fri Apr 10, 2015 6:53 pm

Re: invalid param passed to c runtime

Postby nickak2003 » Sun Jan 19, 2020 11:42 am

https://ibb.co/4szd9HD
from what I can gather from this image, libcef.dll, sometimes or always passes a poor string from readIpHelper, to the windows GetAdapterAddress function, which errors in wsccpy_s, a w-string copy function. I am using visual studio 2019, IDK if that is the issue, or what it could be if it's on my side.


OK it looks like it's a microsoft issue:
https://developercommunity.visualstudio ... -to-c.html
nickak2003
Techie
 
Posts: 43
Joined: Fri Apr 10, 2015 6:53 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 92 guests