fix(cef): use DefaultWindowInfo/DefaultBrowserSettings, store client on WebView
- Use purecef.DefaultWindowInfo() and DefaultBrowserSettings() instead of manual unsafe.Sizeof, removing unsafe import from factory.go - Store client on WebView to prevent GC collection - Move back to async BrowserHostCreateBrowser
- commit
- c04ed5c151d131c2f0c042229a4cc1b5c55ac88e
- author
- brice · · 2026-03-19 19:45 UTC
- committer
- brice · · 2026-03-28 04:36 UTC
- parent
- 577c404
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +7 -8
M internal/infrastructure/cef/factory.go +6 -8
| @@ -3,7 +3,6 @@ package cef | |||
| 3 | 3 | import ( | |
| 4 | 4 | "context" | |
| 5 | 5 | "sync/atomic" | |
| 6 | - | "unsafe" | |
| 7 | 6 | ||
| 8 | 7 | purecef "github.com/bnema/purego-cef/cef" | |
| 9 | 8 | ||
| @@ -54,18 +53,17 @@ func (f *WebViewFactory) Create(_ context.Context) (port.WebView, error) { | |||
| 54 | 53 | input.attachTo(pipeline.glArea) | |
| 55 | 54 | wv.input = input | |
| 56 | 55 | ||
| 57 | - | // Build a CEF client backed by our handlerSet. NewClient returns a Client | |
| 58 | - | // that wraps the raw CEF struct with refcounting and callback vtable. | |
| 56 | + | // Build a CEF client backed by our handlerSet. | |
| 57 | + | // Store on WebView to prevent GC collection before CEF AddRef's it. | |
| 59 | 58 | client := purecef.NewClient(wv.handlers) | |
| 59 | + | wv.client = client | |
| 60 | 60 | ||
| 61 | 61 | // Configure WindowInfo for off-screen rendering (OSR). | |
| 62 | - | var windowInfo purecef.WindowInfo | |
| 63 | - | windowInfo.Size = unsafe.Sizeof(windowInfo) | |
| 62 | + | windowInfo := purecef.DefaultWindowInfo() | |
| 64 | 63 | windowInfo.WindowlessRenderingEnabled = 1 | |
| 65 | 64 | ||
| 66 | - | // Configure BrowserSettings with 60 fps for smooth rendering. | |
| 67 | - | var settings purecef.BrowserSettings | |
| 68 | - | settings.Size = unsafe.Sizeof(settings) | |
| 65 | + | // Configure BrowserSettings. | |
| 66 | + | settings := purecef.DefaultBrowserSettings() | |
| 69 | 67 | settings.WindowlessFrameRate = 60 | |
| 70 | 68 | ||
| 71 | 69 | // Create the browser asynchronously. The browser will be nil until | |
| @@ -3,7 +3,6 @@ package cef | |||||
| 3 | import ( | 3 | import ( | ||
| 4 | "context" | 4 | "context" | ||
| 5 | "sync/atomic" | 5 | "sync/atomic" | ||
| 6 | - | "unsafe" | |||
| 7 | 6 | ||||
| 8 | purecef "github.com/bnema/purego-cef/cef" | 7 | purecef "github.com/bnema/purego-cef/cef" | ||
| 9 | 8 | ||||
| @@ -54,18 +53,17 @@ func (f *WebViewFactory) Create(_ context.Context) (port.WebView, error) { | |||||
| 54 | input.attachTo(pipeline.glArea) | 53 | input.attachTo(pipeline.glArea) | ||
| 55 | wv.input = input | 54 | wv.input = input | ||
| 56 | 55 | ||||
| 57 | - | // Build a CEF client backed by our handlerSet. NewClient returns a Client | 56 | + | // Build a CEF client backed by our handlerSet. |
| 58 | - | // that wraps the raw CEF struct with refcounting and callback vtable. | 57 | + | // Store on WebView to prevent GC collection before CEF AddRef's it. |
| 59 | client := purecef.NewClient(wv.handlers) | 58 | client := purecef.NewClient(wv.handlers) | ||
| 59 | + | wv.client = client | |||
| 60 | 60 | ||||
| 61 | // Configure WindowInfo for off-screen rendering (OSR). | 61 | // Configure WindowInfo for off-screen rendering (OSR). | ||
| 62 | - | var windowInfo purecef.WindowInfo | 62 | + | windowInfo := purecef.DefaultWindowInfo() |
| 63 | - | windowInfo.Size = unsafe.Sizeof(windowInfo) | |||
| 64 | windowInfo.WindowlessRenderingEnabled = 1 | 63 | windowInfo.WindowlessRenderingEnabled = 1 | ||
| 65 | 64 | ||||
| 66 | - | // Configure BrowserSettings with 60 fps for smooth rendering. | 65 | + | // Configure BrowserSettings. |
| 67 | - | var settings purecef.BrowserSettings | 66 | + | settings := purecef.DefaultBrowserSettings() |
| 68 | - | settings.Size = unsafe.Sizeof(settings) | |||
| 69 | settings.WindowlessFrameRate = 60 | 67 | settings.WindowlessFrameRate = 60 | ||
| 70 | 68 | ||||
| 71 | // Create the browser asynchronously. The browser will be nil until | 69 | // Create the browser asynchronously. The browser will be nil until | ||
M internal/infrastructure/cef/webview.go +1 -0
| @@ -31,6 +31,7 @@ type WebView struct { | |||
| 31 | 31 | id port.WebViewID | |
| 32 | 32 | browser purecef.Browser | |
| 33 | 33 | host purecef.BrowserHost | |
| 34 | + | client purecef.Client // prevent GC from collecting the client before CEF AddRef's it | |
| 34 | 35 | pipeline *renderPipeline | |
| 35 | 36 | input *inputBridge | |
| 36 | 37 | handlers *handlerSet | |
| @@ -31,6 +31,7 @@ type WebView struct { | |||||
| 31 | id port.WebViewID | 31 | id port.WebViewID | ||
| 32 | browser purecef.Browser | 32 | browser purecef.Browser | ||
| 33 | host purecef.BrowserHost | 33 | host purecef.BrowserHost | ||
| 34 | + | client purecef.Client // prevent GC from collecting the client before CEF AddRef's it | |||
| 34 | pipeline *renderPipeline | 35 | pipeline *renderPipeline | ||
| 35 | input *inputBridge | 36 | input *inputBridge | ||
| 36 | handlers *handlerSet | 37 | handlers *handlerSet | ||