[ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Windows specific forum
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Dec 04, 2015 9:26 pm

[ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Post by skinkairewalker »

Worked in PureBasic 6.10 LTS

If you include both a WebGadget and WebViewGadget the program will freeze when initializing the second Gadget; see below.
NOTE: Two WebGadget's or two WebViewGadget's work without an issue;


Does Not Work:

Code: Select all

If OpenWindow(0, 100, 100, 800, 400, "Hello", #PB_Window_SystemMenu)
  WebGadget(0, 0, 0, 400, 400, "https://www.purebasic.com", #PB_Web_Edge)
  WebViewGadget(1, 400, 0, 400, 400)
  SetGadgetText(1, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf


Does Work:

Code: Select all

If OpenWindow(0, 100, 100, 800, 400, "Hello", #PB_Window_SystemMenu)
  WebGadget(0, 0, 0, 400, 400, "https://www.purebasic.com", #PB_Web_Edge)
  WebGadget(1, 400, 0, 400, 400, "", #PB_Web_Edge)
  SetGadgetText(1, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf


Does Work:

Code: Select all

If OpenWindow(0, 100, 100, 800, 400, "Hello", #PB_Window_SystemMenu)
  WebViewGadget(0, 0, 0, 400, 400)
  WebViewGadget(1, 400, 0, 400, 400)
  SetGadgetText(0, "https://www.purebasic.com")
  SetGadgetText(1, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
zikitrake
Addict
Addict
Posts: 870
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: [ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Post by zikitrake »

But this works fine :shock:

Code: Select all

If OpenWindow(0, 100, 100, 800, 400, "Hello", #PB_Window_SystemMenu)
  
  WebViewGadget(0, 400, 0, 400, 400)
  SetGadgetText(0, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
  WebGadget(1, 0, 0, 400, 400, "https://www.purebasic.com", #PB_Web_Edge)
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
PB 6.21 beta, PureVision User
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: [ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Post by breeze4me »

In 6.11 beta 3, an internal command was added to change the cache folder of the WebView2 control using an environment variable(https://www.purebasic.fr/english/viewto ... 78#p621678 , Windows: [Done] WebView Gadget leaves files on hard drive), and there seems to be a conflict with this.
If you find and remove the "WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS" string from the compiled executable, it will run properly. This string is in Unicode format.
Fred
Administrator
Administrator
Posts: 18199
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Post by Fred »

So we can't share the cache between instances ? That's annoying.
breeze4me
Enthusiast
Enthusiast
Posts: 633
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: [ PB6.11 ] Adding WebGadget and WebViewGadget in the samine program causes the 2nd gadget to freeze.

Post by breeze4me »

After investigating, it seems that the problem is caused by setting the environment variable value only in WebViewGadget and not in WebGadget.
Setting the value before the WebGadget as shown below solves the problem.

However, Paul's bug report is for the user data folder, so it can't be set in an environment variable.
A folder with the same name as the executable that is created in the Users/AppData/Roaming folder will not be removed by changing the cache folder.
You must change the userDataFolder string in the following two functions to prevent the new folder from being created in the Users/AppData/Roaming folder.

Code: Select all

CreateWebViewEnvironmentWithOptionsInternal(bool checkRunningInstance, int runtimeType, PCWSTR userDataFolder, IUnknown * environmentOptions, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler * webViewEnvironmentCreatedHandler)
CreateCoreWebView2EnvironmentWithOptions(PCWSTR browserExecutableFolder, PCWSTR userDataFolder, ICoreWebView2EnvironmentOptions * environmentOptions, ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler * environmentCreatedHandler)

Code: Select all

SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", ~"--disk-cache-dir=\"" + GetTemporaryDirectory() + ~"\\WebView2_Cache\"")

; --disk-cache-dir="C:\temp\\WebView2_Cache"

If OpenWindow(0, 100, 100, 800, 400, "Hello", #PB_Window_SystemMenu)
  
  WebGadget(0, 0, 0, 400, 400, "https://www.purebasic.com", #PB_Web_Edge)
  
  WebViewGadget(1, 400, 0, 400, 400)
  SetGadgetText(1, "file://" + #PB_Compiler_Home + "examples/sources/Data/WebView/webview.html")
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
Post Reply