Hi, that makes one week that I try to animate tiny.x in a window without result using c#.

I looked on many forums and i just found pple who are in the same situation as me...The SimpleAnimation example in the directX SDK is helpless, I get an Direct3DXException when I try to insert the code wich handle what I need from the SimpleAnimation example.

i have an Exception somewhere here :

// Use ConvertToBlendedMesh to generate a drawable mesh

MeshData data = mesh.MeshData;

data.Mesh = mesh.SkinInformation.ConvertToIndexedBlendedMesh(data.Mesh, flags,

mesh.GetAdjacencyStream(), mesh.NumberPaletteEntries, out influences,

out bones);

and then if I click to continue here :

// Now load the mesh hierarchy

rootFrame = Mesh.LoadHierarchyFromFile("tiny.x", MeshFlags.Managed, device, alloc, null);

I think I get an Exception because I don't know what is

Microsoft.Samples.DirectX.UtilityToolkit and I don't know how does this work too.

I use the last DirectX SDK (February 2006) and Visual C# Express 2005.

Can you help me

(sorry for my english)

Re: Game Technologies: Graphics Mesh animation with directX (c#)

Jon Watte

It would be easier to answer your question if you told us:

1) which line is causing the exception
2) what are the values of the variables at that line (and before it)
3) what is the exact exception you're getting

Microsoft.Samples.DirectX.UtilityToolkit is the sample code toolkit, which ships as part of the DirectX SDK. The source code is also included as far as I recall, so you can read through it if you want to know what it does -- but none of the code you have posted actually seems to call it.

