To be honest I do not know if the title is correct for the issue I am experiencing. The issue is thus. I have a class called Engine, of which there is one instance.
It contains two member variables (among others) called testTexture
, an instance of my custom Texture
class, and testObject
, an instance of my custom object class.
In the Engine function Init
their values are set thusly:
testTexture = Texture(0, TEXT("D:\\spriteWallVertical112.png"),
renderer.ReturnDevice());
testObject = Object(0,testTexture.textureID, D3DXVECTOR3(0,0,0),
D3DXVECTOR3(100,100,100), testTexture.texture, &renderer);
This all appears to function as I would want, their values are stored and appear to be maintained fine.
However, inside the Object
class constructor there is a call to a function in my Renderer
class called AddNewTextureObject
:
rendererPointer->AddNewTextureObject(&objectID, &textureID, textureInput,
&origin, &coordinates);
This appears to go fine, but as the program runs the values the pointers appear to get overwritten as the program goes on. They don't instantly become junk memory, but it seems clear that they are. I can provide code as needed, but I don't want to just spam this question with code that isn't relevant to the question, especially if someone else may see something obvious that I am doing wrong.
I will however post the TextureObject
class code for now as I think it's the most relevant here:
#ifndef TEXTUREOBJECT_H
#define TEXTUREOBJECT_H
#ifndef UNICODE
#define UNICODE
#endif
#include <d3dx9.h>
class TextureObject
{
public:
TextureObject();
TextureObject(unsigned int *, int *, LPDIRECT3DTEXTURE9, D3DXVECTOR3 *, D3DXVECTOR3 *);
~TextureObject();
unsigned int *objectID; // The object with the texture. Use this for locating and deleting this instance of TextureObject.
int *textureID;
LPDIRECT3DTEXTURE9 texture; // May not be needed if we can simply select the texture via ID.
const D3DXVECTOR3 *origin; // Needed for drawing rotations....I think.
D3DXVECTOR3 *coordinates;
int maintainMe;
};
#endif
The variable maintainMe
does keep its value if I assign to it.
This is the code for the AddNewTextureObject()
function:
void Renderer::AddNewTextureObject(unsigned int *objectIDInput, int *textureIDInput, LPDIRECT3DTEXTURE9 textureInput, D3DXVECTOR3 *originInput, D3DXVECTOR3 *coordinatesInput)
{
//testTextureObject = TextureObject(objectID, textureID, textureInput, originInput, coordinatesInput);
testTextureObject.objectID = objectIDInput;
testTextureObject.textureID = textureIDInput;
testTextureObject.texture = textureInput;
testTextureObject.origin = originInput;
testTextureObject.coordinates = coordinatesInput;
testTextureObject.maintainMe = 3067;
Note that either method of assigning values to testTextureObject
results in the issue.
Any assistance with this would be greatly appreciated.
EDIT:
Here is the constructor for the Object
class:
Object::Object(unsigned int objectIDInput, int textureIDInput, D3DXVECTOR3 originInput, D3DXVECTOR3 coordinatesInput, LPDIRECT3DTEXTURE9 textureInput, Renderer *rendererInput)
{
objectID = objectIDInput;
textureID = textureIDInput;
origin = originInput;
coordinates = coordinatesInput;
rendererPointer = rendererInput;
rendererPointer->AddNewTextureObject(&objectID, &textureID, textureInput, &origin, &coordinates);
}
It is declared in Object.h
in the Object
class as public like this:
Object(unsigned int, int, D3DXVECTOR3, D3DXVECTOR3, LPDIRECT3DTEXTURE9, Renderer *);
EDIT2: I made a copy constructor and an assignment operator:
Object::Object(const Object &source)
{
objectID = source.objectID;
textureID = source.textureID;
texture = source.texture;
origin = source.origin;
coordinates = source.coordinates;
rendererPointer = source.rendererPointer;
}
Object& Object::operator=(const Object &source)
{
if(this == &source)
{
return *this;
}
objectID = source.objectID;
textureID = source.textureID;
texture = source.texture;
origin = source.origin;
coordinates = source.coordinates;
rendererPointer = source.rendererPointer;
return *this;
}
Do these look correct to you more experienced people? This alone does not appear to fix the issue unfortunately.