Search code examples
delphichromium-embeddeddelphi-xe4

Chromium-embedded for Delphi - TChromiumOSR.OnPaint is not fired when a modal window is shown


I'm using the Off-screen rendering component TChromiumOSR in the dcef3 package - the Delphi wrapper for Chromium-embedded library.

Situation

FormA contains a TChromiumOSR and paints the output. Modal FormB modifies the web page by executing some js code against FormA.TChromiumOSR.

Issue

The TChromiumOSR.OnPaint event (in FormA) is not triggered until FormB.ShowModal returns.

Notes

  • There is no such issue in the above described situation (under a modal form) with the standard TChromium control.

I assume the `TForm.ShowModal' method only blocks the input of the background forms, but not the painting?

Or does it caused by the internal working of cef3?

Anyway, how to solve it? Thanks.

dcef3 master branch is here


Solution

  • Ok, I found the source of the problem - it's not a bug in cef3 or dcef3 but was caused by my improper use of Delphi Event Bus, and the following are the steps to reproduce the issue:

    1. In one the 'delphi event bus' handler, the program shows a modal form at this point the execution of the main thread is blocked.
    2. On top of the modal form, the user doing certain actions will start a background thread, which in turn will send a message to the main thread, which in turn will calls the 'delphi event bus' to post another new event, which in turn will execute some js code to update the web page inside dcef3, which in turn will trigger some of the dcef3 events (in the main thread), and here is where the program stuck - since the TEventBus.Post() method is locked by a TCriticalSection.

    Solution: In Step #1, don't call ShowModal directly, but use a technique such as PostMessage winapi to 'delay' the execution of ShowModal.

    I'm not sure if I have described it clearly...