godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.83k stars 21.13k forks source link

LSP segfault with AABB in script #66376

Open rcorre opened 2 years ago

rcorre commented 2 years ago

Godot version

3.5.stable.arch_linux

System information

Linux 5.19.7-arch1-1

Issue description

Given the following script:

extends VisualInstance

const MAX_TRIES := 100
const CONTROL_POINT_SCENE := preload("res://scenes/ControlPoint.tscn")

var raycast := RayCast.new()

func _ready() -> void:
    add_child(raycast)
    raycast.cast_to = Vector3(0, -100, 0)

func spawn_control_point():
    Log.info("Spawning control point")
    var bounds := get_transformed_aabb()
    var pos := Vector2(
        bounds.

With the cursor positioned after bounds, requesting completion causes a segfault. This sounds similar to https://github.com/godotengine/godot/issues/24697, but doesn't involve a nested class. I tried reproing https://github.com/godotengine/godot/issues/24697 on 3.5 and could not, so this seems to be a separate issue.

Thread 1 "godot.x11.tools" received signal SIGSEGV, Segmentation fault.
0x0000000006776048 in vtable for __cxxabiv1::__si_class_type_info ()
(gdb) erresc: unknown csi ESC[>4;0m
erresc: unknown csi ESC[23;0t
(gdb) bt
#0  0x0000000006776048 in vtable for __cxxabiv1::__si_class_type_info ()
#1  0x0000000003c20345 in MethodBind0RC<AABB>::call (this=0x9f0b790, p_object=0x1795d430, p_args=0x0, p_arg_count=0, 
    r_error=...) at ./core/method_bind.gen.inc:581
#2  0x0000000001981ef6 in _guess_expression_type (p_context=..., p_expression=0x1790fd00, r_type=...)
    at modules/gdscript/gdscript_editor.cpp:886
#3  0x00000000019843c7 in _guess_identifier_type (p_context=..., p_identifier=..., r_type=...)
    at modules/gdscript/gdscript_editor.cpp:1240
#4  0x00000000019809c6 in _guess_expression_type (p_context=..., p_expression=0x179100c0, r_type=...)
    at modules/gdscript/gdscript_editor.cpp:670
#5  0x000000000198f28a in GDScriptLanguage::complete_code (this=0x874b110, p_code=..., p_path=..., p_owner=0x1795d430, 
    r_options=0x7fffffffc778, r_forced=@0x7fffffffc6bb: false, r_call_hint=...)
    at modules/gdscript/gdscript_editor.cpp:2669
#6  0x0000000001a60f5c in GDScriptWorkspace::completion (this=0x13d42a30, p_params=..., r_options=0x7fffffffc778)
    at modules/gdscript/language_server/gdscript_workspace.cpp:603
#7  0x0000000001a4e530 in GDScriptTextDocument::completion (this=0x13d42c80, p_params=...)
    at modules/gdscript/language_server/gdscript_text_document.cpp:163
#8  0x0000000001a5ae8d in MethodBind1R<Array, Dictionary const&>::call (this=0x13d40500, p_object=0x13d42c80, 
    p_args=0x7fffffffca50, p_arg_count=1, r_error=...) at ./core/method_bind.gen.inc:941
#9  0x000000000498687a in Object::call (this=0x13d42c80, p_method=..., p_args=0x7fffffffca50, p_argcount=1, r_error=...)
    at core/object.cpp:918
#10 0x000000000498606e in Object::callv (this=0x13d42c80, p_method=..., p_args=...) at core/object.cpp:827
#11 0x0000000001a82ffe in JSONRPC::process_action (this=0x13571308, p_action=..., p_process_arr_elements=true)
    at modules/jsonrpc/jsonrpc.cpp:129
#12 0x0000000001a8384c in JSONRPC::process_string (this=0x13571308, p_input=...) at modules/jsonrpc/jsonrpc.cpp:165
#13 0x0000000001a3ab0d in GDScriptLanguageProtocol::process_message (this=0x13571308, p_text=...)
    at modules/gdscript/language_server/gdscript_language_protocol.cpp:141
#14 0x0000000001a3a56e in GDScriptLanguageProtocol::LSPeer::handle_data (this=0x1b2cf400)
    at modules/gdscript/language_server/gdscript_language_protocol.cpp:96
#15 0x0000000001a3bf1b in GDScriptLanguageProtocol::poll (this=0x13571308)
    at modules/gdscript/language_server/gdscript_language_protocol.cpp:242
#16 0x0000000001a4a8fd in GDScriptLanguageServer::_notification (this=0x135710f0, p_what=25)
    at modules/gdscript/language_server/gdscript_language_server.cpp:62
#17 0x0000000001a4ba48 in GDScriptLanguageServer::_notificationv (this=0x135710f0, p_notification=25, p_reversed=false)
    at modules/gdscript/language_server/gdscript_language_server.h:39
#18 0x000000000498699f in Object::notification (this=0x135710f0, p_notification=25, p_reversed=false)
    at core/object.cpp:927
#19 0x0000000003904872 in SceneTree::_notify_group_pause (this=0xa599a10, p_group=..., p_notification=25)
    at scene/main/scene_tree.cpp:1105
#20 0x0000000003901fbf in SceneTree::idle (this=0xa599a10, p_time=0.0500000045) at scene/main/scene_tree.cpp:607
#21 0x000000000189dc78 in Main::iteration () at main/main.cpp:2298
#22 0x000000000185d9cf in OS_X11::run (this=0x7fffffffd280) at platform/x11/os_x11.cpp:3987
#23 0x0000000001847e56 in main (argc=2, argv=0x7fffffffdbb8) at platform/x11/godot_x11.cpp:59
(gdb) frame 1
#1  0x0000000003c20345 in MethodBind0RC<AABB>::call (this=0x9f0b790, p_object=0x1795d430, p_args=0x0, p_arg_count=0, 
    r_error=...) at ./core/method_bind.gen.inc:581
581                     Variant ret = (instance->*method)();
(gdb) p instance
$1 = (__UnexistingClass *) 0x1795d430
(gdb) p method
$2 = &virtual table offset 288
(gdb) info locals
__FUNCTION__ = "call"
instance = 0x1795d430
ret = {type = 4294949136, _data = {_bool = 24, _int = 26840344, _real = 1.3260891892961227e-316, 
    _transform2d = 0x1998d18 <CowData<Variant const*>::size() const+24>, 
    _aabb = 0x1998d18 <CowData<Variant const*>::size() const+24>, 
    _basis = 0x1998d18 <CowData<Variant const*>::size() const+24>, 
    _transform = 0x1998d18 <CowData<Variant const*>::size() const+24>, 
    _ptr = 0x1998d18 <CowData<Variant const*>::size() const+24>, 
    _mem = "\030\215\231\001\000\000\000\000\020\271\377\377\377\177\000"}}

Steps to reproduce

  1. Open the example project
  2. Open maps/ControlPointSpawner.gd in an external editor using the Godot LSP
  3. Position the cursor after bounds.
  4. Request completion candidates

Minimal reproduction project

example.zip

rcorre commented 2 years ago

I'm not sure if either of these things would affect the LSP, but:

Rubonnek commented 2 years ago

CC @Razoric480

Razoric480 commented 2 years ago

Peculiar. I'll add it to my todo and try to replicate it on this end.

kleonc commented 1 year ago

Related: https://github.com/godotengine/godot/issues/67631#issuecomment-1309349880.