Răsfoiți Sursa

Fix android SIGBUS when spawning units with multiple nodes

Daniele Bartolini 12 ani în urmă
părinte
comite
45b6c303ad
4 a modificat fișierele cu 25 adăugiri și 21 ștergeri
  1. 17 13
      engine/world/SceneGraph.cpp
  2. 2 1
      engine/world/SceneGraph.h
  3. 1 2
      engine/world/Unit.cpp
  4. 5 5
      engine/world/Unit.h

+ 17 - 13
engine/world/SceneGraph.cpp

@@ -52,22 +52,23 @@ SceneGraph::SceneGraph(Allocator& a, uint32_t index)
 }
 
 //-----------------------------------------------------------------------------
-void SceneGraph::create(const Matrix4x4& root, uint32_t count, const StringId32* name, const Matrix4x4* local, int32_t* parent)
+void SceneGraph::create(const Matrix4x4& root, uint32_t count, UnitNode* nodes)
 {
-	char* mem = (char*) m_allocator->allocate(count * (sizeof(uint8_t) + sizeof(Matrix4x4) + sizeof(Matrix4x4) + sizeof(int32_t) + sizeof(StringId32)));
-
 	m_num_nodes = count;
 
-	m_flags = (uint8_t*) mem; mem += sizeof(uint8_t) * count;
-	m_world_poses = (Matrix4x4*) mem; mem += sizeof(Matrix4x4) * count;
-	m_local_poses = (Matrix4x4*) mem; mem += sizeof(Matrix4x4) * count;
-	m_parents = (int32_t*) mem; mem += sizeof(int32_t) * count;
-	m_names = (StringId32*) mem; mem += sizeof(StringId32) * count;
+	m_flags = (uint8_t*) m_allocator->allocate(sizeof(uint8_t) * count);
+	m_world_poses = (Matrix4x4*) m_allocator->allocate(sizeof(Matrix4x4) * count);
+	m_local_poses = (Matrix4x4*) m_allocator->allocate(sizeof(Matrix4x4) * count);
+	m_parents = (int32_t*) m_allocator->allocate(sizeof(int32_t) * count);
+	m_names = (StringId32*) m_allocator->allocate(sizeof(StringId32) * count);
 
-	memset(m_flags, (int) CLEAN, sizeof(uint8_t) * count);
-	memcpy(m_local_poses, local, sizeof(Matrix4x4) * count);
-	memcpy(m_parents, parent, sizeof(int32_t) * count);
-	memcpy(m_names, name, sizeof(StringId32) * count);
+	for (uint32_t i = 0; i < count; i++)
+	{
+		m_flags[i] = (int) CLEAN;
+		m_local_poses[i] = nodes[i].pose;
+		m_parents[i] = -1;
+		m_names[i] = nodes[i].name;
+	}
 
 	// Compute initial world poses
 	for (uint32_t i = 1; i < m_num_nodes; i++)
@@ -84,8 +85,11 @@ void SceneGraph::create(const Matrix4x4& root, uint32_t count, const StringId32*
 //-----------------------------------------------------------------------------
 void SceneGraph::destroy()
 {
-	// m_flags is the start of allocated memory
 	m_allocator->deallocate(m_flags);
+	m_allocator->deallocate(m_world_poses);
+	m_allocator->deallocate(m_local_poses);
+	m_allocator->deallocate(m_parents);
+	m_allocator->deallocate(m_names);
 }
 
 //-----------------------------------------------------------------------------

+ 2 - 1
engine/world/SceneGraph.h

@@ -30,6 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Vector3.h"
 #include "Matrix4x4.h"
 #include "Quaternion.h"
+#include "UnitResource.h"
 
 namespace crown
 {
@@ -44,7 +45,7 @@ struct SceneGraph
 	/// @a name, @a local and @parent are the array containing the name of the nodes,
 	/// the local poses of the nodes and the links between the nodes respectively.
 	/// A parent of -1 means "no parent".
-	void			create(const Matrix4x4& root, uint32_t count, const StringId32* name, const Matrix4x4* local, int32_t* parent);
+	void			create(const Matrix4x4& root, uint32_t count, UnitNode* nodes);
 
 	/// Destroys the graph deallocating memory if necessary.
 	void			destroy();

+ 1 - 2
engine/world/Unit.cpp

@@ -84,8 +84,7 @@ const UnitResource*	Unit::resource() const
 void Unit::create_objects(const Matrix4x4& pose)
 {
 	// Create the scene graph
-	m_scene_graph.create(pose, m_resource->num_scene_graph_nodes(), m_resource->scene_graph_names(),
-							m_resource->scene_graph_poses(), m_resource->scene_graph_parents());
+	m_scene_graph.create(pose, m_resource->num_scene_graph_nodes(), m_resource->scene_graph_nodes());
 
 	create_camera_objects();
 	create_renderable_objects();

+ 5 - 5
engine/world/Unit.h

@@ -72,11 +72,11 @@ struct Mesh;
 struct Sprite;
 struct UnitResource;
 
-#define MAX_CAMERA_COMPONENTS 8
-#define MAX_MESH_COMPONENTS 8
-#define MAX_SPRITE_COMPONENTS 8
-#define MAX_ACTOR_COMPONENTS 8
-#define MAX_MATERIAL_COMPONENTS 8
+#define MAX_CAMERA_COMPONENTS 16
+#define MAX_MESH_COMPONENTS 16
+#define MAX_SPRITE_COMPONENTS 16
+#define MAX_ACTOR_COMPONENTS 16
+#define MAX_MATERIAL_COMPONENTS 16
 
 struct Unit
 {