Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DragAndDrop] panic when dropping non-file objects #3596

Closed
Alpa-1 opened this issue Jul 9, 2024 · 4 comments · Fixed by #3597
Closed

[DragAndDrop] panic when dropping non-file objects #3596

Alpa-1 opened this issue Jul 9, 2024 · 4 comments · Fixed by #3597
Labels
Bug Something isn't working

Comments

@Alpa-1
Copy link

Alpa-1 commented Jul 9, 2024

Description

Summary

A panic occurs when dropping a non-file object into the webview - for example a string or browser tab.

Details

internal/frontend/desktop/windows/frontend.go

on the call:

_file, err := objs.GetValueAtIndex(i)

a nil value is returned with no error. Presumably because no value is actually available.

However this nil value is then used subsequently:

file := (*edge.ICoreWebView2File)(unsafe.Pointer(_file))
defer file.Release()

Upon Release() the program panics.


panic: runtime error: invalid memory address or nil pointer dereference
	panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0xb8309e]

goroutine 1 [running, locked to thread]:
github.com/wailsapp/go-webview2/pkg/edge.(*ICoreWebView2File).Release(0x0)
	C:/Users/mic/go/pkg/mod/github.com/wailsapp/[email protected]/pkg/edge/ICoreWebView2File.go:25 +0x1e
panic({0xec12e0?, 0x1979990?})
	C:/Program Files/Go/src/runtime/panic.go:770 +0x136
github.com/wailsapp/go-webview2/pkg/edge.(*ICoreWebView2File).GetPath(0x0)
	C:/Users/mic/go/pkg/mod/github.com/wailsapp/[email protected]/pkg/edge/ICoreWebView2File.go:31 +0x103
github.com/wailsapp/wails/v2/internal/frontend/desktop/windows.(*Frontend).processMessageWithAdditionalObjects(0xc00003a200, {0xc00001eaf8, 0x11}, 0x1e6c00308000, 0x1e6c002d0a80)
	C:/Users/mic/go/pkg/mod/github.com/wailsapp/wails/[email protected]/internal/frontend/desktop/windows/frontend.go:746 +0x60e
github.com/wailsapp/go-webview2/pkg/edge.(*Chromium).MessageReceived(0xc0000dc6c0, 0x1e6c00308000, 0x1e6c002d0a80)
	C:/Users/mic/go/pkg/mod/github.com/wailsapp/[email protected]/pkg/edge/chromium.go:342 +0x3ee
github.com/wailsapp/go-webview2/pkg/edge._ICoreWebView2WebMessageReceivedEventHandlerInvoke(0xc000009140, 0x1e6c00308000, 0x1e6c002d0a80)
	C:/Users/mic/go/pkg/mod/github.com/wailsapp/[email protected]/pkg/edge/ICoreWebView2WebMessageReceivedEventHandler.go:28 +0x38
syscall.SyscallN(0x7ffd344fe1e0, {0xc000712610?, 0x1, 0x1c763c61c28?})
	C:/Program Files/Go/src/runtime/syscall_windows.go:544 +0x11d
[...]

To Reproduce

  1. Enable DragAndDrop
  2. Add a drop target on the frontend --wails-drop-target
  3. Register a callback
OnFileDrop((x,y,f) => { console.log(f) }, true)
  1. Drop a Browser Tab onto the element

Expected behaviour

Dropped non-file object should be disregarded

Screenshots

No response

Attempted Fixes

A simple nil check has alleviated the issue:

_file, err := objs.GetValueAtIndex(i)
if err != nil {
        f.logger.Error("cannot get value at %d : %s", i, err.Error())
	return
}

if _file == nil {
	f.logger.Warning("object at %d is not a file", i)
	continue
}

file := (*edge.ICoreWebView2File)(unsafe.Pointer(_file))
defer file.Release()

System Details

# Wails
Version | v2.9.1

# System
┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | Windows 10 Enterprise                                                            |
| Version      | 2009 (Build: 19045)                                                              |
| ID           | 22H2                                                                             |
| Go Version   | go1.22.1                                                                         |
| Platform     | windows                                                                          |
| Architecture | amd64                                                                            |
| CPU          | AMD Ryzen 7 PRO 4750U with Radeon Graphics                                       |
| GPU          | AMD Radeon(TM) Graphics (Advanced Micro Devices, Inc.) - Driver: 31.0.21024.5005 |
| Memory       | 16GB                                                                             |
└─────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌───────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version       |
| WebView2   | N/A          | Installed | 126.0.2592.87 |
| Nodejs     | N/A          | Installed | 20.12.1       |
| npm        | N/A          | Installed | 10.5.0        |
| *upx       | N/A          | Installed | upx 4.0.1     |
| *nsis      | N/A          | Available |               |
└─────────────── * - Optional Dependency ───────────────┘

# Diagnosis
Optional package(s) installation details:
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

 SUCCESS  Your system is ready for Wails development!

Additional context

No response

@Alpa-1 Alpa-1 added the Bug Something isn't working label Jul 9, 2024
@leaanthony
Copy link
Member

Fantastic catch! There's a PR up for another fix for DnD so I'll look at adding this tomorrow if you don't want to do it.

@Alpa-1
Copy link
Author

Alpa-1 commented Jul 9, 2024

Heya,

I wasnt able to get to it today unfortunately 😕

@leaanthony
Copy link
Member

Please try the above PR to see if this fixes your problem. If you are unsure how to do this, please follow this guide. Let us know how you get on 👍

@Alpa-1
Copy link
Author

Alpa-1 commented Jul 11, 2024

Just tested it out, works great 👍

# Wails
Version  | v2.9.1
Revision | d757a1d9c410d80da3decc5b71b3fe41313bd225
Modified | false

# System
┌─────────────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | Windows 10 Enterprise                                                            |
| Version      | 2009 (Build: 19045)                                                              |
| ID           | 22H2                                                                             |
| Go Version   | go1.22.1                                                                         |
| Platform     | windows                                                                          |
| Architecture | amd64                                                                            |
| CPU          | AMD Ryzen 7 PRO 4750U with Radeon Graphics                                       |
| GPU          | AMD Radeon(TM) Graphics (Advanced Micro Devices, Inc.) - Driver: 31.0.21024.5005 |
| Memory       | 16GB                                                                             |
└─────────────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌───────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version       |
| WebView2   | N/A          | Installed | 126.0.2592.87 |
| Nodejs     | N/A          | Installed | 20.12.1       |
| npm        | N/A          | Installed | 10.5.0        |
| *upx       | N/A          | Installed | upx 4.0.1     |
| *nsis      | N/A          | Available |               |
└─────────────── * - Optional Dependency ───────────────┘

# Diagnosis
Optional package(s) installation details:
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

 SUCCESS  Your system is ready for Wails development!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants