Jump to content

  • Log In with Google      Sign In   
  • Create Account


C++ Stack Overflow Error?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 dvds414   Members   -  Reputation: 124

Like
0Likes
Like

Posted 31 July 2013 - 01:04 PM

So I am having this error with my code and keep getting the Stack Overflow Error and cannot fix it no matter what I try. I was hoping someone could point out what is wrong.

 

Here is my model loading and drawing code:

 

////MODEL.CPP

#include "model.h"

Model::Model()
{
}

Model::~Model()
{
}

void Model::Load(LPCSTR Filename, LPDIRECT3DDEVICE9 GraphicsDevice)
{
    HRESULT HR;
    HR = D3DXLoadMeshFromX("Content/m.x", D3DXMESH_SYSTEMMEM,
        GraphicsDevice, NULL, &MaterialBuffer, NULL, &MaterialCount,
        &Mesh);
    if (FAILED(HR))
        MessageBox(NULL, "Can't load model!", "ERROR", MB_OK);
    Materials = (D3DXMATERIAL*)MaterialBuffer->GetBufferPointer();
    MeshMaterials = new D3DMATERIAL9[MaterialCount];
    MeshTextures = new LPDIRECT3DTEXTURE9[MaterialCount];
    for (DWORD i = 0; i < MaterialCount; i++)
    {
        MeshMaterials[i] = Materials[i].MatD3D;
        MeshMaterials[i].Ambient = MeshMaterials[i].Diffuse;
        MeshTextures[i] = NULL;
        if (Materials[i].pTextureFilename)
            D3DXCreateTextureFromFile(GraphicsDevice,
            Materials[i].pTextureFilename, &MeshTextures[i]);
    }
    MaterialBuffer->Release();
}

void Model::Render(LPDIRECT3DDEVICE9 GraphicsDevice)
{
    D3DXMATRIX World;
    D3DXMatrixIdentity(&World);
    GraphicsDevice->SetTransform(D3DTS_WORLD, &World);
    for (DWORD i = 0; i < MaterialCount; i++)
    {
        GraphicsDevice->SetMaterial(&MeshMaterials[i]);
        GraphicsDevice->SetTexture(0, MeshTextures[i]);
        Mesh->DrawSubset(i);
    }
}

 

////MODEL.H

#ifndef _MODEL_H_
#define _MODEL_H_
#include <d3d9.h>
#include <d3dx9.h>

class Model
{
    public:
        Model();
        ~Model();
        LPD3DXMESH Mesh;
        LPD3DXBUFFER MaterialBuffer;
        DWORD MaterialCount;
        D3DXMATERIAL* Materials;
        D3DMATERIAL9* MeshMaterials;
        LPDIRECT3DTEXTURE9* MeshTextures;
        void Load(LPCSTR, LPDIRECT3DDEVICE9);
        void Render(LPDIRECT3DDEVICE9);
};

#endif

 

Does anyone spot why this would be calling a stackoverflow error?



Sponsor:

#2 Dave Hunt   Crossbones+   -  Reputation: 2416

Like
0Likes
Like

Posted 31 July 2013 - 01:56 PM

Do we get to know where the stack overflow occurs?

 

Also, where is the code that calls the function that is throwing the stack overflow?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS