window.cursor_position is inaccurate and kind of unreasonable.
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version
Newest master branch #[670f3f0](https://github.com/bevyengine/bevy/commit/670f3f0dce2ced27388b10672d30594d399434e1)
## \[Optional\] Relevant system information
If you cannot get Bevy to build or run on your machine, please include:
- the Rust version you're using (you can get this by running `cargo --version`)
- 1.69.0
- the operating system or browser used, including its version
- macOS v13
## What you did
I'm trying to get cursor_position in FileDragAndDrop::DroppedFile event.
Here is the code.
```rust
fn file_drag_and_drop_system(
mut file_events: EventReader,
mut image_drop_event_writer: EventWriter,
windows: Query<&mut Window>,
cameras: Query<(&Camera, &GlobalTransform), With>,
) {
let (cam, cam_transform) = cameras.single();
for event in file_events.iter() {
if let FileDragAndDrop::DroppedFile { window, path_buf } = event {
let win = windows.get(*window).unwrap();
if path_buf.is_file() {
let ext = path_buf.extension().unwrap().to_str().unwrap();
if ["bmp", "dds", "exr", "jpeg", "jpg", "tga", "png"].contains(&ext) {
let pos = win
.cursor_position()
.and_then(|cursor| cam.viewport_to_world(cam_transform, cursor))
.map(|ray| ray.origin.truncate());
println!("{:?} {:?}", win.cursor_position(), pos);
image_drop_event_writer.send(ImageDropEvent {
droped_image_path: path_buf.clone(),
world_pos: Vec2::new(0.0, 0.0),
})
}
}
}
}
}
```
## What went wrong
When I drop a png file into same location of window multiple times, the cursor position is acting weird and kind of unreasonable, it will be none sometime.
And the world_position is also very weird.
Following is the screen record, check the left bottom corner of the print out messages.
https://user-images.githubusercontent.com/18550/234897526-95117a43-6d37-4b1b-a15c-dd46c925a8c5.mp4
Here is the screen shot of the output incase the video is not clear enough.

- what were you expecting?
window.cursor_position should always return the cursor position.
and camera.viewport_to_world should be able to convert cursor position to world position.
- what actually happened?
window.cursor_position will return none sometime
camera.viewport_to_world always returns wrong position.
Contributor guide
Research direction
Reproduce the repeated file-drop case on macOS using the reported Bevy revision and inspect the FileDragAndDrop::DroppedFile event, Window::cursor_position, and Camera::viewport_to_world behavior. Compare the cursor and world positions across repeated drops, then define the fix by ensuring the reported cursor position and converted world position remain correct for each drop.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100