godotengine / godot

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

Unable to create collision object via code on Android #22379

Closed usbhell closed 4 years ago

usbhell commented 6 years ago

Godot version:

2.1.5 Stabe

OS/device including version:

multiple android devices

Issue description:

I'm creating some procedural Terrain and attempting to add a collision object. It works fine on my pc/mac but crashes on my android devices. The attached project attempts to do the same with the default blender cube and crashes on all my devices too. I feel I must be doing something dumb.

# Method 1
get_node("MeshInstance").create_trimesh_collision()

or

# Method 2
var mesh = get_node("MeshInstance").get_mesh()
var shape = ConcavePolygonShape.new()
shape.set_faces(mesh.get_faces())
get_node("MeshInstance/StaticBody").set_shape(0,shape)

Steps to reproduce: run the attached project on an android device

Minimal reproduction project:

collision.zip

usbhell commented 6 years ago

It seems the line mesh.get_faces() was causing the crash in the second method. I guess create_trimesh_collision() does the same and explains why it also causes a crash.

Creating my own faces array and omitting that call solved my problem.

var shape = ConcavePolygonShape.new()
shape.set_faces(mesh_data_array)
get_node("StaticBody").add_shape(shape)
Zireael07 commented 6 years ago

I suggest reopening, mesh.get_faces() shouldn't be crashing on any OS.

usbhell commented 6 years ago

No problem, reopening

akien-mga commented 4 years ago

Fixed in the master branch (at least after #34794).