Re: Two simple meshes - memory gone
- From: "Robert Dunlop [MS MVP]" <rdunlop@xxxxxxxx>
- Date: Fri, 29 Apr 2005 14:32:27 -0700
"the friendly display name"
<thefriendlydisplayname@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0FDE818B-3C72-40F4-8312-C3EBB21F9059@xxxxxxxxxxxxxxxx
[re-ordered]
> This is just a snapshot of the program of course. It is fairly simple to
> see, what I am doing here. I load two meshes, tiger.x and bigship1.x (both
> from the Directx SDK). The problem is, when I try to run this program, I
> get
> a crash.
>
> But, if I replace the second mesh, bigship1.x, with teapot.x or another
> small sized mesh (bigship is around 450 k) the program runs without
> problems.
>
> The program crashes when the second mesh is over 200 kb in size.
I dare say it is very unlikely this is a problem with running out of memory.
Your code needs to properly check errors and return values, otherwise you
will be prone to crashes and have no indication of where they are occuring.
For example:
> void initmesh()
> {
> D3DXLoadMeshFromX("misc\\tiger.x", NULL, ddevice, NULL, &buffer, NULL,
> &countmaterials,
> &mesh);
>
> D3DXMATERIAL *materialinfo = (D3DXMATERIAL*) buffer->GetBufferPointer();
You should always verify return values from D3DX functions, to make sure
they completed successfully. Also it's a good habit to initialize variables
that will be used to return pointers to NULL before calls, and check that
they are non-null before using, like:
ID3DXBuffer *buffer=NULL;
if (SUCCEEDED(D3DXLoadMeshFromX("misc\\tiger.x", NULL, ddevice, NULL,
&buffer, NULL, &countmaterials, &mesh))) {
if (buffer) {
D3DXMATERIAL *materialinfo = (D3DXMATERIAL*)
buffer->GetBufferPointer();
Without at least making sure that the call succeeded, you would end up
calling a method from an invalid ID3DXBuffer pointer if the model fails to
load (for example if it cannot find the specified file), which would cause a
crash.
> texture[i] = NULL;
>
> D3DXCreateTextureFromFile(ddevice, materialinfo[i].pTextureFilename,
> &texture[i]);
You're assuming here that each material structure will have a valid file
name, but there can be materials that don't have a texture mapped to them,
in which case the pTextureFilename member will be NULL. Thus the following
would be appropriate to catch this condition:
texture[i] = NULL;
if (materialinfo[i].pTextureFilename)
D3DXCreateTextureFromFile(ddevice, materialinfo[i].pTextureFilename,
&texture[i]);
If no texture filename is specified, the texture pointer will be NULL, which
will work with later calls to SetTexture() to disable texture mapping for
these materials.
By the way, the Bigship1.x file in the SDK has 5 materials, none of which
have texture file names, so these calls could possibly be your problem.
Finally, when you are done with the ID3DXBuffer pointers you recieved, you
need to call Release() or they will not be properly de-allocated:
buffer->Release();
shipbuffer->Release();
--
Robert Dunlop
The X-Zone
http://www.directxzone.com/
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do not
reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation
with Microsoft.
.
- References:
- Two simple meshes - memory gone
- From: the friendly display name
- Two simple meshes - memory gone
- Prev by Date: RE: Mip-map not generated without D3DUSAGE_AUTOGENMIPMAP
- Next by Date: Re: windows CE porting
- Previous by thread: Two simple meshes - memory gone
- Next by thread: D3DLOCK_DISCARD | D3DLOCK_NOOVERWRITE
- Index(es):
Relevant Pages
|