Skip to content

[v3] Fix not enough memory error when initialising drag and drop on Windows#4765

Merged
leaanthony merged 3 commits into
wailsapp:v3-alphafrom
overlordtm:fix/v3-alpha-windows-dnd
Dec 12, 2025
Merged

[v3] Fix not enough memory error when initialising drag and drop on Windows#4765
leaanthony merged 3 commits into
wailsapp:v3-alphafrom
overlordtm:fix/v3-alpha-windows-dnd

Conversation

@overlordtm

@overlordtm overlordtm commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

Description

This change fixes Not enough memory resources are available to complete this operation. error during drag'n'drop example application initialisation.

2025/12/11 07:34:06 [WebView2] Environment created successfully
Dec 11 07:34:06.572 ERR error registering drag and drop: Not enough memory resources are available to complete this operation.
Dec 11 07:34:06.585 ERR error registering drag and drop: Not enough memory resources are available to complete this operation.
Dec 11 07:34:06.585 ERR error registering drag and drop: Not enough memory resources are available to complete this operation.
Dec 11 07:34:06.586 ERR error registering drag and drop: Not enough memory resources are available to complete this operation.

Fixes #4701

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

 Wails (v3.0.0-alpha.40)  Wails Doctor

# System

┌────────────────────────────────────────────────────────────────────────────────────────────────────┐
| Name              | Windows 10 Enterprise Evaluation                                               |
| Version           | 2009 (Build: 22000)                                                            |
| ID                | 21H2                                                                           |
| Branding          | Windows 11 Enterprise Evaluation                                               |
| Platform          | windows                                                                        |
| Architecture      | amd64                                                                          |
| Go WebView2Loader | true                                                                           |
| WebView2 Version  | 142.0.3595.94                                                                  |
| CPU 1             | AMD Ryzen 9 9900X 12-Core Processor                                            |
| CPU 2             | AMD Ryzen 9 9900X 12-Core Processor                                            |
| CPU 3             | AMD Ryzen 9 9900X 12-Core Processor                                            |
| CPU 4             | AMD Ryzen 9 9900X 12-Core Processor                                            |
| GPU 1             | Red Hat VirtIO GPU DOD controller (Red Hat, Inc.) - Driver: 100.101.104.28500  |
| Memory            | 16GB                                                                           |
└────────────────────────────────────────────────────────────────────────────────────────────────────┘

# Build Environment

┌─────────────────────────────────────────────────────────────────────────────────────────────────────┐
| Wails CLI      | v3.0.0-alpha.40                                                                    |
| Go Version     | go1.25.3                                                                           |
| -buildmode     | exe                                                                                |
| -compiler      | gc                                                                                 |
| CGO_CFLAGS     |                                                                                    |
| CGO_CPPFLAGS   |                                                                                    |
| CGO_CXXFLAGS   |                                                                                    |
| CGO_ENABLED    | 1                                                                                  |
| CGO_LDFLAGS    |                                                                                    |
| DefaultGODEBUG | containermaxprocs=0,decoratemappings=0,tlssha1=1,updatemaxprocs=0,x509sha256skid=0 |
| GOAMD64        | v1                                                                                 |
| GOARCH         | amd64                                                                              |
| GOOS           | windows                                                                            |
└─────────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies

┌────────────────────────────────────────────┐
| MakeAppx.exe (Windows SDK) | Not Installed |
| MSIX Packaging Tool        | 1.2024.405.0  |
| SignTool.exe (Windows SDK) | Not Installed |
| npm                        | 11.6.2        |
| NSIS                       | Not Installed |
|                                            |
└───────── * - Optional Dependency ──────────┘

# Checking for issues

 SUCCESS  No issues found

# Diagnosis

 SUCCESS  Your system is ready for Wails development!

Need documentation? Run: wails3 docs
 ♥   If Wails is useful to you or your company, please consider sponsoring the project: wails3 sponsor

Checklist:

Not sure if I have to update v2 changelog for v3 bugfix, so leaving it unchecked.

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [x ] New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • New Features
    • Enhanced Windows drag-and-drop support with accurate coordinate conversion so dropped items map correctly into webview content.
    • Added drag event callbacks (enter, over, leave) to provide improved visual feedback during drag operations.
    • Extended drag-drop target registration to child/native windows to enable seamless dragging into nested or embedded webview elements.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Adds OLE initialization and refines Windows drag-and-drop handling: converts drop coordinates (screen → window → webview), emits drag events (OnEnter/OnOver/OnLeave), registers drop targets for child Chromium render windows, and adds debug traces and duplicate-registration handling.

Changes

Cohort / File(s) Summary
Windows Drag-and-Drop
v3/pkg/application/webview_window_windows.go
Adds OLE initialization in setupChromium (two locations); updates drag handlers to convert coordinates (screen → window → webview) and call frontend drop logic; introduces OnEnter/OnOver/OnLeave callbacks; registers drop targets for child Chrome_RenderWidgetHostHWND windows with duplicate-registration error handling and debug logging.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review OLE initialization placement and threading/context assumptions.
  • Verify correctness of convertWindowToWebviewCoordinates and coordinate math.
  • Inspect child-window drop-target registration and duplicate-registration handling.
  • Confirm new drag callbacks integrate cleanly with existing event flow and frontend call site.

