CreateBrowser spawns a copy of my main window

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.

CreateBrowser spawns a copy of my main window

Postby Muanh » Fri Apr 19, 2013 10:16 am

Hi all, I'm new to CEF and trying to get starting with it.

I'm trying to to get it integrated into a simple opengl framework the problem is whenever I call CreateBrowser or CreateBrowserSync I end up with a copy of my main window.
The second window is spawned over the window holding my CEF browser is white and not responding.

Am I doing something wrong with the settings? Hopefully somebody has an answer.
Muanh
Newbie
 
Posts: 2
Joined: Fri Apr 19, 2013 9:42 am

Re: CreateBrowser spawns a copy of my main window

Postby magreenblatt » Fri Apr 19, 2013 3:40 pm

CEF3 uses multiple processes. You are probably not calling CefExecuteProcess(). See the cefclient sample application and viewtopic.php?f=6&t=10567.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: CreateBrowser spawns a copy of my main window

Postby daktor » Thu May 30, 2013 2:54 pm

I am having the same issue but am calling CefExecuteProcesses. Maybe I'm not calling it correctly?

I got the desired results in a stand-alone project but when I use the same code in my main project (game engine), it opens the game engine again in a new window and the CEF popup remains white.

Code is here: viewtopic.php?f=6&t=10657&p=16948#p16948
daktor
Techie
 
Posts: 14
Joined: Wed May 22, 2013 3:39 pm

Re: CreateBrowser spawns a copy of my main window

Postby magreenblatt » Fri May 31, 2013 1:34 pm

See dgooden's answer to your other post. Please don't post about the same question in multiple threads (stick with the original thread).
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: CreateBrowser spawns a copy of my main window

Postby daktor » Fri May 31, 2013 1:40 pm

I updated my code based on dgooden's response. CefExecuteProcess is called once with a return value of -1. I still see the same behavior I mentioned (game engine window launches).

Sorry for the thread confusion. I wanted to help yerbamate with code but I developed that code to help me debug the issue in this thread.
daktor
Techie
 
Posts: 14
Joined: Wed May 22, 2013 3:39 pm

Re: CreateBrowser spawns a copy of my main window

Postby magreenblatt » Fri May 31, 2013 1:47 pm

You might have an easier time using a separate executable for the sub-processes. See for example viewtopic.php?f=6&t=737#p2972.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: CreateBrowser spawns a copy of my main window

Postby daktor » Mon Jun 03, 2013 12:05 am

It took me a while to piece through what you meant but I finally got it!

If you're a total CEF-noob like me, here's some additional info:

Sub-processes refer to processes other than the browser process. If you extend CefApp and override OnBeforeCommandLineProcessing, the process_type is helpful. No value means the browser process.

My problem was CefExecuteProcess was opening my main application because it used the program part of the command-line by default for launching sub-processes. This caused failures when it tried to launch the rendering process, resulting in a white screen (no rendering). As magreenblatt described, the work-around for this is to specify a different executable to use when launching those subprocesses. The links in the connected thread are no longer valid, but if you do some sleuthing you can find cefclient_helper_mac.cc. Here's code to create this helper executable:

Code: Select all
#include "include/cef_app.h"

int main(int argc, char* argv[]) {
  CefMainArgs main_args(argc, argv);

  // Execute the secondary process.
  return CefExecuteProcess(main_args, NULL);
}


Once you've created the helper executable, set CefSettings::browser_subprocess_path to point to your helper executable before calling CefInitialize(...).

Next step is offscreen rendering, but for tonight... success.
daktor
Techie
 
Posts: 14
Joined: Wed May 22, 2013 3:39 pm

Re: CreateBrowser spawns a copy of my main window

Postby daktor » Mon Jun 03, 2013 9:45 pm

Another solution is to add code to the entry point of your application (eg WinMain) to handle when CEF is creating a sub-process. Searching the command line for "--type=" works but there may be better ways to detect that CEF should handle things. Once you know it's CEF, return CefExecuteProcess(...) and exit instead of proceeding into your application.

This fixes the problem without adding an additional executable to your project.
daktor
Techie
 
Posts: 14
Joined: Wed May 22, 2013 3:39 pm

Re: CreateBrowser spawns a copy of my main window

Postby itsthetaste » Wed Jun 12, 2013 9:47 am

daktor wrote:It took me a while to piece through what you meant but I finally got it!

If you're a total CEF-noob like me, here's some additional info:

Sub-processes refer to processes other than the browser process. If you extend CefApp and override OnBeforeCommandLineProcessing, the process_type is helpful. No value means the browser process.

My problem was CefExecuteProcess was opening my main application because it used the program part of the command-line by default for launching sub-processes. This caused failures when it tried to launch the rendering process, resulting in a white screen (no rendering). As magreenblatt described, the work-around for this is to specify a different executable to use when launching those subprocesses. The links in the connected thread are no longer valid, but if you do some sleuthing you can find cefclient_helper_mac.cc. Here's code to create this helper executable:

Code: Select all
#include "include/cef_app.h"

int main(int argc, char* argv[]) {
  CefMainArgs main_args(argc, argv);

  // Execute the secondary process.
  return CefExecuteProcess(main_args, NULL);
}


Once you've created the helper executable, set CefSettings::browser_subprocess_path to point to your helper executable before calling CefInitialize(...).

Next step is offscreen rendering, but for tonight... success.


I'm looking at making a separate executable for my needs right now and came across this post and am confused. How can I call CefMainArgs main_args(argc, argv) when main_args only takes one parameter of type HINSTANCE. I am a noob so am probably missing something.
itsthetaste
Techie
 
Posts: 35
Joined: Mon Jun 10, 2013 8:03 pm

Re: CreateBrowser spawns a copy of my main window

Postby daktor » Wed Jun 12, 2013 11:06 am

I copied and pasted that when I shouldn't have :)

Cef does not care about argc/argv in Windows, instead looking at the commandline (use GetCommandLine() to check) passed when the process is created. So you can modify code to be:

Code: Select all
#include "include/cef_app.h"

int main(int argc, char* argv[])
{
  CefMainArgs main_args;

  // Execute the secondary process.
  return CefExecuteProcess(main_args, NULL);
}
daktor
Techie
 
Posts: 14
Joined: Wed May 22, 2013 3:39 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 54 guests