Re: Game Technologies: Graphics Mesh animation with directX (c#)


I got the same exception, probably, so...if you have replaced every call to the utility framework, then you've probably replaced this one too:

Caps caps = framework.GetCaps() (Or something like this. It's at the beginning of the GetSkinnedMesh function)

and you may have used some queer way of getting the Caps (maybe Managed.Adapters. ...)

Try using:


instead. It definitely worked for me.

P.S.: SimpleAnimation is nice. But to really learn something about 3D Animation! it totally sucks. Sorry, but it does. If I'd want to see an example of how the Utility-Pack is being used, I would've searched for a Utility-Use-Example. I want to know how to program a 3D Animation WITHOUT the Samples.Utility Package. I can't use it every single time I try to program a 3d environment now, can I

Also, it MUST be possible to program the same example without the package and without callback function. Even though callback functions are really nice, I'm just not at this level, yet. Sooooo....does anyone have an example without callbacks Or at least without the sample.utility

Because all I get ist either a very strange model (hard to explain)


An AccessViolationException when the program tries to Draw a Subset:

Line: _MeshContainer.MeshData.Mesh.DrawSubset(iAttrib);
in Method: DrawMeshContainer

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

Now...where do I corrupt the friggin' memory

Re: Game Technologies: Graphics Mesh animation with directX (c#)


thank you for your answer Wickermoon, but i posted this message a long time ago ^^.

I fixed it and I'm not using the Utility-Pack. You are right, it sucks.

Re: Game Technologies: Graphics Mesh animation with directX (c#)


Lol. I didn't look at the date ^^

But if you're not using the utility-pack, maybe you could help me

I really don't know why I get the problem and I need either someone how explains this to me, or someone who could give me a simple sample project, so that I may try to figure out what he's done. Maybe you could help me with that I would really appreciate it!

If you still have the source code of you non-utility-pack simpleanimation I'd be most grateful!

See ya :)

Re: Game Technologies: Graphics Mesh animation with directX (c#)


Just in case you might not get an email for a reply to your other post ;)

P.S.: Please help me ^^

Re: Game Technologies: Graphics Mesh animation with directX (c#)


I need your e-mail Wickermoon i will send you a project which can load an animated mesh like tiny.x but i didn't care about the caps, i did it for my computer. I hope your computer isn't too old.

Re: Game Technologies: Graphics Mesh animation with directX (c#)


Ah, sorry!

My email address is:

My PC isn't too old, I guess, but I just want to see how it works, anyway. So there shouldn't be any problems. In the worst case I just modify the caps ^^.

Thanks again for your help! :)

Re: Game Technologies: Graphics Mesh animation with directX (c#)


Hi,I met and solved your problems too.

It is the reason that this is must be some mistake in Texture rendering.

I think the problem is DirectX recyled the texture's memory .

When the 3d object rendering in multi-thread conidition, the memory has cleaned AUTOMATICLY,so this is a null pointer mistake.

My method is don't use MeshContainer to store your texture,just store your texture's name.

You must load the texture as your 3D object is need to initialised.JUST Look at my code.

private void DrawMeshContainer(MeshContainerDerived mesh, FrameDerived frame)
// Is there skin information
if (mesh.SkinInformation != null)

int attribIdPrev = -1;

// Draw
for (int iattrib = 0; iattrib < mesh.NumberAttributes; iattrib++)
int numBlend = 0;
BoneCombination[] bones = mesh.GetBones();
for (int i = 0; i < mesh.NumberInfluences; i++)
if (bones[iattrib].BoneIdIdea != -1)
numBlend = i;

if (device.DeviceCaps.MaxVertexBlendMatrices >= numBlend + 1)
// first calculate the world matrices for the current set of
// blend weights and get the accurate count of the number of
// blends
Matrix[] offsetMatrices = mesh.GetOffsetMatrices();
FrameDerived[] frameMatrices = mesh.GetFrames();
for (int i = 0; i < mesh.NumberInfluences; i++)
int matrixIndex = bones[iattrib].BoneIdIdea;
if (matrixIndex != -1)
Matrix tempMatrix = offsetMatrices[matrixIndex] *

device.Transform.SetWorldMatrixByIndex(i, tempMatrix);


device.RenderState.VertexBlend = (VertexBlend)numBlend;
// lookup the material used for this subset of faces
if ((attribIdPrev != bones[iattrib].AttributeId) ||
(attribIdPrev == -1))
//drawArgs.device.Material = meshMaterials[scriptedMachine.CurModel][j];
// drawArgs.device.SetTexture(0, meshTextures[scriptedMachine.CurModel][j]);
//device.Material = mesh.GetMaterials()[
// bones[iattrib].AttributeId].Material3D;
device.Material = mesh.GetMaterials()[

device.SetTexture(0, textures[bones[iattrib].AttributeId]);

//if you comment this line, It does works!so I find the way!

// device.SetTexture(0, mesh.GetTextures()[
// bones[iattrib].AttributeId]);

attribIdPrev = bones[iattrib].AttributeId;
catch (Exception ex) {

else // standard mesh, just draw it after setting material properties
device.Transform.World = frame.CombinedTransformationMatrix;

ExtendedMaterial[] mtrl = mesh.GetMaterials();
for (int iMaterial = 0; iMaterial < mtrl.Length; iMaterial++)
device.Material = mtrl[iMaterial].Material3D;
device.SetTexture(0, textures[iMaterial]);

public override void Initialize(DrawArgs drawArgs)

device = drawArgs.device;

// Initialize the stats font
statsFont = ResourceCache.GetGlobalInstance().CreateFont(device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,
Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch
, "Arial");

// Create our allocate hierarchy derived class
alloc = new AllocateHierarchyDerived(this);
textSprite = new Sprite(device);

// Load our file
string meshFile = (string)scriptedMachine.ModelList[0];
// Store the current folder, then switch to the folder where the media was found
MeshPath = meshFile;
rootFrame = Mesh.LoadHierarchyFromFile(meshFile, MeshFlags.Managed,
device, alloc, null);

// Calculate the center and radius of a bounding sphere
objectRadius = Frame.CalculateBoundingSphere(rootFrame.FrameHierarchy,
out objectCenter);

// Setup the matrices for animation

// Start the timer

// Create any textures
textures = new Texture[textureNames.Length];
for (int i = 0; i < this.textureNames.Length; i++)

if (textureNamesIdea != null)

texturesIdea = TextureLoader.FromFile(device,


Initialized = true;


public override MeshContainer CreateMeshContainer(string name, MeshData meshData, ExtendedMaterial[] materials, EffectInstance[] effectInstances, GraphicsStream adjacency, SkinInformation skinInfo)
// We only handle meshes here
if (meshData.Mesh == null)
throw new ArgumentException();

// We must have a vertex format mesh
if (meshData.Mesh.VertexFormat == VertexFormats.None)
throw new ArgumentException();

MeshContainerDerived mesh = new MeshContainerDerived();

mesh.Name = name;
int numFaces = meshData.Mesh.NumberFaces;
Device dev = meshData.Mesh.Device;

// Make sure there are normals
if ((meshData.Mesh.VertexFormat & VertexFormats.Normal) == 0)
// Clone the mesh
Mesh tempMesh = meshData.Mesh.Clone(meshData.Mesh.Options.Value,
meshData.Mesh.VertexFormat | VertexFormats.Normal, dev);

meshData.Mesh = tempMesh;

// Store the materials
Texture[] meshTextures = new Texture[materials.Length];
Material[] meshMaterials = new Material[materials.Length];
string[] textureNames = new string[materials.Length];
string xFilePath = Path.GetDirectoryName(app.MeshPath);

// Create any textures
for (int i = 0; i < materials.Length; i++)
meshMaterialsIdea = materialsIdea.Material3D;
// Set the ambient color for the material (D3DX does not do this)
meshMaterialsIdea.Ambient = meshMaterialsIdea.Diffuse;

if (materialsIdea.TextureFilename != null)
string textureFilePath = Path.Combine(xFilePath, materialsIdea.TextureFilename);
//meshTexturesIdea= ResourceCache.GetGlobalInstance().CreateTextureFromFile(
// dev, textureFilePath);
// meshTexturesIdea = TextureLoader.FromFile(dev,
// textureFilePath);
textureNamesIdea = textureFilePath;


// Animation.meshTextures = meshTextures;
// Animation.meshMaterials = meshMaterials;
mesh.MeshData = meshData;
app.TextureNames = textureNames;

// If there is skinning info, save any required data
if (skinInfo != null)
mesh.SkinInformation = skinInfo;
int numBones = skinInfo.NumberBones;
Matrix[] offsetMatrices = new Matrix[numBones];

for (int i = 0; i < numBones; i++)
offsetMatricesIdea = skinInfo.GetBoneOffsetMatrix(i);



return mesh;

Re: Game Technologies: Graphics Mesh animation with directX (c#)

The Real John Smith

Thank you! I was going crazy on this, trying to figure out where was the error... After 3 days i finally have that stupid Tiny walking on screen! WEEEEE! Only problem now is, FPS dropped from 60 to 3... -_- Does that take so many resources I guess optimization waits around the corner... T_T

Thanks again!

Re: Game Technologies: Graphics Mesh animation with directX (c#)


do you use the Device caps and indicated that must use hardware device

My app run well and my graphic card is Ati 1650GT. Fps is above 300.

Re: Game Technologies: Graphics Mesh animation with directX (c#)

The Real John Smith

hey, thanks, i solved this, i had screwed up an IF in the device initialization, so it switched to software device thinking the card wasnt able to handle skinning.