Call of cef functions shreds variables

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.

Call of cef functions shreds variables

Postby Albus » Tue Apr 03, 2018 8:40 am

Hi, I have a class that I use as a callback handler for extensions (cef_register_extension). In my handler I have the following structure: The render process sends a message to the browser process. This then executes the code and sends a message back to the render process. And if a function was passed as the last additional parameter when the function was called in JavaScript, it is called with the return value by the browser process as a callback function.
Here's my problem: Everything works fine the first time you call the native function. However, when I call the function a second time, the global variable in which I save the instance of my handler only contains scrap. To be precise, the variable is shredded after the first time a cef function is called in the browser process after receiving the Process Message Received Event.

I hope my explanation is understandable.
Albus
 

Re: Call of cef functions shreds variables

Postby ndesktop » Tue Apr 03, 2018 9:42 am

Without some code accompanying the problem, for me (at least) is quite hard to understand what happens.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: Call of cef functions shreds variables

Postby Albus » Tue Apr 03, 2018 10:35 am

My code is very complex (and it's Delphi code) so it wouldn't help anyone if i posted my code here. And I'm not even allowed to post my complete code here. But I try to explain it a bit more detailed with the C function names.

1. At startup I register an extension with cef_register_extension with "Instance" as handler
2. In javaScript I call a function
3. the central Execute function of my handler is called
4. I temporarily save the callback function (the last parameter of the nativ function)
5. I send a IPC message with target PID_BROWSER to the browser processs with send_process_message
6. The browser process receives this message in CefClient::OnProcessMessageReceived()
7. I call some functions of my own code and get a return value
8. I send a IPC message back to the renderer process (PID_RENDERER) with send_process_message
9. The renderer process recieves the message in CefRenderProcessHandler::OnProcessMessageReceived()
10. I call the temporarily stored callback function

This is my process. The first time it works great. But the second time not. When i do this the second time, i get the problem between step 6 and step 7. At this place I make some checks and logging. But as soon as i call the first cef api function inside CefClient::OnProcessMessageReceived() my "Instance" handler (of step 1) is shredded. By this I mean that the memory addressed by this variable suddenly contains something else.
I'm using "Instance" also to store some data and provide the ProcessMessageReceived function.
When you need more information, I maybe can provide some code of a specific step (but remind that I use cef behind a Delphi implementation (CEF4Delphi))
Albus
 

Re: Call of cef functions shreds variables

Postby Albus » Wed Apr 04, 2018 1:32 am

I figured out that this problem occures because I use my "Instance" as handler in cef_v8value_create_function. In now created a new class with just the Execute function (which just calls the Execute function of my "Instance") and create a new instance of this new class for every call of cef_v8value_create_function. Now everything works fine. Except for the constantly increasing RAM consumption.
Albus
 

Re: Call of cef functions shreds variables

Postby magreenblatt » Wed Apr 04, 2018 12:01 pm

Sounds like you (or the Delphi wrapper) is doing something wrong with ref-counting. See https://bitbucket.org/chromiumembedded/ ... TheCAPI.md
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot], linuxcef07, Majestic-12 [Bot] and 97 guests