Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash calling 2D space intersect_shape with 3D query parameters #17439

Closed
ghost opened this issue Mar 11, 2018 · 4 comments
Closed

Crash calling 2D space intersect_shape with 3D query parameters #17439

ghost opened this issue Mar 11, 2018 · 4 comments
Assignees
Milestone

Comments

@ghost
Copy link

ghost commented Mar 11, 2018

Godot version:
Godot 3.0.2 Stable

OS/device including version:
Win 7 x64

Issue description:
When the project run the intersect_shape( function, Godot crash with this error :

CrashHandlerException: Program crashed
Dumping the backtrace. Please include this when reporting the bug on https://git
hub.com/godotengine/godot/issues
[0] <couldn't map PC to fn name>
[1] <couldn't map PC to fn name>
[2] <couldn't map PC to fn name>
[3] <couldn't map PC to fn name>
[4] <couldn't map PC to fn name>
[5] <couldn't map PC to fn name>
[6] <couldn't map PC to fn name>
[7] <couldn't map PC to fn name>
[8] <couldn't map PC to fn name>
[9] <couldn't map PC to fn name>
[10] <couldn't map PC to fn name>
[11] <couldn't map PC to fn name>
[12] <couldn't map PC to fn name>
[13] <couldn't map PC to fn name>
[14] <couldn't map PC to fn name>
[15] <couldn't map PC to fn name>
[16] <couldn't map PC to fn name>
[17] <couldn't map PC to fn name>
[18] <couldn't map PC to fn name>
[19] <couldn't map PC to fn name>
[20] <couldn't map PC to fn name>
[21] <couldn't map PC to fn name>
[22] <couldn't map PC to fn name>
[23] BaseThreadInitThunk
-- END OF BACKTRACE --
Nothing read: Invalid argument
ERROR: StreamPeerTCPWinsock::read: Server disconnected!

At: drivers\windows\stream_peer_tcp_winsock.cpp:203

Steps to reproduce:
Just run the project and play

Minimal reproduction project:
Bug raycast.zip

Thank you !

@ShyRed
Copy link
Contributor

ShyRed commented Mar 11, 2018

Holy cow, that was a nasty one to figure out 😂

You are working in 2D space which means you need to use the 2D objects. Replace PhysicsShapeQueryParameters with Physics2DShapeQueryParameters and set_collision_mask with set_collision_layer and it works fine.

The real issue here is that Godot does not notice that the type is wrong. The crash is because down the line it tries to convert PhysicsShapeQueryParameters into Physics2DShapeQueryParameters which fails silently and results in NULL being passed to the Physics2DDirectSpaceState::_intersect_shape method. As the method does not check for NULL it crashes when trying to access the parameter.

I do think that this is a general problem. This most likely will be fixed once GDScript supports typing ( see #10630 )

Working script:

func segment_cast(begin_pos, end_pos):
	var space_state = ray.get_world_2d().get_direct_space_state()
	var segment = SegmentShape2D.new()
	segment.set_a(begin_pos)
	segment.set_b(end_pos)
	var query = Physics2DShapeQueryParameters.new()
	query.set_exclude([self])
	query.set_collision_layer(2)
	query.set_shape(segment)
	var hits = space_state.intersect_shape(query, 12)

@akien-mga akien-mga changed the title GODOT 3.0.2 Crash - Node : RayCast2D, Function : intersect_shape( Crash - Node : RayCast2D, Function : intersect_shape( Mar 13, 2018
@akien-mga akien-mga added this to the 3.1 milestone Mar 13, 2018
@akien-mga
Copy link
Member

I do think that this is a general problem. This most likely will be fixed once GDScript supports typing ( see #10630 )

Well in this case it's just a missing null check though. GDScript typing will be optional, so it won't solve type mismatches in the case where people don't use the optional typing.

@vnen
Copy link
Member

vnen commented Sep 7, 2018

@reduz the issue is not in GDScript, but in the physics engine (missing an argument check).

@vnen vnen removed their assignment Sep 7, 2018
@akien-mga akien-mga self-assigned this Sep 10, 2018
@akien-mga akien-mga changed the title Crash - Node : RayCast2D, Function : intersect_shape( Crash calling 2D space intersect_shape with 3D query parameters Sep 10, 2018
@akien-mga
Copy link
Member

Backtrace with debug symbols (current master):

[1] /lib64/libc.so.6(+0x338a0) [0x7f85185568a0] (??:0)
[2] Physics2DDirectSpaceState::_intersect_shape(Ref<Physics2DShapeQueryParameters> const&, int) (/home/akien/Projects/godot/godot.git/servers/physics_2d_server.cpp:296)
[3] MethodBind2R<Array, Ref<Physics2DShapeQueryParameters> const&, int>::call(Object*, Variant const**, int, Variant::CallError&) (/home/akien/Projects/godot/godot.git/core/method_bind.gen.inc:1608 (discriminator 13))
[4] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/home/akien/Projects/godot/godot.git/core/object.cpp:968 (discriminator 1))
[5] Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) (/home/akien/Projects/godot/godot.git/core/variant_call.cpp:1049 (discriminator 1))
[6] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) (/home/akien/Projects/godot/godot.git/modules/gdscript/gdscript_function.cpp:1069)
[7] GDScriptInstance::call(StringName const&, Variant const**, int, Variant::CallError&) (/home/akien/Projects/godot/godot.git/modules/gdscript/gdscript.cpp:1161)
[8] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/home/akien/Projects/godot/godot.git/core/object.cpp:947 (discriminator 1))
[9] Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) (/home/akien/Projects/godot/godot.git/core/variant_call.cpp:1049 (discriminator 1))
[10] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) (/home/akien/Projects/godot/godot.git/modules/gdscript/gdscript.h:426)
[11] GDScriptInstance::call_multilevel(StringName const&, Variant const**, int) (/home/akien/Projects/godot/godot.git/modules/gdscript/gdscript.cpp:1177)
[12] Node::_notification(int) (/home/akien/Projects/godot/godot.git/core/variant.h:415)
[13] Node::_notificationv(int, bool) (/home/akien/Projects/godot/godot.git/./scene/main/node.h:46 (discriminator 14))
[14] CanvasItem::_notificationv(int, bool) (/home/akien/Projects/godot/godot.git/./scene/2d/canvas_item.h:140 (discriminator 1))
[15] Node2D::_notificationv(int, bool) (/home/akien/Projects/godot/godot.git/./scene/2d/node_2d.h:38 (discriminator 1))
[16] CollisionObject2D::_notificationv(int, bool) (/home/akien/Projects/godot/godot.git/./scene/2d/collision_object_2d.h:39 (discriminator 1))
[17] PhysicsBody2D::_notificationv(int, bool) (/home/akien/Projects/godot/godot.git/scene/2d/physics_body_2d.h:43 (discriminator 1))
[18] KinematicBody2D::_notificationv(int, bool) (/home/akien/Projects/godot/godot.git/scene/2d/physics_body_2d.h:289 (discriminator 1))
[19] Object::notification(int, bool) (/home/akien/Projects/godot/godot.git/core/object.cpp:980)
[20] SceneTree::_notify_group_pause(StringName const&, int) (/home/akien/Projects/godot/godot.git/scene/main/scene_tree.cpp:958)
[21] SceneTree::iteration(float) (/home/akien/Projects/godot/godot.git/scene/main/scene_tree.cpp:474 (discriminator 2))
[22] Main::iteration() (/home/akien/Projects/godot/godot.git/main/main.cpp:1778)
[23] OS_X11::run() (/home/akien/Projects/godot/godot.git/platform/x11/os_x11.cpp:2787)
[24] /home/akien/Projects/godot/godot.git/bin/godot.x11.tools.64(main+0xb5) [0xf34b5b] (/home/akien/Projects/godot/godot.git/platform/x11/godot_x11.cpp:56)
[25] /lib64/libc.so.6(__libc_start_main+0xf0) [0x7f8518543600] (??:0)
[26] /home/akien/Projects/godot/godot.git/bin/godot.x11.tools.64(_start+0x29) [0xf349d9] (/home/iurt/rpmbuild/BUILD/glibc-2.22/csu/../sysdeps/x86_64/start.S:121)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants