My code compiles but crashes.

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.

My code compiles but crashes.

Postby applegrew » Tue Apr 15, 2014 2:30 am

I am a complete noob in CEF. I am trying to create an app which tries to take snapshot of a web page. For this my plan is to create an off-screen rendering app and save the image pixels as an image file. My code is a command-line app so I am placing the Framework and cef dll libraries in the executable's directory and that seems to be working.

Anyway, so my code compiles but terminates on running, with error:-

Code: Select all
0415/122715:FATAL:browser_host_impl.cc(279)] Check failed: false. context not valid
0   Chromium Embedded Framework         0x00000001004519cf base::debug::StackTrace::StackTrace() + 47
1   Chromium Embedded Framework         0x0000000100451a23 base::debug::StackTrace::StackTrace() + 35
2   Chromium Embedded Framework         0x00000001004c5f96 logging::LogMessage::~LogMessage() + 70
3   Chromium Embedded Framework         0x00000001004c4d93 logging::LogMessage::~LogMessage() + 35
4   Chromium Embedded Framework         0x00000001001fe1bf CefBrowserHost::CreateBrowser(CefWindowInfo const&, CefRefPtr<CefClient>, CefStringBase<CefStringTraitsUTF16> const&, CefStructBase<CefBrowserSettingsTraits> const&, CefRefPtr<CefRequestContext>) + 239
5   Chromium Embedded Framework         0x000000010015a4d8 cef_browser_host_create_browser + 632
6   CefWebShot                          0x000000010000da15 CefBrowserHost::CreateBrowser(CefWindowInfo const&, CefRefPtr<CefClient>, CefStringBase<CefStringTraitsUTF16> const&, CefStructBase<CefBrowserSettingsTraits> const&, CefRefPtr<CefRequestContext>) + 277
7   CefWebShot                          0x0000000100003039 main + 313
8   CefWebShot                          0x00000001000009b4 start + 52
9   ???                                 0x0000000000000001 0x0 + 1

Program ended with exit code: 9


Below is the full code. I have pasted codes from all the files together below.

Code: Select all
class WebShotRenderHandler : public CefRenderHandler {
public:
    bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect) override;
    void OnPaint(CefRefPtr<CefBrowser> browser,
                PaintElementType type,
                const RectList& dirtyRects,
                const void* buffer,
                int width, int height) override;
   
IMPLEMENT_REFCOUNTING(WebShotRenderHandler)
};
bool WebShotRenderHandler::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect) {
    rect.x = rect.y = 0;
    rect.width = 800;
    rect.height = 600;
    return true;
}

void WebShotRenderHandler::OnPaint(CefRefPtr<CefBrowser> browser,
             PaintElementType type,
             const RectList& dirtyRects,
             const void* buffer,
             int width, int height) {
   
    // TODO save content of buffer as PNG
   
}


class WebShotClient : public CefClient {
public:
    CefRefPtr<CefRenderHandler> GetRenderHandler() override;
   
IMPLEMENT_REFCOUNTING(WebShotClient)
};
CefRefPtr<CefRenderHandler> WebShotClient::GetRenderHandler() {
    return new WebShotRenderHandler();
}

int main(int argc, const char * argv[])
{
    CefWindowInfo windowInfo;
    CefBrowserSettings browserSettings;
    CefRefPtr<CefClient> client = new WebShotClient();
   
    std::string url = "http://www.google.com";
    CefString cef_url(url);
   
    windowInfo.SetAsWindowless(NULL, false);
   
    CefBrowserHost::CreateBrowser(windowInfo, client.get(), url, browserSettings, NULL);

    return 0;
}
applegrew
Newbie
 
Posts: 7
Joined: Fri Mar 04, 2011 1:03 pm

Re: My code compiles but crashes.

Postby magreenblatt » Tue Apr 15, 2014 10:46 am

You need to call CefExecuteProcess, CefInitialize, etc. See https://code.google.com/p/chromiumembed ... i/Tutorial.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 48 guests