Game Development Community

dMemcpy to vertex buffer in _createVBIB causing crash with addMesh

by Thomas -elfprince13- Dickerson · in Torque 3D Professional · 06/23/2011 (8:13 pm) · 3 replies

I've been working on adding support for the LDraw parts library to T3D, and this week have finally got parts and models to load in-game as TSMeshes (I subclassed the AppMesh/AppNode/AppMaterial/TSShapeLoader classes to do so).

I've been using TSShapeConstructor to add collision meshes to my test models, and it worked just fine. The next step was assembling a character model from separate LDraw meshes by using TSShapeConstructor to rig them to a skeleton.

I produced the code given below based on Michael Perry's documentation - and while I didn't expect it to look good on the stock skeleton (the player.dts I am using is just a copy of the Gideon model from which I am stripping all its meshes), I *was* expecting to see something. Instead it crashes after proceeding all the way through adding the correct mesh from 3626a.dat and attempting to initialize the vertex buffer. Are there restrictions or quirks I should know about here? Does anyone have a hunch as to what the problem may be?

//-----------------------------------------------------------------------------
// Updated Gideon Model done in 3DS Max with Stock Torque Animations
//-----------------------------------------------------------------------------

singleton TSShapeConstructor(MinifigDts)
{
   baseShape = "./player.dts";
   sequence0 = "./player_root.dsq root";
   sequence1 = "./player_forward.dsq run";
   sequence2 = "./player_back.dsq back";
   sequence3 = "./player_side.dsq side";
   sequence4 = "./player_lookde.dsq look";
   sequence5 = "./player_headlook.dsq headLook";
   sequence6 = "./player_fall.dsq fall";
   sequence7 = "./player_land.dsq land";
   sequence8 = "./player_jump.dsq jump";
   sequence9  = "./player_diehead.dsq death1";
   sequence10 = "./player_diechest.dsq death2";
   sequence11 = "./player_dieback.dsq death3";
   sequence12 = "./player_diesidelf.dsq death4";
   sequence13 = "./player_diesidert.dsq death5";
   sequence14 = "./player_dieleftleg.dsq death6";
   sequence15 = "./player_dierightleg.dsq death7";
   sequence16 = "./player_dieslump.dsq death8";
   sequence17 = "./player_dieknees.dsq death9";
   sequence18 = "./player_dieforward.dsq death10";  
   sequence19 = "./player_diespin.dsq death11";
   sequence20 = "./player_looksn.dsq looksn";
   sequence21 = "./player_lookms.dsq lookms";
   sequence22 = "./player_root.dsq scoutroot";
   sequence23 = "./player_headside.dsq headside";
   sequence24 = "./player_recoil.dsq light_recoil";
   sequence25 = "./player_root.dsq sitting";
   sequence26 = "./player_celsalute.dsq celsalute";
   sequence27 = "./player_celwave.dsq celwave";
   sequence28 = "./player_standjump.dsq standjump";
   sequence29 = "./player_looknw.dsq looknw";
   sequence30 = "./player_celcheck.dsq celcheck";
   sequence31 = "./player_celimp.dsq celimp";
   sequence32 = "./player_celrocky.dsq celrocky";
   sequence33 = "./player_celtaunt.dsq taunt";
   sequence34 = "./player_celdance.dsq celdance";
   sequence35 = "./player_celflex.dsq celflex";
   sequence36 = "./player_crouchroot.dsq crouch_root";
   sequence37 = "./player_crouchback.dsq crouch_back";
   sequence38 = "./player_crouchforward.dsq crouch_forward";
   sequence39 = "./player_crouchside.dsq crouch_side";
   sequence40 = "./player_swimroot.dsq swim_root";
   sequence41 = "./player_swimback.dsq swim_backward";
   sequence42 = "./player_swimforward.dsq swim_forward";
   sequence43 = "./player_swimsidelf.dsq swim_left";
   sequence44 = "./player_swimsiderg.dsq swim_right";
};  


