ent_setmesh and LPD3DXMEHS

Posted By: Joey

ent_setmesh and LPD3DXMEHS - 06/05/08 13:01

hello jcl,

i've got a question: i want to use the sdk to create a dll which replaces a mesh of a given entity. the dll is to be used with a7. the mesh is created with D3DXCreateMeshFVF, the flags are set to D3DXMESH_MANAGED | D3DXMESH_32BIT and the vertex format is the one described in the manual (D3DFVF_TLSHADED). the mesh is then set to the entity via ent_setmesh(entity, mesh, 0, 0). this process works properly.

now, when i delete the mesh, i call mesh->Release() and ent_setmesh(entity, NULL, 0, 0). now, when i have multiple entities sharing the same mesh, i have to call that only for the last entity, obviously. but now, for the last entity, the dll crashes. i took out mesh->Release() and it didn't crash - one time. the next time i tried it crashed again. it also crashed when i just closed the engine window, even though i'm calling Release() for all meshes i created in DLL_PROCESS_DETACH. here again, it worked once by taking out ent_setmesh, crashed again, i took out the Release-stuff and it worked one time but then crashed.

could it be that the error comes from the mesh format, a different dx sdk version (i'm using april 08), or... well, i'm somehow stuck here because sometimes the crash happens in the engine (ent_setmesh) and sometimes in the dll (Release).

i'd be very grateful for any hint you might have.
Posted By: jcl

Re: ent_setmesh and LPD3DXMEHS - 06/05/08 15:48

Call ent_setmesh(entity, NULL, 0, 0) _before_ releasing the mesh - otherwise a crash on release is likely.

Apart from that, I'd also first look for possible reasons in the different mesh format and the different DirectX version. Omit the D3DXMESH_32BIT flag - that will cause crashes on old video cards when the mesh is animated. And try the SDK that A7 is using, that's April 2006.
Posted By: Joey

Re: ent_setmesh and LPD3DXMEHS - 06/05/08 17:05

i've installed the old sdk which made the whole stuff work one time but then crashed again when removing the mesh.

but now i could track down the error, the crashes weren't that random anymore. if i call mesh->Release() after ent_setmesh(entity, NULL, 0, 0) the thing crashes. i tend to think that ent_setmesh already released the mesh. how i can know that? well, if i release the mesh before calling ent_setmesh the latter one crashes, so at least it tries to do something with the old mesh.

i'm not sure, but since the crashes don't occur any more... but i don't want to bloat my memory consumption, neither!

thanks for the hint with the sdk, it helped a lot! the D3DXMESH_32BIT changed nothing, though, and anyway, how are you supposed to create meshes with more than 2^16 vertices without 32 bit indices?

joey.
Posted By: Joey

Re: ent_setmesh and LPD3DXMEHS - 06/05/08 18:06

and another question, can it be that the engine already deletes meshes when quitting, because when i try to release meshes - which haven't been released before - on DLL_PROCESS_DETACH, the whole stuff crashes again.
Posted By: jcl

Re: ent_setmesh and LPD3DXMEHS - 06/06/08 08:35

Yes to both. The engine releases all its DirectX objects when it exits, and it also releases its previous mesh when you set a new mesh, or set it to NULL. That's the reason for your release crashes - I should have thought about that.
Posted By: Joey

Re: ent_setmesh and LPD3DXMEHS - 06/06/08 13:26

ok then i'd like to suggest that you remove the hint in the manual which tells you to release the meshes by yourself.

thanks jcl!
Posted By: jcl

Re: ent_setmesh and LPD3DXMEHS - 06/06/08 14:26

I rather leave the hint and disable releasing the mesh on ent_setmesh(entity, NULL, 0, 0). The mesh should not be released by that call, but just set to NULL for preventing a release on exit.
Posted By: Joey

Re: ent_setmesh and LPD3DXMEHS - 06/06/08 14:33

that's probably better, yes, then we can also use newer directx sdk versions and release our stuff ourselves.
© 2023 lite-C Forums