touilleMan / godot-python

Python support for Godot 🐍🐍🐍
Other
1.87k stars 142 forks source link

_input causes game to stop running. #217

Open bpm-mcgill opened 4 years ago

bpm-mcgill commented 4 years ago

I was making a camera for my character when the game began to close its self. I realized that it was only occurring when I moved my mouse. It would say (before I moved my mouse):

--- Debugging process started ---
Godot Engine v3.2.2.stable.official - https://godotengine.org
OpenGL ES 3.0 Renderer: Mesa DRI Intel(R) Sandybridge Mobile 

Pythonscript 0.40.0 (CPython 3.8.3.final.0)
Calling wrapper on <class 'scripts.Player.Player'>
Calling wrapper on <class 'scripts.main.main'>
Calling wrapper on <class 'scripts.test1.test1'>

and when I moved my mouse it would add: --- Debugging process stopped ---

It works with gdscript, but breaks with python. This is all that is needed for this to happen:

def _input(self,event):
    pass

Does anyone know why this is happening and how to fix it?

matheus2740 commented 4 years ago

Looks like #189 . Do you not get a traceback when this happens? What OS are you running on? In linux I got this crash when compiling godot with LLVM/Clang but not GCC, so if you can try building godot from source with GCC.

bpm-mcgill commented 4 years ago

"Do you not get a traceback when this happens?" Nope, the only thing that is returned is what I gave earlier. "What OS are you running on?" Linux Debian Buster I installed godot with https://godotengine.org/download/linux .

matheus2740 commented 4 years ago

I'll have a crack at this bug again this weekend. Meanwhile, try building godot from source with GCC, or use Input.is_action_pressed / Input.is_key_pressed

gustavi commented 3 years ago

Issue still present on version 0.50.0 with Godot 3.2.3.

On Windows 64bit the following code crash the program started :

from godot import exposed, Node2D

@exposed
class Test(Node2D):

    def _ready(self):
        print("ready")

    def _input(self, event):
        print("input")

Console output :

Running: C:\xxx\Godot_v3.2.3-stable_win64.exe --path C:/yyy --remote-debug 127.0.0.1:6007 --allow_focus_steal_pid 10576 --position 448,240 res://Test.tscn
Godot Engine v3.2.3.stable.official - https://godotengine.org
OpenGL ES 3.0 Renderer: GeForce GTX 1660 SUPER/PCIe/SSE2

Pythonscript 0.50.0 (CPython 3.8.5.final.0)
ready
input

You can notice that _input method is called once then crash.

gustavi commented 3 years ago

More logs now appears :

[...]
ready
input
ERROR: call: Condition "!instance" is true. Returned: Variant()
   At: ./core/method_bind.gen.inc:2284

Even if I trigger an exception on _input() Godot crash.

sustainablelab commented 3 years ago

I observe the same on Windows 64bit. But the crash only happens if the mouse is inside the game window.

Code:

from godot import exposed, export
from godot import *

@exposed
class Main(Node2D):

    def _ready(self):
        print("_ready")

    def _input(self, event):
        print("_input")
        if event.is_action_pressed("ui_select"):
            print("Pressed Space.")

Output in terminal (Windows PowerShell):

1. Play the project:

PS C:\Users\mike> Running: C:\cygwin64\home\mike\Godot_v3.2.3-stable_win64.exe --path C:/cygwin64/home/mike/godot-games/talk-to-python --remote-debug 127.0.0.1:6007 --allow_focus_steal_pid 20116 --position 580,284
Godot Engine v3.2.3.stable.official - https://godotengine.org
OpenGL ES 3.0 Renderer: GeForce GTX 1080/PCIe/SSE2

Pythonscript 0.50.0 (CPython 3.8.5.final.0)
_ready

2. Press Space:

_input
Pressed Space.
_input

_3. Move the mouse into the game window:

_input

The the game window closes. This final _input shows up in the terminal, but not in the Godot Editor Output window.

If the mouse is already inside the game window when I play the project, the game window closes immediately.

Workaround for registering a single event per key press using _process() instead of _input():

    def _process(self, delta):
        if Input.is_action_just_pressed("ui_select"):
            print("Pressed Space.")
KouriiRaiko commented 3 years ago

Still experiencing this issue, and have to use _process() instead of _input() as a workaround.