function addLDrawMesh(%shape, %filename, %name, %node)
{
	/*
	 
	 %shape.addNode("Bip01 Pelvis",      "",                  "-8.10647e-005 8.34974e-006 1.28118 0.00147092 0.999914 0.000312013 1.50833");
	 %shape.addNode("Bip01 Spine",       "Bip01 Pelvis",      "0.117738 -0.000117005 0.00695224 0.995531 0 0.054662 0.178899");
	 %shape.addNode("Bip01 Spine1",      "Bip01 Spine",       "0.149188 -0.000154936 5.87594e-006 0.158383 0.207314 0.965104 0.285376");
	 %shape.addNode("Bip01 Spine2",      "Bip01 Spine1",      "0.202462 -0.000162536 2.93078e-005 0.731516 -0.35723 -0.579706 0.251143");
	 %shape.addNode("Bip01 Neck",        "Bip01 Spine2",      "0.209867 -4.86846e-005 -2.05922e-005 -0.926274 0.0899337 -0.365008 0.431595");
	 %shape.addNode("Bip01 Head",        "Bip01 Neck",        "0.067264 -6.98505e-009 -6.66524e-009 -0.139433 0.872649 -0.450268 0.089769");
	 %shape.addNode("Eye",               "Bip01 Head",        "0.180021 0.33282 -0.00125568 -0.0139777 -0.999387 0.030751 1.57784");
	 %shape.addNode("Bip01 L Clavicle",  "Bip01 Neck",        "0.0059334 0.0332864 0.0795624 -0.632128 -0.230228 -0.739819 2.58923");
	 %shape.addNode("Bip01 L UpperArm",  "Bip01 L Clavicle",  "0.358891 -1.27006e-008 1.34618e-007 0.300944 -0.93298 0.197112 1.51847");
	 %shape.addNode("Bip01 L Forearm",   "Bip01 L UpperArm",  "0.395474 -1.37648e-008 1.96789e-008 0 0 0.999871 0.850149");
	 %shape.addNode("Bip01 L Hand",      "Bip01 L Forearm",   "0.363508 3.95569e-008 3.80099e-008 -0.975012 -0.0676349 0.211535 3.8945");
	 %shape.addNode("Bip01 R Clavicle",  "Bip01 Neck",        "-0.00593357 -0.0331793 -0.0795624 0.631473 -0.0957054 -0.769459 3.0916");
	 %shape.addNode("Bip01 R UpperArm",  "Bip01 R Clavicle",  "0.358891 -1.02138e-008 1.01681e-007 0.594451 0.803854 -0.017401 1.47305");
	 %shape.addNode("Bip01 R Forearm",   "Bip01 R UpperArm",  "0.395474 6.19864e-008 1.31302e-008 0 0 0.999951 1.88239");
	 %shape.addNode("Bip01 R Hand",      "Bip01 R Forearm",   "0.363508 1.03579e-008 -1.18848e-008 -0.976003 -0.105148 0.190568 1.71108");
	 %shape.addNode("mount0",            "Bip01 R Hand",      "0.192386 0.0479768 0.000897807 0.0616579 0.0736096 0.995312 1.76131");
	 %shape.addNode("mount2",            "Bip01 Spine2",      "0.101603 -0.255502 0.00682753 0.0431623 -0.998124 -0.0431623 1.57267");
	 %shape.addNode("mount1",            "Bip01 Spine2",      "0.101603 -0.255502 0.00682756 0.0431623 -0.998124 -0.0431623 1.57267");
	 %shape.addNode("Bip01 L Thigh",     "Bip01 Spine",       "-0.117582 -0.0342993 0.1847 -0.227865 -0.966002 -0.121932 3.27836");
	 %shape.addNode("Bip01 L Calf",      "Bip01 L Thigh",     "0.567764 2.88694e-008 -2.61884e-009 0 0 0.999795 0.784881");
	 %shape.addNode("Bip01 L Foot",      "Bip01 L Calf",      "0.659264 6.37417e-009 5.70856e-009 -0.0798252 0.398941 -0.913186 0.331842");
	 %shape.addNode("Ski0",              "Bip01 L Foot",      "0.587469 -0.0426512 -0.0990439 0.750521 0.554827 0.358877 1.9778");
	 %shape.addNode("Bip01 R Thigh",     "Bip01 Spine",       "-0.117896 0.0347 -0.198562 -0.134559 -0.982239 0.130533 2.9039");
	 %shape.addNode("Bip01 R Calf",      "Bip01 R Thigh",     "0.567764 8.48371e-010 1.88575e-009 0 0 0.999915 0.836729");
	 %shape.addNode("Bip01 R Foot",      "Bip01 R Calf",      "0.659264 -3.34983e-008 -2.20877e-008 0.0784375 -0.241304 -0.967069 0.567876");
	 %shape.addNode("Ski1",              "Bip01 R Foot",      "0.600815 -0.0369749 0.0998079 -0.352371 -0.698146 -0.62318 3.91937");
	 %shape.addNode("Unlink",            "",                  "-0.00586435 -0.000234549 0.056661 -0.579417 -0.577691 -0.574872 2.09521");
	 %shape.addNode("Cam",               "Unlink",            "0.237214 2.06536 -0.00742381 0.999942 -0.00266823 -0.00189359 1.57655");
	 */
	%shape.addMesh(%filename, %filename @ "2", %name @ "2");
	%shape.setObjectNode(%name, %node);
}

