Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Honas

Member Since 18 Jan 2011
Offline Last Active May 17 2012 02:50 PM

Topics I've Started

Need help with the last drip of a memory leak

03 April 2012 - 10:26 AM

Hey everyone,
I recently adapted code for skinning meshes into my current project, which I took from a book on character animation. But I ran into memory leaks as soon as I tried to import my own character in my own project. The demo code from the book runs fine with my character without ever calling DestroyFrame or DestroyMeshContainer for the BoneHierarchyLoader, to my surprise.
I ran into 212 unfreed allocations and tried to clean it up, which, for example included creating a new function that actually traverses the hierarchy and deletes every bone.
I got it down to two unfreed locations and I cannot pinpoint them. I even used Evil Steve's memory leak checker.
http://www.gamedev.n...leak-checker-c/

My output (includes the checker output and D3DX output):
(Please notice that only BoneMesh and SkinnedMesh stuff is relevant.)

MEMORY  : High watermark was 2699428 bytes (2636KB, 2MB)
MEMORY  : Memory leaks detected!
47 active allocations totalling 1408 bytes:
+ ID 00000045, tag ID 0x00000000: 0x008A3E44 160 bytes [thegame.cpp:250 (InitTerrain)]
+ ID 00000393, tag ID 0x00000000: 0x008A427C 44 bytes [gameobject.cpp:459 (createCube)]
+ ID 00000394, tag ID 0x00000000: 0x008A7D44 16 bytes [gameobject.cpp:459 (createCube)]
+ ID 00000404, tag ID 0x00000000: 0x008A4564 8 bytes [??:0 (BoneMesh::BoneMesh)]
+ ID 00000405, tag ID 0x00000000: 0x008A464C 8 bytes [??:0 (BoneMesh::BoneMesh)]
+ ID 00000408, tag ID 0x00000000: 0x008A4854 20 bytes [skinnedmesh.cpp:111 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000409, tag ID 0x00000000: 0x008A4944 64 bytes [skinnedmesh.cpp:116 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000410, tag ID 0x00000000: 0x008A4A64 64 bytes [skinnedmesh.cpp:117 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000414, tag ID 0x00000000: 0x008A4DDC 8 bytes [??:0 (BoneMesh::BoneMesh)]
+ ID 00000415, tag ID 0x00000000: 0x09040244 8 bytes [??:0 (BoneMesh::BoneMesh)]
+ ID 00000418, tag ID 0x00000000: 0x0904052C 20 bytes [skinnedmesh.cpp:111 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000419, tag ID 0x00000000: 0x0904061C 64 bytes [skinnedmesh.cpp:116 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000420, tag ID 0x00000000: 0x0904073C 64 bytes [skinnedmesh.cpp:117 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000424, tag ID 0x00000000: 0x09040BF4 8 bytes [??:0 (BoneMesh::BoneMesh)]
+ ID 00000425, tag ID 0x00000000: 0x09040CDC 8 bytes [??:0 (BoneMesh::BoneMesh)]
+ ID 00000428, tag ID 0x00000000: 0x09040FC4 20 bytes [skinnedmesh.cpp:111 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000429, tag ID 0x00000000: 0x090410B4 64 bytes [skinnedmesh.cpp:116 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000430, tag ID 0x00000000: 0x090411D4 64 bytes [skinnedmesh.cpp:117 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000434, tag ID 0x00000000: 0x0904168C 8 bytes [??:0 (BoneMesh::BoneMesh)]
+ ID 00000435, tag ID 0x00000000: 0x09041774 8 bytes [??:0 (BoneMesh::BoneMesh)]
+ ID 00000438, tag ID 0x00000000: 0x09041A5C 20 bytes [skinnedmesh.cpp:111 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000439, tag ID 0x00000000: 0x09041B4C 64 bytes [skinnedmesh.cpp:116 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000440, tag ID 0x00000000: 0x09041C6C 64 bytes [skinnedmesh.cpp:117 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000444, tag ID 0x00000000: 0x09042124 8 bytes [??:0 (BoneMesh::BoneMesh)]
+ ID 00000445, tag ID 0x00000000: 0x0904220C 8 bytes [??:0 (BoneMesh::BoneMesh)]
+ ID 00000448, tag ID 0x00000000: 0x090424F4 20 bytes [skinnedmesh.cpp:111 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000449, tag ID 0x00000000: 0x090425E4 64 bytes [skinnedmesh.cpp:116 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000450, tag ID 0x00000000: 0x09042704 64 bytes [skinnedmesh.cpp:117 (BoneHierarchyLoader::CreateMeshContainer)]
+ ID 00000451, tag ID 0x00000000: 0x09042824 4 bytes [skinnedmesh.cpp:331 (SkinnedMesh::SetupBoneMatrixPointers)]
+ ID 00000452, tag ID 0x00000000: 0x09042904 4 bytes [skinnedmesh.cpp:331 (SkinnedMesh::SetupBoneMatrixPointers)]
+ ID 00000453, tag ID 0x00000000: 0x090429E4 4 bytes [skinnedmesh.cpp:331 (SkinnedMesh::SetupBoneMatrixPointers)]
+ ID 00000454, tag ID 0x00000000: 0x09042AC4 4 bytes [skinnedmesh.cpp:331 (SkinnedMesh::SetupBoneMatrixPointers)]
+ ID 00000455, tag ID 0x00000000: 0x09042BA4 4 bytes [skinnedmesh.cpp:331 (SkinnedMesh::SetupBoneMatrixPointers)]
+ ID 00000456, tag ID 0x00000000: 0x09042C84 4 bytes [gameobject.cpp:459 (createCube)]
+ ID 00000457, tag ID 0x00000000: 0x09042D64 32 bytes [gameobject.cpp:459 (createCube)]
+ ID 00000459, tag ID 0x00000000: 0x09042F44 44 bytes [gameobject.cpp:479 (createBase)]
+ ID 00000460, tag ID 0x00000000: 0x0904304C 12 bytes [gameobject.cpp:479 (createBase)]
+ ID 00000461, tag ID 0x00000000: 0x09043134 44 bytes [gameobject.cpp:363 (BaseGraphicsComponent::BaseGraphicsComponent)]
+ ID 00000462, tag ID 0x00000000: 0x0904323C 44 bytes [gameobject.cpp:372 (BaseGraphicsComponent::BaseGraphicsComponent)]
+ ID 00000463, tag ID 0x00000000: 0x09043344 4 bytes [gameobject.cpp:479 (createBase)]
+ ID 00000464, tag ID 0x00000000: 0x09043424 8 bytes [gameobject.cpp:479 (createBase)]
+ ID 00000466, tag ID 0x00000000: 0x090435F4 44 bytes [gameobject.cpp:479 (createBase)]
+ ID 00000467, tag ID 0x00000000: 0x090436FC 12 bytes [gameobject.cpp:479 (createBase)]
+ ID 00000468, tag ID 0x00000000: 0x090437E4 44 bytes [gameobject.cpp:363 (BaseGraphicsComponent::BaseGraphicsComponent)]
+ ID 00000469, tag ID 0x00000000: 0x090438EC 44 bytes [gameobject.cpp:372 (BaseGraphicsComponent::BaseGraphicsComponent)]
+ ID 00000470, tag ID 0x00000000: 0x09042E64 4 bytes [gameobject.cpp:479 (createBase)]
+ ID 00000471, tag ID 0x00000000: 0x090439F4 8 bytes [gameobject.cpp:479 (createBase)]
End of allocations
Memory leaks were foundTheGame (Debug) .exe has triggered a breakpoint
The thread 'Win32 Thread' (0x1140) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x418) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x16c8) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xb8c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1028) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x148c) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x13f0) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1144) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1280) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1500) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x1080) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x172c) has exited with code 0 (0x0).
Direct3D9: (ERROR) :Memory still allocated!  Alloc count = 185
Direct3D9: (ERROR) :Current Process (pid) = 0000155c
Direct3D9: (ERROR) :Memory Address: 056707fc lAllocID=1 dwSize=00004bc4, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 056753f4 lAllocID=2 dwSize=00000350, ReturnAddr=6b6f02fa (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567577c lAllocID=3 dwSize=00000ef0, ReturnAddr=6b6f6401 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b3434c lAllocID=5 dwSize=000242b4, ReturnAddr=6b6fe508 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b58634 lAllocID=6 dwSize=00001bd8, ReturnAddr=6b6eec04 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 056766a4 lAllocID=7 dwSize=000005e0, ReturnAddr=6b6eecd5 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05676cbc lAllocID=8 dwSize=00000014, ReturnAddr=6b6eed27 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b10064 lAllocID=12 dwSize=00001950, ReturnAddr=6b6e3cab (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b5a244 lAllocID=13 dwSize=000005e0, ReturnAddr=6b6e3cf1 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05676dc4 lAllocID=14 dwSize=00000014, ReturnAddr=6b6e3d3e (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b5a85c lAllocID=15 dwSize=00000350, ReturnAddr=6b6f02fa (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b119ec lAllocID=16 dwSize=00000ef0, ReturnAddr=6b6f6401 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b5abe4 lAllocID=18 dwSize=0001bd28, ReturnAddr=6b6fe508 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b12914 lAllocID=19 dwSize=00001bd8, ReturnAddr=6b6eec04 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b76944 lAllocID=20 dwSize=000005c0, ReturnAddr=6b6eecd5 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b76f3c lAllocID=21 dwSize=00000014, ReturnAddr=6b6eed27 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b14524 lAllocID=23 dwSize=00001950, ReturnAddr=6b6e3cab (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b15eac lAllocID=24 dwSize=000005c0, ReturnAddr=6b6e3cf1 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b76f84 lAllocID=25 dwSize=00000014, ReturnAddr=6b6e3d3e (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05676e0c lAllocID=26 dwSize=00000044, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05676e84 lAllocID=27 dwSize=00000050, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1682c lAllocID=35 dwSize=00000ef0, ReturnAddr=6b6f6401 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05676f0c lAllocID=36 dwSize=00000030, ReturnAddr=6b700881 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b17754 lAllocID=37 dwSize=00001bd8, ReturnAddr=6b6eec04 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b19364 lAllocID=38 dwSize=000005e0, ReturnAddr=6b6eecd5 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05676f74 lAllocID=39 dwSize=00000014, ReturnAddr=6b6eed27 (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1997c lAllocID=41 dwSize=00004138, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1daec lAllocID=42 dwSize=00000198, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b164a4 lAllocID=43 dwSize=00000030, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1dcbc lAllocID=44 dwSize=00001020, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1ed14 lAllocID=45 dwSize=00000a48, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1650c lAllocID=46 dwSize=00000098, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b165dc lAllocID=47 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1668c lAllocID=48 dwSize=00000024, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b166e4 lAllocID=49 dwSize=00000098, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1f794 lAllocID=50 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b167b4 lAllocID=51 dwSize=00000044, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1f844 lAllocID=52 dwSize=00000024, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1f89c lAllocID=53 dwSize=000000a8, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1f97c lAllocID=54 dwSize=00000098, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1fa4c lAllocID=55 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b76fcc lAllocID=56 dwSize=0002b330, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2334 lAllocID=57 dwSize=0000002c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2394 lAllocID=58 dwSize=00000028, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba23f4 lAllocID=59 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba284c lAllocID=60 dwSize=00000030, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba28b4 lAllocID=61 dwSize=00000030, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b1fafc lAllocID=62 dwSize=00001020, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba291c lAllocID=63 dwSize=00000120, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2a74 lAllocID=64 dwSize=00000060, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b20b54 lAllocID=65 dwSize=00000e20, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2b0c lAllocID=66 dwSize=00000120, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2c64 lAllocID=67 dwSize=00000060, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b219ac lAllocID=68 dwSize=000003ec, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2cfc lAllocID=69 dwSize=00000050, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2d84 lAllocID=70 dwSize=00000050, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2e0c lAllocID=71 dwSize=00000050, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2e94 lAllocID=72 dwSize=00000050, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2f1c lAllocID=73 dwSize=00000048, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b21dcc lAllocID=74 dwSize=00000054, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b21e54 lAllocID=75 dwSize=00000048, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b21ed4 lAllocID=78 dwSize=000000b8, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b21fc4 lAllocID=79 dwSize=00010020, ReturnAddr=6b6ed65a (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b3201c lAllocID=80 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b320cc lAllocID=81 dwSize=000000c0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b321c4 lAllocID=82 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b32274 lAllocID=83 dwSize=000000c0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b3236c lAllocID=84 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b3241c lAllocID=85 dwSize=000000b0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b32504 lAllocID=86 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b325b4 lAllocID=87 dwSize=00000050, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba2f9c lAllocID=88 dwSize=0000002c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b3263c lAllocID=89 dwSize=00000028, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b3269c lAllocID=90 dwSize=0000002c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05676fbc lAllocID=91 dwSize=0000517c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b326fc lAllocID=92 dwSize=00001020, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b33754 lAllocID=93 dwSize=0000003c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba3004 lAllocID=94 dwSize=00004020, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b337c4 lAllocID=95 dwSize=0000003c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567c16c lAllocID=96 dwSize=0000183c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05ba705c lAllocID=97 dwSize=0000fab8, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b33834 lAllocID=98 dwSize=00000068, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b338d4 lAllocID=99 dwSize=00000140, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b33a4c lAllocID=100 dwSize=0000003c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bb6b4c lAllocID=101 dwSize=00004020, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b33abc lAllocID=102 dwSize=0000003c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbaba4 lAllocID=103 dwSize=0000183c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b33b2c lAllocID=104 dwSize=0000021c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b33d7c lAllocID=105 dwSize=00000224, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b33fd4 lAllocID=106 dwSize=0000003c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b34044 lAllocID=107 dwSize=00000060, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b341ac lAllocID=109 dwSize=00000050, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b34234 lAllocID=110 dwSize=00000038, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbc414 lAllocID=111 dwSize=00000080, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b342a4 lAllocID=112 dwSize=0000002c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbc4cc lAllocID=113 dwSize=00000040, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbc544 lAllocID=114 dwSize=00000040, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbc5bc lAllocID=115 dwSize=00000040, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbc634 lAllocID=116 dwSize=00000060, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbc6cc lAllocID=117 dwSize=00000030, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567d9dc lAllocID=118 dwSize=00000b38, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567e54c lAllocID=119 dwSize=00001020, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbc734 lAllocID=120 dwSize=00000120, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbc88c lAllocID=121 dwSize=00000060, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbc924 lAllocID=122 dwSize=00001020, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567f5a4 lAllocID=123 dwSize=00000120, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567f6fc lAllocID=124 dwSize=00000060, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567f794 lAllocID=125 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567fbec lAllocID=126 dwSize=000000e4, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567fd04 lAllocID=127 dwSize=00000028, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bbd97c lAllocID=128 dwSize=000053c0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bc2d74 lAllocID=129 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bc31cc lAllocID=130 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567fd64 lAllocID=131 dwSize=000001a0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0567ff3c lAllocID=133 dwSize=00000040, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bc8d24 lAllocID=549 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bc917c lAllocID=550 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bc9954 lAllocID=553 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bc9f04 lAllocID=557 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bca35c lAllocID=558 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bcb06c lAllocID=592 dwSize=00000054, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bcb5f4 lAllocID=593 dwSize=00000080, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05c0c8fc lAllocID=628 dwSize=00000114, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05c0ca44 lAllocID=629 dwSize=000003e4, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b340dc lAllocID=630 dwSize=0000003c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05c0ce5c lAllocID=631 dwSize=00000048, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05b3414c lAllocID=632 dwSize=00000028, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05c0c60c lAllocID=633 dwSize=00000028, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05c0cedc lAllocID=634 dwSize=0000003c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05c0cf4c lAllocID=635 dwSize=00000028, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bca964 lAllocID=643 dwSize=00000028, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05c0c45c lAllocID=651 dwSize=00000090, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05bc9864 lAllocID=655 dwSize=000000a0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05c0d46c lAllocID=659 dwSize=00000054, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 05c0d4f4 lAllocID=660 dwSize=00000080, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0addcb34 lAllocID=2383 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0addcf8c lAllocID=2384 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0adde96c lAllocID=2462 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0addedc4 lAllocID=2463 dwSize=00000420, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6345c lAllocID=3182 dwSize=000000b8, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6354c lAllocID=3183 dwSize=000000a0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63624 lAllocID=3184 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae636d4 lAllocID=3185 dwSize=0000005c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63764 lAllocID=3186 dwSize=00000044, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae637dc lAllocID=3187 dwSize=00000024, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63834 lAllocID=3188 dwSize=00000112, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6397c lAllocID=3191 dwSize=000000a8, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63a5c lAllocID=3192 dwSize=00000068, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63afc lAllocID=3193 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63bac lAllocID=3194 dwSize=00000060, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63c44 lAllocID=3195 dwSize=00000044, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63cbc lAllocID=3196 dwSize=00000024, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63d14 lAllocID=3197 dwSize=00000112, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63e5c lAllocID=3200 dwSize=000000b8, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae63f4c lAllocID=3201 dwSize=000000a0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae64024 lAllocID=3202 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae640d4 lAllocID=3203 dwSize=0000005c, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae64164 lAllocID=3204 dwSize=00000044, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae641dc lAllocID=3205 dwSize=00000024, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae64234 lAllocID=3206 dwSize=00000112, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6437c lAllocID=3209 dwSize=000000a8, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6445c lAllocID=3210 dwSize=00000068, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae644fc lAllocID=3211 dwSize=0000007c, ReturnAddr=6b70a22b (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae645ac lAllocID=3212 dwSize=00000060, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae64644 lAllocID=3213 dwSize=00000044, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae646bc lAllocID=3214 dwSize=00000024, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae64714 lAllocID=3215 dwSize=00000112, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0adde3dc lAllocID=3216 dwSize=00000010, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6485c lAllocID=3217 dwSize=000001a0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae64a34 lAllocID=3219 dwSize=00000038, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae69144 lAllocID=3343 dwSize=00000054, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae691cc lAllocID=3344 dwSize=00000080, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae699d4 lAllocID=3363 dwSize=00000028, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae69284 lAllocID=3373 dwSize=00000044, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6a1a4 lAllocID=3383 dwSize=00000084, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae69574 lAllocID=3387 dwSize=000001e0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6a48c lAllocID=3391 dwSize=000001e0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6e4b4 lAllocID=3501 dwSize=000001a0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6e68c lAllocID=3503 dwSize=00000038, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6e6fc lAllocID=3504 dwSize=00000054, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6e784 lAllocID=3505 dwSize=00000080, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6e83c lAllocID=3506 dwSize=000001a0, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6ea14 lAllocID=3508 dwSize=00000040, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6ed04 lAllocID=3513 dwSize=00000080, ReturnAddr=6b6ed5ea (pid=0000155c)
Direct3D9: (ERROR) :Memory Address: 0ae6edbc lAllocID=3514 dwSize=0000007c, ReturnAddr=6b70b592 (pid=0000155c)
Direct3D9: (ERROR) :Total Memory Unfreed From Current Process = 810080 bytes
D3DX: MEMORY LEAKS DETECTED: 2 allocations unfreed (182 bytes)
D3DX: Set HKLM\Software\Microsoft\Direct3D\D3DXBreakOnAllocId=0x10b4 to debug
The program '[5468] TheGame (Debug) .exe: Native' has exited with code 0 (0x0).


SkinnedMesh.h
#ifndef SKINNED_MESH_H
#define SKINNED_MESH_H
#include <windows.h>
#include <d3dx9.h>
#include <string>
#include <vector>
#include "TriBase.h"
class Camera;
class BoneHierarchyLoader;
using namespace std;

struct Bone: public D3DXFRAME
{
	D3DXMATRIX CombinedTransformationMatrix;
};

struct BoneMesh: public D3DXMESHCONTAINER
{
ID3DXMesh* OriginalMesh;
vector<D3DMATERIAL9> materials;
vector<IDirect3DTexture9*> textures;
DWORD NumAttributeGroups;
D3DXATTRIBUTERANGE* attributeTable;
D3DXMATRIX** boneMatrixPtrs;
D3DXMATRIX* boneOffsetMatrices;
D3DXMATRIX* currentBoneMatrices;
};

class SkinnedMesh
{
public:
  SkinnedMesh();
  ~SkinnedMesh();
  void Load(char fileName[]);
  void Render(Bone *bone);
  void RenderStart(Bone *bone, Camera & cam, D3DXMATRIX world);
  void SetPose(D3DXMATRIX world, float time);
  void SetAnimation(string name);
  void GetAnimations(vector<string> &animations);
  ID3DXAnimationController* GetController();
private:
  void UpdateMatrices(Bone* bone, D3DXMATRIX *parentMatrix);
  void SetupBoneMatrixPointers(Bone *bone);
  void Destroy(LPD3DXFRAME bone, BoneHierarchyLoader& bh);
  D3DXFRAME *m_pRootBone;
  ID3DXAnimationController *m_pAnimControl;
  ID3DXEffect*  m_pEffect;
};
#endif SKINNED_MESH_H


SkinnedMesh.cpp
#include "skinnedMesh.h"
#include <fstream>
#include "Camera.h"
#pragma warning(disable:4996)
//extern IDirect3DDevice9* g_pDevice;
//extern ID3DXEffect *g_pEffect;
//extern ofstream g_debug;

class BoneHierarchyLoader: public ID3DXAllocateHierarchy
{
public:
	   STDMETHOD(CreateFrame)(THIS_ LPCSTR Name, LPD3DXFRAME *ppNewFrame);
	   STDMETHOD(CreateMeshContainer)(THIS_ LPCTSTR Name, CONST D3DXMESHDATA * pMeshData, CONST D3DXMATERIAL * pMaterials, CONST D3DXEFFECTINSTANCE * pEffectInstances, DWORD NumMaterials, CONST DWORD * pAdjacency, LPD3DXSKININFO pSkinInfo, LPD3DXMESHCONTAINER * ppNewMeshContainer);
	   STDMETHOD(DestroyFrame)(THIS_ LPD3DXFRAME pFrameToFree);
	   STDMETHOD(DestroyMeshContainer)(THIS_ LPD3DXMESHCONTAINER pMeshContainerBase);
};

HRESULT BoneHierarchyLoader::CreateFrame(LPCSTR Name, LPD3DXFRAME *ppNewFrame)
{
	 Bone *newBone = new Bone;
	 memset(newBone, 0, sizeof(Bone));

	 //Copy name
	 if(Name != NULL)
	 {
	   	 newBone->Name = new char[strlen(Name)+1];
	   	 strcpy(newBone->Name, Name);
	 }
	 //Set the transformation matrices
	 D3DXMatrixIdentity(&newBone->TransformationMatrix);
	 D3DXMatrixIdentity(&newBone->CombinedTransformationMatrix);
	 //Return the new bone...
	 *ppNewFrame = (D3DXFRAME*)newBone;
	
	 return S_OK;
}

HRESULT BoneHierarchyLoader::CreateMeshContainer(LPCSTR Name,
		   CONST D3DXMESHDATA *pMeshData,
		   CONST D3DXMATERIAL *pMaterials,
		   CONST D3DXEFFECTINSTANCE *pEffectInstances,
		   DWORD NumMaterials,
		   CONST DWORD *pAdjacency,
		   LPD3DXSKININFO pSkinInfo,
		   LPD3DXMESHCONTAINER *ppNewMeshContainer)
{
	 //Create new Bone Mesh
	 BoneMesh *boneMesh = new BoneMesh;
	 memset(boneMesh, 0, sizeof(BoneMesh));
	
	 //Get mesh data
	 boneMesh->OriginalMesh = pMeshData->pMesh;
	 boneMesh->MeshData.pMesh = pMeshData->pMesh;
	 boneMesh->MeshData.Type = pMeshData->Type;
	 pMeshData->pMesh->AddRef();  //Add Reference so that the mesh isnt deallocated
	 IDirect3DDevice9 *g_pDevice = NULL;
	 pMeshData->pMesh->GetDevice(&g_pDevice); //Get g_pDevice ptr from mesh
	 //Copy materials and load textures (just like with a static mesh)
	 for(int i=0;i<(int)NumMaterials;i++)
	 {
	   	 D3DXMATERIAL mtrl;
	   	 memcpy(&mtrl, &pMaterials[i], sizeof(D3DXMATERIAL));
			boneMesh->materials.push_back(mtrl.MatD3D);
	   	 IDirect3DTexture9* newTexture = NULL;
	   	 if(mtrl.pTextureFilename != NULL)
	   	 {
   	 	 	 char textureFname[200];
   	 	 	 strcpy(textureFname, "_GRAPHICS/");
   			   strcat(textureFname, mtrl.pTextureFilename);
			 	 //Load texture
			 	 D3DXCreateTextureFromFile(g_pDevice, textureFname, &newTexture);
	   	 }
	   	 boneMesh->textures.push_back(newTexture);
	 }
	 if(pSkinInfo != NULL)
	 {
	   	 //Get Skin Info
			boneMesh->pSkinInfo = pSkinInfo;
			pSkinInfo->AddRef(); //Add reference so that the SkinInfo isnt deallocated

			DWORD maxVertInfluences = 0;
			DWORD numBoneComboEntries = 0;
			ID3DXBuffer* boneComboTable = 0;
			pSkinInfo->ConvertToIndexedBlendedMesh(pMeshData->pMesh,
			D3DXMESH_MANAGED | D3DXMESH_WRITEONLY,
			30,
			0, // ignore adjacency in
			0, // ignore adjacency out
			0, // ignore face remap
			0, // ignore vertex remap
			&maxVertInfluences,
			&numBoneComboEntries,
			&boneComboTable,
			&boneMesh->MeshData.pMesh);

	   if(boneComboTable != NULL)
		boneComboTable->Release();

	   //Get Attribute Table
	   boneMesh->MeshData.pMesh->GetAttributeTable(NULL, &boneMesh->NumAttributeGroups); ################actual line 111#########
	   boneMesh->attributeTable = new D3DXATTRIBUTERANGE[boneMesh->NumAttributeGroups];
	   boneMesh->MeshData.pMesh->GetAttributeTable(boneMesh->attributeTable, NULL);

	   //Create bone offset and current matrices
	   int NumBones = pSkinInfo->GetNumBones();
	  boneMesh->boneOffsetMatrices = new D3DXMATRIX[NumBones]; ###########116###########
	   boneMesh->currentBoneMatrices = new D3DXMATRIX[NumBones]; #########117############

	   //Get bone offset matrices
	   for(int i=0;i < NumBones;i++)
		boneMesh->boneOffsetMatrices[i] = *(boneMesh->pSkinInfo->GetBoneOffsetMatrix(i));
	 }
	 //Set ppNewMeshContainer to the newly created boneMesh container
	 *ppNewMeshContainer = boneMesh;
	
	 return S_OK;
}

HRESULT BoneHierarchyLoader::DestroyFrame(LPD3DXFRAME pFrameToFree)
{
	 if(pFrameToFree)
	 {
	   	 //Free name
	   	 if(pFrameToFree->Name != NULL)
			 delete [] pFrameToFree->Name;
			//Free bone
			delete pFrameToFree;
	 }
	 pFrameToFree = NULL;
		return S_OK;
}

HRESULT BoneHierarchyLoader::DestroyMeshContainer(LPD3DXMESHCONTAINER pMeshContainerBase)
{
	 BoneMesh *boneMesh = (BoneMesh*)pMeshContainerBase;
	 //Release textures
	 int numTextures = (int)boneMesh->textures.size();
	 for(int i=0;i < numTextures;i++)
			if(boneMesh->textures[i] != NULL)
				  boneMesh->textures[i]->Release();
	 //Release mesh data
	 if(boneMesh->MeshData.pMesh) boneMesh->MeshData.pMesh->Release();
	 if(boneMesh->pSkinInfo) boneMesh->pSkinInfo->Release();
	 if(boneMesh->OriginalMesh) boneMesh->OriginalMesh->Release();
	 delete boneMesh;
	return S_OK;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
//		 SKINNED MESH			//
//////////////////////////////////////////////////////////////////////////////////////////////////
struct VERTEX{
	 VERTEX();
	 VERTEX(D3DXVECTOR3 pos, D3DCOLOR col){position = pos; color = col;}
	 D3DXVECTOR3 position;
	 D3DCOLOR color;
	 static const DWORD FVF;
};
const DWORD VERTEX::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;

SkinnedMesh::SkinnedMesh()
{
	 m_pRootBone = NULL;
	 m_pAnimControl = NULL;
	 m_pEffect = NULL;
}

SkinnedMesh::~SkinnedMesh()
{
	 BoneHierarchyLoader boneHierarchy;
	 Destroy(m_pRootBone, boneHierarchy);
	 if(m_pAnimControl) m_pAnimControl->Release();
	 m_pEffect->Release();
}

void SkinnedMesh::Load(char fileName[])
{
	 BoneHierarchyLoader boneHierarchy;
	 D3DXLoadMeshHierarchyFromX(fileName, D3DXMESH_MANAGED,
	   tbDirect3D::Instance().GetDevice(), &boneHierarchy,
		  NULL, &m_pRootBone, &m_pAnimControl);
	 SetupBoneMatrixPointers((Bone*)m_pRootBone);
	
	 //Update all the bones
	 D3DXMATRIX i;
	 D3DXMatrixIdentity(&i);
	 UpdateMatrices((Bone*)m_pRootBone, &i);
	 //Set up the effect
	 ID3DXBuffer *pErrorMsgs = NULL;
	 HRESULT hRes = D3DXCreateEffectFromFile(tbDirect3D::Instance().GetDevice(), "_GRAPHICS/lighting.fx", NULL, NULL, D3DXSHADER_DEBUG, NULL, &m_pEffect, &pErrorMsgs);
	 if(FAILED(hRes) && (pErrorMsgs != NULL))  //Failed to create Effect
	 {
			tbWriteToLog( (char*)pErrorMsgs->GetBufferPointer());
			MessageBox(tbDirect3D::Instance().GetWindow(), "Fehler beim Erstellen eines .fx!",
		  "Fehler", MB_OK | MB_ICONEXCLAMATION);
	 }
}

void SkinnedMesh::UpdateMatrices(Bone* bone, D3DXMATRIX *parentMatrix)
{
	 if(bone == NULL)return;
	 D3DXMatrixMultiply(&bone->CombinedTransformationMatrix,
		&bone->TransformationMatrix,
		parentMatrix);
	 if(bone->pFrameSibling)UpdateMatrices((Bone*)bone->pFrameSibling, parentMatrix);
	 if(bone->pFrameFirstChild)UpdateMatrices((Bone*)bone->pFrameFirstChild, &bone->CombinedTransformationMatrix);
}

void SkinnedMesh::Render(Bone *bone)
{
	 if(bone == NULL)bone = (Bone*)m_pRootBone;
	 //If there is a mesh to render...
	 if(bone->pMeshContainer != NULL)
	 {
	   BoneMesh *boneMesh = (BoneMesh*)bone->pMeshContainer;
	   if (boneMesh->pSkinInfo != NULL)
			{
				  // set up bone transforms
				  int numBones = boneMesh->pSkinInfo->GetNumBones();
				  for(int i=0;i < numBones;i++)
   	 	 	 {
						D3DXMatrixMultiply(&boneMesh->currentBoneMatrices[i],
		   &boneMesh->boneOffsetMatrices[i],
			  boneMesh->boneMatrixPtrs[i]);
   	 	 	 }
				  D3DXMATRIX view, proj, identity;  
				  m_pEffect->SetMatrixArray("FinalTransforms", boneMesh->currentBoneMatrices, boneMesh->pSkinInfo->GetNumBones());
				  D3DXMatrixIdentity(&identity);
				  //Render the mesh
				  for(int i=0;i < (int)boneMesh->NumAttributeGroups;i++)
				 {
						int mtrlIndex = boneMesh->attributeTable[i].AttribId;
						tbDirect3D::Instance().GetDevice()->SetMaterial(&(boneMesh->materials[mtrlIndex]));
						tbDirect3D::Instance().GetDevice()->SetTexture(0, boneMesh->textures[mtrlIndex]);
						//m_pEffect->SetMatrix("matW", &identity);
						m_pEffect->SetTexture("texDiffuse", boneMesh->textures[mtrlIndex]);
						D3DXHANDLE hTech = m_pEffect->GetTechniqueByName("Skinning");
						m_pEffect->SetTechnique(hTech);
						m_pEffect->Begin(NULL, NULL);
						m_pEffect->BeginPass(0);
						boneMesh->MeshData.pMesh->DrawSubset(mtrlIndex);
						m_pEffect->EndPass();
						m_pEffect->End();
				  }
			}
	   else
	   {
				  //Normal Static Mesh
			 m_pEffect->SetMatrix("matW", &bone->CombinedTransformationMatrix);
			 D3DXHANDLE hTech = m_pEffect->GetTechniqueByName("Lighting");
			 m_pEffect->SetTechnique(hTech);
			 //Render the mesh
			 int numMaterials = (int)boneMesh->materials.size();
			 for(int i=0;i < numMaterials;i++)
				  {
				   tbDirect3D::Instance().GetDevice()->SetMaterial(&boneMesh->materials[i]);
				   m_pEffect->SetTexture("texDiffuse", boneMesh->textures[i]);
				   m_pEffect->Begin(NULL, NULL);
				   m_pEffect->BeginPass(0);
				   boneMesh->OriginalMesh->DrawSubset(i);
				   m_pEffect->EndPass();
				   m_pEffect->End();
				  }
	   }
	 }
	 if(bone->pFrameSibling != NULL)Render((Bone*)bone->pFrameSibling);
	 if(bone->pFrameFirstChild != NULL)Render((Bone*)bone->pFrameFirstChild);
}

void SkinnedMesh::RenderStart(Bone *bone, Camera & cam, D3DXMATRIX world)
{
	 tbDirect3D& D3D = tbDirect3D::Instance();
	 D3DXVECTOR4 lightPos(10.0f, 120.0f, 0.0f, 0.0f);
	 m_pEffect->SetMatrix("matW", &world);
	 m_pEffect->SetMatrix("matVP", &(cam.view()*cam.proj()));
	 m_pEffect->SetVector("lightPos", &lightPos);
	 Render(bone);
}

void SkinnedMesh::SetupBoneMatrixPointers(Bone *bone)
{
	 if(bone->pMeshContainer != NULL)
	   {
	   	 BoneMesh *boneMesh = (BoneMesh*)bone->pMeshContainer;
			if(boneMesh->pSkinInfo != NULL)
			{
				  int NumBones = boneMesh->pSkinInfo->GetNumBones();
				  boneMesh->boneMatrixPtrs = new D3DXMATRIX*[NumBones]; ############actual line 331##############
				  for(int i=0;i < NumBones;i++)
				  {
						Bone *b = (Bone*)D3DXFrameFind(m_pRootBone, boneMesh->pSkinInfo->GetBoneName(i));
						if(b != NULL)boneMesh->boneMatrixPtrs[i] = &b->CombinedTransformationMatrix;
		 	 	 	 else boneMesh->boneMatrixPtrs[i] = NULL;
				 }
	   	 }
	 }

	 if(bone->pFrameSibling != NULL)SetupBoneMatrixPointers((Bone*)bone->pFrameSibling);
	 if(bone->pFrameFirstChild != NULL)SetupBoneMatrixPointers((Bone*)bone->pFrameFirstChild);
}

void SkinnedMesh::SetPose(D3DXMATRIX world, float time)
{
	 m_pAnimControl->AdvanceTime(time, NULL);
	 UpdateMatrices((Bone*)m_pRootBone, &world);
}

void SkinnedMesh::SetAnimation(string name)
{
	 ID3DXAnimationSet *anim = NULL;
	 int numAnims = (int)m_pAnimControl->GetMaxNumAnimationSets();
	 for(int i=0;i<numAnims;i++)
	 {
			anim = NULL;
			m_pAnimControl->GetAnimationSet(i, &anim);
			if(anim != NULL)
			{
				  if(strcmp(name.c_str(), anim->GetName()) == 0)
				   m_pAnimControl->SetTrackAnimationSet(0, anim);
				  anim->Release();
			}
	 }
}

void SkinnedMesh::GetAnimations(vector<string> &animations)
{
	 ID3DXAnimationSet *anim = NULL;
	 for(int i=0;i<(int)m_pAnimControl->GetMaxNumAnimationSets();i++)
	 {
	   	 anim = NULL;
	   	 m_pAnimControl->GetAnimationSet(i, &anim);
	   	 if(anim != NULL)
			{
   	 	 	 animations.push_back(anim->GetName());
   	 	 	 anim->Release();
	   }
	 }
}

ID3DXAnimationController* SkinnedMesh::GetController()
{
	 ID3DXAnimationController* newAnimController = NULL;
	 if(m_pAnimControl != NULL)
	 {
			m_pAnimControl->CloneAnimationController(m_pAnimControl->GetMaxNumAnimationOutputs(),
			 m_pAnimControl->GetMaxNumAnimationSets(),
			 m_pAnimControl->GetMaxNumTracks(),
			 m_pAnimControl->GetMaxNumEvents(),
			 &newAnimController);
	 }
	 return newAnimController;
}

void SkinnedMesh::Destroy(LPD3DXFRAME bone, BoneHierarchyLoader& bh)
{
	 if((BoneMesh *) bone->pMeshContainer != NULL)
	 {
			bh.DestroyMeshContainer(bone->pMeshContainer);
	 }
	 if(bone->pFrameSibling != NULL) Destroy(bone->pFrameSibling, bh);
	 if(bone->pFrameFirstChild != NULL) Destroy(bone->pFrameFirstChild, bh);
	 bh.DestroyFrame(bone);
}


I've marked some of the code lines from the checker output.

Any ideas what I forgot?

Problem with forward declarations and #includes

21 March 2012 - 07:15 AM

---------SOLVED-----------
Include the headers in your .cpp when you forward declare! Posted Image

Hello gamdev,
I am working on a 3D game and I want to give my camera object now a reference to my player (a GameObject) instead of only a 3D vector - which I used to direct my camera at the player's position- so that it can change the orientation of the player. All my headers have inclusion guards and the according source files only include the header. But now I get weird errors when I include "Camera.h":

1>------ Build started: Project: TheGame, Configuration: Debug Win32 ------
1>  Camera.cpp
1>c:\users\jonas\desktop\thegame\terrain.h(19): error C2143: syntax error : missing ';' before '*'
1>c:\users\jonas\desktop\thegame\terrain.h(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jonas\desktop\thegame\terrain.h(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jonas\desktop\thegame\terrain.h(32): error C2061: syntax error : identifier 'Camera'
1>c:\users\jonas\desktop\thegame\terrain.h(52): error C2061: syntax error : identifier 'Camera'
1>c:\users\jonas\desktop\thegame\terrain.h(55): error C2061: syntax error : identifier 'Camera'
1>c:\users\jonas\desktop\thegame\terrain.h(56): error C2061: syntax error : identifier 'Camera'
1>  Terrain.cpp
1>c:\users\jonas\desktop\thegame\gameobject.h(22): error C2061: syntax error : identifier 'Terrain'
1>c:\users\jonas\desktop\thegame\gameobject.h(63): error C2061: syntax error : identifier 'Terrain'
1>c:\users\jonas\desktop\thegame\gameobject.h(65): error C2065: 'terrain' : undeclared identifier
1>  TheGame.cpp
1>c:\users\jonas\desktop\thegame\terrain.h(19): error C2143: syntax error : missing ';' before '*'
1>c:\users\jonas\desktop\thegame\terrain.h(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jonas\desktop\thegame\terrain.h(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jonas\desktop\thegame\terrain.h(32): error C2061: syntax error : identifier 'Camera'
1>c:\users\jonas\desktop\thegame\terrain.h(52): error C2061: syntax error : identifier 'Camera'
1>c:\users\jonas\desktop\thegame\terrain.h(55): error C2061: syntax error : identifier 'Camera'
1>c:\users\jonas\desktop\thegame\terrain.h(56): error C2061: syntax error : identifier 'Camera'
1>c:\users\jonas\desktop\thegame\thegame.cpp(111): error C2660: 'Terrain::draw' : function does not take 3 arguments
1>c:\users\jonas\desktop\thegame\thegame.cpp(249): error C2661: 'Terrain::Terrain' : no overloaded function takes 12 arguments
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

According to this link: http://www.cplusplus...articles/10627/ I don't really need to be that drastic so I tried a forward declaration:

1>------ Build started: Project: TheGame, Configuration: Debug Win32 ------
1>  Camera.cpp
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2027: use of undefined type 'GameObject'
1>		  c:\users\jonas\desktop\thegame\camera.h(4) : see declaration of 'GameObject'
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.Position' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.x' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2027: use of undefined type 'GameObject'
1>		  c:\users\jonas\desktop\thegame\camera.h(4) : see declaration of 'GameObject'
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.Position' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.y' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2027: use of undefined type 'GameObject'
1>		  c:\users\jonas\desktop\thegame\camera.h(4) : see declaration of 'GameObject'
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.Position' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.z' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(218): error C2027: use of undefined type 'GameObject'
1>		  c:\users\jonas\desktop\thegame\camera.h(4) : see declaration of 'GameObject'
1>c:\users\jonas\desktop\thegame\camera.cpp(218): error C2228: left of '.Position' must have class/struct/union
1>  GameObject.cpp
1>  Terrain.cpp
1>  TheGame.cpp
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Why is it undefined?

So in my first approach my Camera.h includes GameObject.h because of a reference to a GameObject object as a function parameter (too drastic). In GameObject.h I include Terrain.h because of pointer to a Terrain object as a function parameter (so my GameObjects stay on the terrain, also too drastic). In Terrain.h I pass a camera reference as a function parameter and save a camera pointer in a class contained in the terrain class, so I include Camera.h. (for some culling, and again too drastic!)

So I basically have a cyclic dependency.
I tried to forward declare in those files:
1>------ Build started: Project: TheGame, Configuration: Debug Win32 ------
1>  Camera.cpp
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2027: use of undefined type 'GameObject'
1>		  c:\users\jonas\desktop\thegame\camera.h(4) : see declaration of 'GameObject'
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.Position' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.x' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2027: use of undefined type 'GameObject'
1>		  c:\users\jonas\desktop\thegame\camera.h(4) : see declaration of 'GameObject'
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.Position' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.y' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2027: use of undefined type 'GameObject'
1>		  c:\users\jonas\desktop\thegame\camera.h(4) : see declaration of 'GameObject'
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.Position' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(217): error C2228: left of '.z' must have class/struct/union
1>c:\users\jonas\desktop\thegame\camera.cpp(218): error C2027: use of undefined type 'GameObject'
1>		  c:\users\jonas\desktop\thegame\camera.h(4) : see declaration of 'GameObject'
1>c:\users\jonas\desktop\thegame\camera.cpp(218): error C2228: left of '.Position' must have class/struct/union
1>  GameObject.cpp
1>c:\users\jonas\desktop\thegame\gameobject.cpp(64): error C2027: use of undefined type 'Terrain'
1>		  c:\users\jonas\desktop\thegame\gameobject.h(5) : see declaration of 'Terrain'
1>c:\users\jonas\desktop\thegame\gameobject.cpp(64): error C2227: left of '->getWidth' must point to class/struct/union/generic type
1>c:\users\jonas\desktop\thegame\gameobject.cpp(65): error C2027: use of undefined type 'Terrain'
1>		  c:\users\jonas\desktop\thegame\gameobject.h(5) : see declaration of 'Terrain'
1>c:\users\jonas\desktop\thegame\gameobject.cpp(65): error C2227: left of '->getDepth' must point to class/struct/union/generic type
1>c:\users\jonas\desktop\thegame\gameobject.cpp(78): error C2027: use of undefined type 'Terrain'
1>		  c:\users\jonas\desktop\thegame\gameobject.h(5) : see declaration of 'Terrain'
1>c:\users\jonas\desktop\thegame\gameobject.cpp(78): error C2227: left of '->getHeight' must point to class/struct/union/generic type
1>c:\users\jonas\desktop\thegame\gameobject.cpp(320): error C2027: use of undefined type 'Terrain'
1>		  c:\users\jonas\desktop\thegame\gameobject.h(5) : see declaration of 'Terrain'
1>c:\users\jonas\desktop\thegame\gameobject.cpp(320): error C2227: left of '->getHeight' must point to class/struct/union/generic type
1>  Terrain.cpp
1>c:\users\jonas\desktop\thegame\terrain.cpp(117): error C2027: use of undefined type 'Camera'
1>		  c:\users\jonas\desktop\thegame\terrain.h(4) : see declaration of 'Camera'
1>c:\users\jonas\desktop\thegame\terrain.cpp(117): error C2227: left of '->pos' must point to class/struct/union/generic type
1>c:\users\jonas\desktop\thegame\terrain.cpp(118): error C2027: use of undefined type 'Camera'
1>		  c:\users\jonas\desktop\thegame\terrain.h(4) : see declaration of 'Camera'
1>c:\users\jonas\desktop\thegame\terrain.cpp(118): error C2227: left of '->pos' must point to class/struct/union/generic type
1>c:\users\jonas\desktop\thegame\terrain.cpp(128): error C2027: use of undefined type 'Camera'
1>		  c:\users\jonas\desktop\thegame\terrain.h(4) : see declaration of 'Camera'
1>c:\users\jonas\desktop\thegame\terrain.cpp(128): error C2228: left of '.isVisible' must have class/struct/union
1>  TheGame.cpp
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

My main still includes the according headers, and I use these objects like this:
Camera	 g_Camera;	
Terrain*	g_Terrain;	
std::vector<GameObject*> g_GameObjectList;
Do I have to forward declare Terrain and GameObject, too? Well, at the moment it gives me more of the same errors when I do.
Any advice?

Passing an object to another class

01 March 2012 - 01:29 PM

Hey gamedev,
I am extremely rusty with my C++ skills. I want to pass my camera object to the terrain class, so I can cull some subgrids from my view frustrum.
So, my initial idea was to pass the camera in the terrain constructor.
I have my camera declared like this:
Camera	 g_Camera;
and after I initialize the camera I call the constructor for my terrain.
I am really unsure how I should accomplish this, but I would save a "Camera &" in my terrain class and just pass over the reference in the constructor. But I get these errors:

1>c:\***\thegame\terrain.cpp(13): error C2758: 'Terrain::mCamera' : must be initialized in constructor base/member initializer list
1>		  c:\***\thegame\terrain.h(72) : see declaration of 'Terrain::mCamera'
1>c:\***\thegame\terrain.cpp(128): error C2327: 'Terrain::mCamera' : is not a type name, static, or enumerator
1>c:\***\thegame\terrain.cpp(128): error C2065: 'mCamera' : undeclared identifier
1>c:\***\thegame\terrain.cpp(128): error C2228: left of '.getPos' must have class/struct/union
1>		  type is ''unknown-type''

Can anyone outline the correct way to do this? [Full code below]

[DirectX, C++] Problems drawing a cube on screen

24 August 2011 - 07:24 AM

Hello gamedev,
I want to a draw 3D cube using the vertex and index buffer (DX9!). But I cannot see the cube on screen.

This is my vertex:
struct SCubeVertex
{
	tbVector3			vPosition;  
	DWORD				dwColor;	
	static const DWORD 			dwFVF;
};

const DWORD SCubeVertex::dwFVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;

I am using an engine that makes it somewhat easier to use Direct3D. So I will include the declaration of some functions.
This is how initialize my buffers.
    	SCubeVertex Vertex;

		vBuf = new tbVertexBuffer;

   	//tbResult Init(DWORD dwSize, DWORD dwVertexSize, DWORD dwFVF, DWORD dwUsage = D3DUSAGE_WRITEONLY, D3DPOOL Pool = D3DPOOL_DEFAULT);
		if (vBuf->Init(8 * sizeof(SCubeVertex), sizeof(SCubeVertex), SVertex::dwFVF, D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DPOOL_DEFAULT))
		{
			// error...
		}
		iBuf = new tbIndexBuffer;
    	//tbResult Init(DWORD dwSize, DWORD dwIndexSize, D3DFORMAT IndexFormat, DWORD dwUsage = D3DUSAGE_WRITEONLY, D3DPOOL Pool = D3DPOOL_DEFAULT);
		if(iBuf->Init(36 * sizeof(WORD), sizeof(WORD), D3DFMT_INDEX16))
		{
 		// error..
		}
		// Color is choosen randomly
		Vertex.vPosition = pos + tbVector3(-1.0f,  1.0f, -1.0f);
		Vertex.dwColor = tbColorRandom(1.0f) * 2.0f;
		vBuf->SetVertex(0, &Vertex);
		Vertex.vPosition = pos + tbVector3(-1.0f,  1.0f,  1.0f);
		Vertex.dwColor = tbColorRandom(1.0f) * 2.0f;
		vBuf->SetVertex(1, &Vertex);
		Vertex.vPosition = pos + tbVector3( 1.0f,  1.0f,  1.0f);
		Vertex.dwColor = tbColorRandom(1.0f) * 2.0f;
		vBuf->SetVertex(2, &Vertex);
		Vertex.vPosition = pos + tbVector3( 1.0f,  1.0f, -1.0f);
		Vertex.dwColor = tbColorRandom(1.0f) * 2.0f;
		vBuf->SetVertex(3, &Vertex);
		Vertex.vPosition = pos + tbVector3(-1.0f, -1.0f, -1.0f);
		Vertex.dwColor = tbColorRandom(1.0f) * 2.0f;
		vBuf->SetVertex(4, &Vertex);
		Vertex.vPosition = pos + tbVector3(-1.0f, -1.0f,  1.0f);
		Vertex.dwColor = tbColorRandom(1.0f) * 2.0f;
		vBuf->SetVertex(5, &Vertex);
		Vertex.vPosition = pos + tbVector3( 1.0f, -1.0f,  1.0f);
		Vertex.dwColor = tbColorRandom(1.0f) * 2.0f;
		vBuf->SetVertex(6, &Vertex);
		Vertex.vPosition = pos + tbVector3( 1.0f, -1.0f, -1.0f);
		Vertex.dwColor = tbColorRandom(1.0f) * 2.0f;
		vBuf->SetVertex(7, &Vertex);
		

		// index order is correct!
		int aiIndex[36] = 
   						{0, 3, 7,   0, 7, 4,	// Front
           				2, 1, 5,   2, 5, 6,	// Back
                           1, 0, 4,   1, 4, 5,	// Left
                           3, 2, 6,   3, 6, 7,	// Right
                           0, 1, 2,   0, 2, 3,	// Top
                           6, 5, 4,   6, 4, 7};	// Bottom
		iBuf->AddIndices(36, aiIndex);

Here's the actual render function. I am using a sky box and a free flying camera.
tbResult RenderProc(float fNumSecsPassed)
{
	tbMatrix	mProjection;
	tbMatrix	mCamera;
	tbMatrix	mWorld;
	tbVector3	vCameraDir;
	int			iNumPasses;


	tbDirect3D& D3D = tbDirect3D::Instance();
	D3D->BeginScene();
   
    // camera stuff
	// ------------------------------------------------------------------

	// create projection matrix
	mProjection = tbMatrixProjection(TB_DEG_TO_RAD(90.0f), D3D.GetAspect(), 0.1f, 100.0f);
	D3D.SetTransform(D3DTS_PROJECTION, mProjection);

	// create camera matrix (unimportant regarding the issue)
	vCameraDir = tbVector3(sinf(g_fCameraRot) * cosf(g_fCameraUpDown),
       					sinf(g_fCameraUpDown),
                           cosf(g_fCameraRot) * cosf(g_fCameraUpDown));
	mCamera = tbMatrixCamera(g_vCameraPos, g_vCameraPos + vCameraDir);
	D3D.SetTransform(D3DTS_VIEW, mCamera);

	// sky box stuff
	// ------------------------------------------------------------------

	D3D.SetRS(D3DRS_ZENABLE, FALSE);
	D3D.SetRS(D3DRS_DITHERENABLE, TRUE);

	D3D.SetTexture(0, g_pEnvMap);
	D3D.SetTSS(1, D3DTSS_COLOROP, D3DTOP_DISABLE);

	// create worldmatrix, that translates the sky box the camera
	mWorld = tbMatrixTranslation(g_vCameraPos);
	D3D.SetTransform(D3DTS_WORLD, mWorld);

	D3D->SetStreamSource(0, g_pSkyBoxVB->GetVB(), 0, sizeof(SSkyBoxVertex));
	D3D->SetIndices(g_pSkyBoxIB->GetIB());
	D3D.SetFVF(SSkyBoxVertex::dwFVF);

	// Draw!
	iNumPasses = g_pSkyBoxEffect->Begin();
	for(int iPass = 0; iPass < iNumPasses; iPass++)
	{
		g_pSkyBoxEffect->Pass(iPass);
		D3D->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
	}

	g_pSkyBoxEffect->End();
  
    // cube stuff
	// ------------------------------------------------------------------
	D3D.SetRS(D3DRS_ZENABLE, TRUE);
	D3D.SetTransform(D3DTS_WORLD, tbMatrixIdentity());
	g_Cube->Update(D3D); //g_Cube is a initialized GameObject

   D3D->EndScene();

What g_Cube->Update(D3D); calls:
D3D->SetStreamSource(0, vBuf->GetVB(), 0, sizeof(SCubeVertex));
D3D->SetIndices(iBuf->GetIB());
D3D->SetFVF(SCubeVertex::dwFVF);
D3D->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);

Questions regarding 3D models [Direct3D]

12 August 2011 - 06:23 PM

Hellooo gamedev,
I want to make a larger 3D game with DirectX and sample models do not suffice.
I also want my models to be animated (bonus: being able to control certain parts independently, for example the mouth of a humanoid character).

1. What is a good way to load them in my programm?
2. What about file formats?
3. Which programs should I use to create them / export?

Thanks in advance. (I will update this post.)

PARTNERS