Possibly related issues

Possibly related PRs

Suggested labels

Bug, Windows, v3, v3-alpha, go, size:M

Poem

🐰 I hopped through Windows, tracing each drop's track,
OLE charms in place to welcome files back,
Child windows now listen, coordinates align,
I cheer as drops land right where they were assigned! 🎉

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: fixing a memory error during drag-and-drop initialization on Windows, which directly relates to the code modifications in the changeset.
Description check ✅ Passed The PR description covers the critical sections: a clear summary of the bug being fixed with error logs, proper issue linkage (Fixes #4701), type of change selection, comprehensive testing details on Windows with full environment configuration, and most checklist items completed.
Linked Issues check ✅ Passed The PR directly addresses issue #4701's requirement to fix drag-and-drop registration errors on Windows by implementing OLE initialization and improving coordinate transformation handling in the Windows webview window code.
Out of Scope Changes check ✅ Passed All code changes are focused on resolving the drag-and-drop initialization error on Windows as outlined in #4701, with enhanced coordinate transformation and callback registration directly addressing the root cause.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52fe03d and 37c076b.

📒 Files selected for processing (1)
  • v3/pkg/application/webview_window_windows.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • v3/pkg/application/webview_window_windows.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@overlordtm overlordtm changed the title Fix not enough memory error when initialising drag and drop on Windows [v3] Fix not enough memory error when initialising drag and drop on Windows Dec 11, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
v3/pkg/application/webview_window_windows.go (2)

563-614: Coordinate conversion looks sound; verify behaviour on high‑DPI setups.

The logic here for mapping window‑relative coordinates into client/webview coordinates via GetWindowRect + ClientToScreen is correct and nicely instrumented.

One thing to double‑check: on per‑monitor DPI >100%, WebView2/JS uses DIPs (CSS px) while these Win32 APIs work in device pixels. That means the webviewX/webviewY you ultimately pass into InitiateFrontendDropProcessing (via the native OnDrop path) might be scaled differently from the x/y coming from the "FilesDropped:x:y" JS path.

Might be worth explicitly testing on a high‑DPI monitor to confirm both paths line up; if not, you may want to normalise here using the window DPI (e.g. via scaleWithWindowDPI) so native and JS drop coordinates are consistent.


1963-2022: OLE initialisation placement is good; consider lifetime and teardown semantics.

Calling w32.OleInitialise() here, on the same thread and immediately before creating / registering the DropTarget, is the right place and should address the "Not enough memory resources..." failures from RegisterDragDrop.

Two follow‑ups worth considering:

  1. OleInitialize lifetime. OleInitialize is ref‑counted per thread and normally expects a matching OleUninitialize. If setupChromium can run multiple times on the same OS thread (e.g. repeatedly creating/destroying windows), this will keep incrementing the OLE ref count without ever releasing it. For the typical “run for the life of the process” model this is probably fine, but if you want to be strict you could:

    • expose a w32.OleUninitialise() wrapper and call it during app/window teardown, or
    • guard w32.OleInitialise() behind a sync.Once at package level so it runs only once per thread/process.
  2. DropTarget registration teardown. You register the same DropTarget instance on every child HWND via w32.RegisterDragDrop, and only call w.dropTarget.Release() in destroy(). If w32.RegisterDragDrop is a thin wrapper over the Win32 API, OLE usually expects a corresponding RevokeDragDrop(hwnd) before destroying the window. It may be worth ensuring you either:

    • explicitly revoke for each registered HWND on teardown, or
    • have the w32 DropTarget/registration helper own revocation so registration and revocation stay paired.

None of this blocks the fix for #4701, but clarifying the intended lifetime now will help avoid subtle leaks or surprises in more dynamic window lifecycles.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47d827c and 52fe03d.

📒 Files selected for processing (1)
  • v3/pkg/application/webview_window_windows.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-17T23:16:11.570Z
Learnt from: Sammy-T
Repo: wailsapp/wails PR: 4570
File: v2/internal/frontend/desktop/linux/window_webkit6.go:97-108
Timestamp: 2025-10-17T23:16:11.570Z
Learning: For webkit_6/GTK4 builds in v2/internal/frontend/desktop/linux/window_webkit6.go, GTK widget creation should not be wrapped in invokeOnMainThread. The activation mechanism (activateWg + onActivate export) already handles thread safety, and additional wrapping would cause issues.

Applied to files:

  • v3/pkg/application/webview_window_windows.go
🧬 Code graph analysis (1)
v3/pkg/application/webview_window_windows.go (1)
v3/pkg/w32/ole32.go (1)
  • OleInitialise (92-94)

@sonarqubecloud

Copy link
Copy Markdown

@leaanthony leaanthony merged commit 54942d4 into wailsapp:v3-alpha Dec 12, 2025
50 checks passed
@leaanthony

Copy link
Copy Markdown
Member

Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants