Re: Two simple meshes - memory gone



"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.


.



Relevant Pages

  • multiple mesh loading function crashing
    ... D3DXLoadMeshFromX(meshnames, // load this file ... D3DXMESH_SYSTEMMEM, ... // put the materials here ... // if there is a texture to load, ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: D3DFVF_XYZRHW | D3DFVF_DIFFUSE question
    ... lighting computations done? ... >Materials can also influence the colour of a surface. ... >white so that the true texture colour shows through. ... >You need to enable the specular render state for this to have an affect ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: D3DFVF_XYZRHW | D3DFVF_DIFFUSE question
    ... Materials can also influence the colour of a surface. ... So if you set white verts, and a yellow material and shine a white light on ... If i want to use lights in the scene but not texture objects, ... > specified diffuse color altered seemingly at random. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Problem Loading Simple Mesh
    ... like it isn't shading the object, but just appling the texture so the object ... //globabl variables for the mesh ... Mesh\Sample\tiger.x", MeshFlags.SystemMemory, device, out materials); ... //used to render the mesh to backbuffer ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: D3DFVF_XYZRHW | D3DFVF_DIFFUSE question
    ... even using lit vertices without a normal. ... you should render between a disable and enable lighting call. ... >>Materials can also influence the colour of a surface. ... >>white so that the true texture colour shows through. ...
    (microsoft.public.win32.programmer.directx.graphics)