Index: trunk/src/gfx/mesh_creator.cc
===================================================================
--- trunk/src/gfx/mesh_creator.cc	(revision 417)
+++ trunk/src/gfx/mesh_creator.cc	(revision 418)
@@ -82,6 +82,6 @@
 				for ( uint16 c = 0; c < chan_count; ++c )
 				{
-					size_t idx = nv::min( old_keys->get_channel(c)->size() - 1, n );
-					pkey += old_keys->get_raw( old_keys->get_channel(c), idx, pkey );
+					size_t idx = nv::min( old_keys->get_channel_size(c) - 1, n );
+					pkey += old_keys->get_raw( *old_keys->get_channel(c), idx, pkey );
 				}
 				kt_channel.data()[n].tform = extract_transform_raw( final_key, key );
@@ -252,6 +252,6 @@
 	}
 
-	raw_data_channel* g_channel = data_channel_creator::create< vertex_g >( p_channel->size() );
-	vec4* tangents              = &( data_channel_access< vertex_g >( g_channel ).data()[0].tangent );
+	raw_data_channel g_channel  = data_channel_creator::create< vertex_g >( p_channel->size() );
+	vec4* tangents              = &( data_channel_access< vertex_g >( &g_channel ).data()[0].tangent );
 	vec3* tangents2             = new vec3[ p_channel->size() ];
 	uint32 tri_count = i_channel ? i_channel->size() / 3 : t_channel->size() / 3;
@@ -334,19 +334,18 @@
 	delete tangents2;
 
