New CEF user with problems

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.

New CEF user with problems

Postby alexisgreene » Sun Jan 27, 2013 7:07 am

I have been working on a 3D game engine. I have decided to use CEF1 to provide an HTML based user interface. My engine is a 64-bit application. Upon start-up, I launch a 32-bit server application which is responsible for initiating, closing, and updating cef1. My engine and communicates with this local server via sockets. Everything seems to work fine, up until the point my cef1 server receives the command to initiate cef1.

Here is the code I use to start cef1:
Code: Select all
   // Create an instance of our CefClient implementation. Various methods in the
   // MyClient instance will be called to notify about and customize browser
   // behavior.
   CefRefPtr<CefClient> Client(new rdk::cef_server::CCefRenderHandler());

   // Information about the parent window, client rectangle, etc.
   CefWindowInfo WindowInfo;
   WindowInfo.SetAsOffScreen(hWndParent);

   // Browser initialization settings.
   CefBrowserSettings Settings;
   memset(&Settings, 0, sizeof(Settings));

   // Create the new browser window object asynchronously. This eventually results
   // in a call to CefLifeSpanHandler::OnAfterCreated().
   CefBrowser::CreateBrowser(WindowInfo, Client, L"http://www.google.com", Settings);


I zero out CefBrowserSettings because in the docs it says set to 0 or NULL for the default settings. The call to CefBrowser::CreateBrowser is what causes the crash.
Here is my CCefRenderHandler class definition:
Code: Select all
      class CCefRenderHandler : public CefClient, public CefRenderHandler
      {
      public:
         CCefRenderHandler(void) :
            m_iWidth(0),
            m_iHeight(0)
         { }
         ~CCefRenderHandler(void) { }

         void OnPaint(CefRefPtr<CefBrowser> Browser, PaintElementType Type,
                   const RectList& DirtyRects, const void* pBuffer) OVERRIDE;

      private:
         IMPLEMENT_REFCOUNTING(CCefClient);

         int   m_iWidth;
         int   m_iHeight;
      };   // CCefRenderHandler

OnPaint is just an empty function for the time being.

The only message I get in the debugger is: cef_server_DEBUG.exe has triggered a breakpoint. When I click Break, it takes me to line 37 of browser_ctocpp.cc which contains this code:
Code: Select all
  // Execute
  int _retval = cef_browser_create(
      &windowInfo,
      CefClientCppToC::Wrap(client),
      url.GetStruct(),
      &settings);


My code is based on the osrplugin example. Hopefully some of you can see what I am doing wrong. Thanks in advance.
alexisgreene
Newbie
 
Posts: 4
Joined: Sun Jan 27, 2013 6:47 am

Re: New CEF user with problems

Postby magreenblatt » Sun Jan 27, 2013 5:11 pm

Did you call CefInitialize?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: New CEF user with problems

Postby alexisgreene » Sun Jan 27, 2013 9:26 pm

I forgot to call CefInitialize, and then I discovered I forgot to copy the locale folder. I also discovered there is a debug.log file created. That helped me find out what I was doing wrong. I do have another question now. I cant seem to figure out how to get OnPaint to be called to handle the rendering of the off screen browser.
alexisgreene
Newbie
 
Posts: 4
Joined: Sun Jan 27, 2013 6:47 am

Re: New CEF user with problems

Postby magreenblatt » Sun Jan 27, 2013 9:59 pm

Are you calling CefRunMessageLoop or CefDoMessageLoopWork? If so, did you implement the CefClient Get*() methods?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: New CEF user with problems

Postby alexisgreene » Mon Jan 28, 2013 7:01 am

I was handling the message loop manually because I have cef "wrapped" in a background process that will never have focus and it should only react to messages that are received via sockets (which will be mouse and keystroke information that I will forward to cef using the CefBrowser::Send* functions) and not the message loop. From reading the docs, OnPaint should be called at a rate of 30 times per second (which is the default value) but it is not being called at all. After reading your last reply, I tried placing CefDoMessageLoopWork() in my message loop, but this did not fix my problem. I have added only GetRenderHandler() to CefClient.

Here is the main loop I last tried:
Code: Select all
   while(bContinue)
   {
      while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
         if(msg.message == WM_QUIT)
            bContinue = false;
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }
      if(!bContinue)
         break;
      if(!Server.Update())
         bContinue = false;
      CefDoMessageLoopWork();
   }


Server.Update() is the function that receives messages from the host 64-bit application via sockets and then translate them into the proper CefBrowser::Send* function calls.

I hope you can see what I am doing wrong here. Thank you for taking the time to help me with my problems.
alexisgreene
Newbie
 
Posts: 4
Joined: Sun Jan 27, 2013 6:47 am

Re: New CEF user with problems

Postby alexisgreene » Mon Jan 28, 2013 6:50 pm

After hours of searching through this forum, studying osrplugin.cpp, and trial and error, I have finally got it to work.

1. I changed CefSettings::multi_threaded_message_loop to true to handle my message loop problem.
2. I called CefBrowser::SetSize() after creating the browser.
alexisgreene
Newbie
 
Posts: 4
Joined: Sun Jan 27, 2013 6:47 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 183 guests