BindOnce

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.

BindOnce

Postby arczi » Tue Nov 23, 2021 7:56 am

Hi, how can I call method in TID_UI?

I'm upgrading CEF version and in old code:
CefPostTask(TID_UI, base::Bind(&setZoomLevel, browser, delta));
was working well now because Bind has been removed I tried to use BindOnce instead but something is wrong.
CefPostTask(TID_UI, base::BindOnce(&setZoomLevel, browser, delta));

That's the declaration of a zoom method

void zoomLevel(CefRefPtr<CefBrowser> browser, double *level)

How am I supposed to call this method in UI thread without declaring another class which inherit from CefTask?
arczi
Newbie
 
Posts: 5
Joined: Mon Nov 22, 2021 3:28 am

Re: BindOnce

Postby alexandermol » Tue Nov 23, 2021 10:14 am

Are you getting any compile errors?
What is zoomLevel a member of?

I suspect you need
CefPostTask(TID_UI, base::BindOnce(&setZoomLevel, this, browser, delta));
alexandermol
Techie
 
Posts: 19
Joined: Mon Nov 22, 2021 1:55 pm

Re: BindOnce

Postby magreenblatt » Tue Nov 23, 2021 10:46 am

arczi wrote:That's the declaration of a zoom method

void zoomLevel(CefRefPtr<CefBrowser> browser, double *level)

You can't use out pointers with bound methods. I suggest you change your code so that the result (level) is consumed on the UI thread.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: BindOnce

Postby alexandermol » Tue Nov 23, 2021 11:58 am

What do you mean? I am sending a void* as parameter and calling it in a bound function, it works fine?

Code: Select all
void WebSocketHandler::onConnect(seasocks::WebSocket *connection) {
....
CefPostTask(TID_UI,
                base::BindOnce(base::IgnoreResult(&BrowserApp::CreateBrowser),
                               base::Unretained(m_app), connection));
....
}
alexandermol
Techie
 
Posts: 19
Joined: Mon Nov 22, 2021 1:55 pm

Re: BindOnce

Postby magreenblatt » Tue Nov 23, 2021 12:20 pm

alexandermol wrote:What do you mean? I am sending a void* as parameter and calling it in a bound function, it works fine?

Think about the function signature that was posted:
Code: Select all
void zoomLevel(CefRefPtr<CefBrowser> browser, double *level)

What happens with |level| when zoomLevel is executed on a different thread? Is |level| likely to still reference a valid memory address at that time? Of course it might if |level| is heap allocated or if you're somehow blocking the calling thread on zoomLevel completion, but neither of those are good design approaches.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: BindOnce

Postby arczi » Fri Nov 26, 2021 2:53 am

|level| is actually heap allocated and I'm using shared_ptr so I don't worry about memory leak or dangling pointer. That was problem with implementation and now it works fine.
arczi
Newbie
 
Posts: 5
Joined: Mon Nov 22, 2021 3:28 am

Re: BindOnce

Postby tapineb371 » Thu Oct 26, 2023 12:03 am

arczi wrote:|level| is actually heap allocated and I'm using shared_ptr so I don't worry about memory leak or dangling pointer. That was problem with implementation and now it works fine.


Can you elaborate on the solution @arczi?
tapineb371
Techie
 
Posts: 13
Joined: Mon Sep 04, 2023 8:49 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 47 guests