-	data_channel_set_creator( m_data ).set_channel( n_channel_index, merge_channels( n_channel, g_channel ) );
-	delete g_channel;
-}
-
-nv::raw_data_channel* nv::mesh_data_creator::merge_channels( const raw_data_channel* a, const raw_data_channel* b )
-{
-	NV_ASSERT( a->size() == b->size(), "merge_channel - bad channels!" );
-	data_descriptor desc  = a->descriptor();
-	desc.append( b->descriptor() );
-
-	raw_data_channel* result = data_channel_creator::create( desc, a->size() );
-	for ( uint32 i = 0; i < a->size(); ++i )
-	{
-		raw_copy_n( a->raw_data() + i * a->element_size(), a->element_size(), raw_data_channel_access( result ).raw_data() + i*desc.element_size() );
-		raw_copy_n( b->raw_data() + i * b->element_size(), b->element_size(), raw_data_channel_access( result ).raw_data() + i*desc.element_size() + a->element_size() );
+	data_channel_set_creator( m_data ).set_channel( n_channel_index, merge_channels( *n_channel, g_channel ) );
+}
+
+nv::raw_data_channel nv::mesh_data_creator::merge_channels( const raw_data_channel& a, const raw_data_channel& b )
+{
+	NV_ASSERT( a.size() == b.size(), "merge_channel - bad channels!" );
+	data_descriptor desc  = a.descriptor();
+	desc.append( b.descriptor() );
+
+	raw_data_channel result = data_channel_creator::create( desc, a.size() );
+	for ( uint32 i = 0; i < a.size(); ++i )
+	{
+		raw_copy_n( a.raw_data() + i * a.element_size(), a.element_size(), raw_data_channel_access( &result ).raw_data() + i*desc.element_size() );
+		raw_copy_n( b.raw_data() + i * b.element_size(), b.element_size(), raw_data_channel_access( &result ).raw_data() + i*desc.element_size() + a.element_size() );
 	}
 
@@ -354,24 +353,24 @@
 }
 
-nv::raw_data_channel* nv::mesh_data_creator::append_channels( const raw_data_channel* a, const raw_data_channel* b, uint32 frame_count )
-{
-	if ( a->descriptor() != b->descriptor() ) return nullptr;
-	if ( a->size() % frame_count != 0 ) return nullptr;
-	if ( b->size() % frame_count != 0 ) return nullptr;
-	size_t vtx_size = a->element_size();
-
-	raw_data_channel* result = data_channel_creator::create( a->descriptor(), a->size() + b->size() );
-	uint8* rdata = raw_data_channel_access( result ).raw_data();
+nv::raw_data_channel nv::mesh_data_creator::append_channels( const raw_data_channel& a, const raw_data_channel& b, uint32 frame_count )
+{
+	NV_ASSERT( a.descriptor() == b.descriptor(), "Merge - append not compatible format!" );
+	NV_ASSERT( a.size() % frame_count == 0, "Merge - append first mesh empty!" );
+	NV_ASSERT( b.size() % frame_count == 0, "Merge - append second mesh empty!" );
+	size_t vtx_size = a.element_size();
+
+	raw_data_channel result = data_channel_creator::create( a.descriptor(), a.size() + b.size() );
+	uint8* rdata = raw_data_channel_access( &result ).raw_data();
 
 	if ( frame_count == 1 )
 	{
-		size_t a_size = vtx_size * a->size();
-		raw_copy_n( a->raw_data(), a_size, rdata );
-		raw_copy_n( b->raw_data(), vtx_size * b->size(), rdata + a_size );
+		size_t a_size = vtx_size * a.size();
+		raw_copy_n( a.raw_data(), a_size, rdata );
+		raw_copy_n( b.raw_data(), vtx_size * b.size(), rdata + a_size );
 	}
 	else
 	{
-		size_t frame_size_a = ( a->size() / frame_count ) * vtx_size;
-		size_t frame_size_b = ( b->size() / frame_count ) * vtx_size;
+		size_t frame_size_a = ( a.size() / frame_count ) * vtx_size;
+		size_t frame_size_b = ( b.size() / frame_count ) * vtx_size;
 		size_t pos_a = 0;
 		size_t pos_b = 0;
@@ -379,6 +378,6 @@
 		for ( size_t i = 0; i < frame_count; ++i )
 		{
-			raw_copy_n( a->raw_data() + pos_a, frame_size_a, rdata + pos );
-			raw_copy_n( b->raw_data() + pos_b, frame_size_b, rdata + pos + frame_size_a );				pos_a += frame_size_a;
+			raw_copy_n( a.raw_data() + pos_a, frame_size_a, rdata + pos );
+			raw_copy_n( b.raw_data() + pos_b, frame_size_b, rdata + pos + frame_size_a );				pos_a += frame_size_a;
 			pos_b += frame_size_b; 
 			pos   += frame_size_a + frame_size_b;
@@ -422,11 +421,12 @@
 	{
 		const raw_data_channel* old = m_data->get_channel( c );
-		bool old_is_index = old->size() > 0 && old->descriptor()[0].vslot == slot::INDEX;
-		size_t frame_count = ( old_is_index ? 1 : old->size() / size );
-		data.set_channel( c, append_channels( old, other->get_channel(c), frame_count ) );
-		NV_ASSERT( data[c], "Merge problem!" );
+		uint32 old_size = old->size();
+		data_descriptor old_desc = old->descriptor();
+		bool old_is_index = old_size > 0 && old_desc[0].vslot == slot::INDEX;
+		size_t frame_count = ( old_is_index ? 1 : old_size / size );
+		data.set_channel( c, append_channels( *old, *other->get_channel(c), frame_count ) );
 		if ( old_is_index )
 		{
-			switch ( old->descriptor()[0].etype )
+			switch ( old_desc[0].etype )
 			{
 			case USHORT : 
@@ -435,5 +435,5 @@
 					raw_data_channel_access ic( data[c] );
 					uint16* indexes = reinterpret_cast<uint16*>( ic.raw_data() );
-					for ( uint16 i = uint16( old->size() ); i < ic.size(); ++i )
+					for ( uint16 i = uint16( old_size ); i < ic.size(); ++i )
 						indexes[i] += uint16( size );
 
@@ -444,5 +444,5 @@
 					raw_data_channel_access ic( data[c] );
 					uint32* indexes = reinterpret_cast<uint32*>( ic.raw_data() );
-					for ( uint32 i = old->size(); i < ic.size(); ++i )
+					for ( uint32 i = old_size; i < ic.size(); ++i )
 						indexes[i] += size;
 				}
@@ -451,5 +451,4 @@
 			}
 		}
-		delete old;
 	}
 }
@@ -459,5 +458,4 @@
 	if ( index < m_pack->get_count() )
 	{
-		data_channel_set_creator( &m_pack->m_meshes[index] ).destroy();
 		data_channel_set_creator( &m_pack->m_meshes[m_pack->m_count - 1] ).move_to( m_pack->m_meshes[index] );
 		m_pack->m_count--;
