My mouse_position changes every call in one process

Godot Version

4.2.1

System Information (please tell me if needed more)

Windows 11 build 22631.3155
Renderer: Forward+ or Compatiblity

Question

Note: I am using c#. It should not matter though.

I am calling GetGlobalMousePosition() twice in a control node without any process in between. However, they return different positions. Could you give me a hint on what is possibly happening?

How to reproduce (at least on my computer):

  1. Create a new project and a scene
  2. Set CanvasLayer to be the root node of the scene
  3. Add a ColorRect as a child node, use PRESET_FULL_RECT anchors
  4. Attach the script below to the ColorRect
  5. Run the scene and move mouse around
using Godot;
using System;

public partial class GetGlobalMousePositionTest : ColorRect
{
    public override void _GuiInput(InputEvent inputEvent)
    {
        GD.Print(GetGlobalMousePosition(), " first");
        GD.Print(GetGlobalMousePosition(), " second");

        // This has the same problem
        // GD.Print(GetWindow().GetViewport().GetMousePosition(), " viewport first");
        // GD.Print(GetWindow().GetViewport().GetMousePosition(), " viewport second");
    }

    // It is inconsistent also in _Process()
    //
    // public override void _Process(double delta)
    // {
    //     GD.Print(GetGlobalMousePosition(), " process first");
    //     GD.Print(GetGlobalMousePosition(), " process second");

    //     // This has the same problem
    //     GD.Print(GetWindow().GetViewport().GetMousePosition(), " process window first");
    //     GD.Print(GetWindow().GetViewport().GetMousePosition(), " process window second");
    // }
}

Console log (example)

(988, 235) first
(988, 233) second
(1001, 191) first
(1003, 183) second
(1017, 138) first
(1017, 135) second
(1028, 101) first
(1029, 97) second

What about

GetWindow().GetViewport().GetMousePosition();

Thank you for your suggestion. It also gives different positions call by call.

a new godot project was created, using the setup you described, i am not able to reproduce the issue.

instead of Debug.Print (System.Diagnostics.Debug.Print?) i recommend using GD.Print

using Godot;
using System;

public partial class ColorRect : Godot.ColorRect {
	public override void _GuiInput(InputEvent inputEvent) {
		GD.Print(GetGlobalMousePosition(), " first");
		GD.Print(GetGlobalMousePosition(), " second");
		GD.Print(GetWindow().GetViewport().GetMousePosition().ToString() + " viewport first");
		GD.Print(GetWindow().GetViewport().GetMousePosition().ToString() + " viewport second");
	}
}

I appreciate your help! I will use GD.Print(). Now my computer system is a suspect (oh no).
I will keep digging but I may have to post this in github at some point.

I reported this bug in github.