function MinifigDts::onLoad(%this)
{
	// remove the existing nodes and geometry so we start with a blank shape
	%count = %this.getObjectCount();
	for (%i = %count-1; %i >= 0; %i--)
		%this.removeObject(%this.getObjectName(%i));
	
	addLDrawMesh(%this, "3626a.dat", "head", "Bip01 Head");
	addLDrawMesh(%this, "981.dat", "arm_left", "Bip01 L UpperArm");
	addLDrawMesh(%this, "982.dat", "arm_right", "Bip01 R UpperArm");
	addLDrawMesh(%this, "983.dat", "hand_left", "Bip01 L Hand");
	addLDrawMesh(%this, "983.dat", "hand_right", "Bip01 R Hand");
	addLDrawMesh(%this, "970.dat", "hips", "Bip01 Pelvis");
	addLDrawMesh(%this, "972.dat", "leg_left", "Bip01 L Thigh");
	addLDrawMesh(%this, "973.dat", "torso", "Bip01 Spine");
	addLDrawMesh(%this, "971.dat", "leg_left", "Bip01 R Thigh");
	
	%shape.addMesh("cube", "bounds", "Col-1");
	
	
}

About the author

C.S. PhD student at Brown University. Project lead for FreeBuild. Administrator, Cemetech tech community. Webmaster for the Village2Village Projects and the Vermont Sustainable Heating Initiative.


#1
07/20/2011 (9:17 pm)
*Bump*

I still haven't made headway on this problem, so if anyone has a hunch, I'm listening.
#2
07/21/2011 (3:14 pm)
Are you running (or ported from) T3D 1.1 final? There was a crash bug relating to TSShapeConstructor::addMesh fixed in that release.

You could also check that using addMesh with a normal DTS or DAE shape works correctly. If it does, it would suggest the problem is in your LDraw mesh loading code.

Since you've made custom source code changes, your best bet is to do some more debugging - step through TSShape::addMesh and try to find out why dMemcpy is crashing. Perhaps you haven't set something up correctly when loading the LDraw mesh data?
#3
07/21/2011 (3:21 pm)
Chris,
I'm running 1.0.1, since I've been doing most of my development from the Mac side of things, I'll be sure to do a diff of the related area to see what has changed though.


In my original question, I forgot to mention that the call to vb.lock doesn't succeed - hence the dMemcpy is trying to copy to 0x0. I had partial success with the addMesh: adding collision meshes with TSShapeConstructor to my LDraw models seemed to work fine, it was only when I tried to add them to each other and rig a skeleton that I had problems.

Is there a known restriction on the sort of meshes that can be used with TSShapeConstructor? My meshes do load+render more or less properly in game without the use of TSShapeConstructor.


[edit]

Thanks for the headsup about the crashing bug. I think that was it. I did some merges from the 1.1 and reran it without a crash (although my model still didn't appear since it looks like the material didn't get initialized properly...)