Using global object in JS extension

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.

Using global object in JS extension

Postby rozenman » Wed Apr 15, 2015 10:06 am

Hey guys,
I have a global object, of some custom class, that I have created. It is initialized in main, before CEF.
I use this global in my code - everything is working good. But, when I try using this global in a JS extension - it crushes (the pointer does not exists there).
For example:
Code: Select all
// Our global object
extern CustomClass* g_var;

CefRefPtr<CefV8Value> get_size(const CefV8ValueList& arguments) {
   return CefV8Value::CreateInt(g_var->size());
}


The program crashes here. If I use a global object, without pointers, it is creating a new object and uses the new one instead of the global one...
If I use primitive globals - everything works...
What is the problem?

Thanks!
rozenman
Techie
 
Posts: 16
Joined: Sun Mar 01, 2015 10:02 am

Re: Using global object in JS extension

Postby magreenblatt » Fri Apr 17, 2015 5:27 am

Where/how are you initializing the global? Note that CEF uses multiple processes and threads, so your global needs to be initialized in the correct process and available from the correct thread.
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: Using global object in JS extension

Postby rozenman » Sat Apr 18, 2015 3:05 am

magreenblatt wrote:Where/how are you initializing the global? Note that CEF uses multiple processes and threads, so your global needs to be initialized in the correct process and available from the correct thread.

I see. This global is initialized in the main.cpp file, before initializing CEF.
I need this global to work in custom scheme handlers and when using JS extensions. Is there any way doing so?

Thanks!
rozenman
Techie
 
Posts: 16
Joined: Sun Mar 01, 2015 10:02 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 42 guests