fetch() appears to be synchronous in CEF

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.

fetch() appears to be synchronous in CEF

Postby sshuzaFulcrum » Thu Oct 06, 2022 4:46 pm

Hello CEF Forums,

I am trying to create a lively updating <img> based on a backend that is a Resource Handler, the Resource Handler generates preview frames until the final frame is available in the form of PNGs. I can't go into the exact specifics on what the actual generator does since its under NDA.

Image

In my current Resource Handler code, there is a request that starts the background process which the response is the final image or error (this has a delay due to the generation process), and there is another request that will return the most recent preview image or error.

In my JavaScript page, the first fetch request starts the generation process, then a small delay is placed (give some time for the handler to respond), then a loop of the preview fetch request starts, the loop being able to live update the img, as every request pulls a new frame. Once the first request completes, the loop stops and the final image is displayed.

Image

Image
The blurred out part here is the loop condition variable, its named after NDA stuff, sorry about that, the function PreviewLoopPost() returns false if the final scan has already been found.

With CEFSharp.WPF, using fetch, the code works as intended and the graphics do not hang or freeze. This follows the definition of fetch() which is meant to be asynchronous, using Promises for answers as they become available.

However in CEF with C++ my first request starts and immediately hangs until the final result is available, then after the final result is complete (the generation finishes), the secondary loop starts then immediately fails because the result has already been found.


It appears that fetch() in CEF is not asynchronous as it is supposed to, I ensured that all of my processes have the Resource Handler registered with the scheme and domain associated, and that they are all running (they don't crash).


Is there a setting I have to change to make fetch asynchronous, or is there something I am missing? Due to other factors I need to use CEF and not CEFSharp.

Any help is greatly appreciated.
Last edited by sshuzaFulcrum on Thu Oct 06, 2022 4:52 pm, edited 1 time in total.
sshuzaFulcrum
Techie
 
Posts: 12
Joined: Tue Sep 27, 2022 9:31 am

Re: fetch() appears to be synchronous in CEF

Postby magreenblatt » Thu Oct 06, 2022 4:52 pm

What OS and CEF version? How do your CEFSharp.WPF and C++ implementations differ? Show your code.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: fetch() appears to be synchronous in CEF

Postby sshuzaFulcrum » Thu Oct 06, 2022 5:36 pm

magreenblatt wrote:What OS and CEF version? How do your CEFSharp.WPF and C++ implementations differ? Show your code.


Currently Windows 11, and cef_binary_105.3.39+g2ec21f9+chromium-105.0.5195.127_windows64.

Both my C# and C++ have the same JavaScript code excluding the C# one has a custom scheme rather than a scheme based on http (based on the reply I got here: https://magpcss.org/ceforum/viewtopic.php?f=6&t=19213)

In both I register my resource handler with the scheme and domain.

C#:
Image
C++:
Image

Both Resource Handlers use locking mechanisms to access a shared section of memory provided by the generator (the final result and previews are simply bitmap byte arrays that need to be converted to PNG by the Resource Handler)

Based on my unit tests of the actual functions that are being ran from the generator and Resource Handlers they do behave exactly the same, its a matter of the CEF browser.

Both print out when the Resource Handler gets a request such as this which prints the unix millisecond time, the scheme, domain, and the local path that was specified (for which function to do), if any Post objects are present the count is printed:

Image

In my logs of my C++ code, I only get the Start command like that, and I don't receive anything else until the generator completes and returns a result. After this happens, I get one preview request which immediately returns false no longer continuing the loop.

Also while it is generating attempting to interact with the CEF window is not possible, the entire window freezes including minimizing or maximizing, interacting with other client side only buttons, or even closing the window is not possible during this time.

(I will provide more screenshots and videos tomorrow to show what i mean).
sshuzaFulcrum
Techie
 
Posts: 12
Joined: Tue Sep 27, 2022 9:31 am

Re: fetch() appears to be synchronous in CEF

Postby magreenblatt » Thu Oct 06, 2022 5:51 pm

From your description it sounds like you’re blocking one or more of the main CEF threads. Don’t do that. More specific guidance is not possible unless you show your code as requested.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 37 guests