hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
10.74k stars 649 forks source link

internal/ui: crash by dropping an HTML element onto the canvas #3043

Closed cowboymacke closed 1 month ago

cowboymacke commented 1 month ago

Ebitengine Version

v2.7.5

Operating System

Go Version (go version)

go1.22.3 darwin/arm64

What steps will reproduce the problem?

Problem happens you object are drag from the web view into the canvas/iframe,

Follow example on https://ebitengine.org/en/documents/webassembly.html

  1. add image into your simple index.html
<!DOCTYPE html>
<iframe src="main.html" width="640" height="480"></iframe>
<img src="https://ebitengine.org/images/logo.png">
  1. Run using favorite web-server
  2. drag and drop image into the iframe

https://github.com/user-attachments/assets/d7a97c11-13f0-4364-8d83-bbc3278e19d1

What is the expected result?

Not to crash the engine

What happens instead?

Engine crash with following console output

goroutine 630 [running]:
wasm_exec.js:22 syscall/js.Value.Get({{}, 0x7ff8000000000002, 0x0}, {0x131fad, 0xa})
wasm_exec.js:22     /opt/homebrew/Cellar/go/1.22.3/libexec/src/syscall/js/js.go:290 +0xc
wasm_exec.js:22 github.com/hajimehoshi/ebiten/v2/internal/ui.(*UserInterface).appendDroppedFiles(0x1cb0248, {{}, 0x7ff8000100002292, 0x284a878})
wasm_exec.js:22     /Users/ling/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.7.5/internal/ui/ui_js.go:713 +0xa
wasm_exec.js:22 created by github.com/hajimehoshi/ebiten/v2/internal/ui.(*UserInterface).setCanvasEventHandlers.func13 in goroutine 12
wasm_exec.js:22     /Users/ling/go/pkg/mod/github.com/hajimehoshi/ebiten/v2@v2.7.5/internal/ui/ui_js.go:693 +0xa

Anything else you feel useful to add?

Only been verified on safari and chrome

hajimehoshi commented 1 month ago

The point is

panic: syscall/js: call of Value.Get on null

there.

hajimehoshi commented 1 month ago

As we discussed in the Discord server, I'm waiting for @cowboymacke's PR. thanks!