Question about CefStringVisitor

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.

Question about CefStringVisitor

Postby silver » Sat Jul 04, 2015 10:20 pm

My application is crashing and the scenario is like this.

I create an instance of CefStringVisitor like this, which also gets a pointer to the class object.

Code: Select all
GetMainFrame()->GetSource( new MyCefStringVisitor( this ));


The Visit function of MyCefStringVisitor uses "this" to call a function.
Now if I close the application in between, there is a crash, because the "this" object goes out of scope before MyCefStringVisitor::Visit is done.

How do I fix this ? What am I doing wrong ?

In the destructor of the "this" object I am calling CloseBrowser(true).
Is there a way to stop all CefStringVisitor activity before calling CloseBrowser ?
Last edited by silver on Mon Jul 06, 2015 10:24 pm, edited 1 time in total.
User avatar
silver
Techie
 
Posts: 48
Joined: Tue Feb 24, 2015 5:39 am

Re: Question about CefStringVisitor

Postby magreenblatt » Mon Jul 06, 2015 12:25 pm

The object type represented by |this| should be refcounted, or you should use WeakPtrFactory. See include/base/cef_ref_counted.h and include/base/cef_weak_ptr.h. Example usage exists in cefclient.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Question about CefStringVisitor

Postby silver » Mon Jul 06, 2015 11:00 pm

magreenblatt wrote:The object type represented by |this| should be refcounted, or you should use WeakPtrFactory. See include/base/cef_ref_counted.h and include/base/cef_weak_ptr.h. Example usage exists in cefclient.


"this" is an object of type wxFrame ( a window frame ) whose scope is controlled by the wxWidgets library internally.
Once I press the close button, wxWidgets will delete it.

How do I then implement ref counting ?
User avatar
silver
Techie
 
Posts: 48
Joined: Tue Feb 24, 2015 5:39 am

Re: Question about CefStringVisitor

Postby magreenblatt » Tue Jul 07, 2015 10:29 am

silver wrote:"this" is an object of type wxFrame ( a window frame ) whose scope is controlled by the wxWidgets library internally.
Once I press the close button, wxWidgets will delete it.

In this case you should use WeakPtrFactory which will invalidate the WeakPtr when the wxWidgets object is deleted. What thread does the wxWidgets object live on? Since WeakPtr is not thread safe you will need to post it and the associated data to the correct thread (the thread that the wxWidgets object lives on) before dereferencing it.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Question about CefStringVisitor

Postby silver » Wed Jul 08, 2015 3:41 am

magreenblatt wrote:In this case you should use WeakPtrFactory which will invalidate the WeakPtr when the wxWidgets object is deleted. What thread does the wxWidgets object live on? Since WeakPtr is not thread safe you will need to post it and the associated data to the correct thread (the thread that the wxWidgets object lives on) before dereferencing it.


1. The wxWidgets object are created on the one and only main thread.
2. How exactly do I use WeakPtr (need some code example).

Even if I were to wrap the wxWidget object in some kind of a smart pointer, wxWidgets will delete the object while the other thread is running some function on it.
User avatar
silver
Techie
 
Posts: 48
Joined: Tue Feb 24, 2015 5:39 am

Re: Question about CefStringVisitor

Postby magreenblatt » Wed Jul 08, 2015 10:42 am

Here is an example of using WeakPtrFactory: https://www.chromium.org/developers/des ... ncellation
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 53 guests