Here is a link to a post I made elsewhere, no one there knows what to say to my problem, maybe on of you guys can help
http://www.gamedev.net/community/for...opic_id=364947
Here is a link to a post I made elsewhere, no one there knows what to say to my problem, maybe on of you guys can help
http://www.gamedev.net/community/for...opic_id=364947
Last edited by Shamino; 12-19-2005 at 11:43 PM.
Sometimes I forget what I am doing when I enter a room, actually, quite often.
First off. I don't see any checks for obj == NULL in your code. Got to make sure you Obj isn't NULL.
Woop?
Not it, Obj definately has something in it the second time around. I put an if (Obj != NULL) around the whole function.
Sometimes I forget what I am doing when I enter a room, actually, quite often.
The error is unlikely to be in the code you have posted. The error is likely to be where you have filled out the ship information and memory allocation. Memory problems (overruns, allocation, deallocation) often don't show up immediately.
Your code contains a lot of pointers. Can I suggest you minimise your use of pointers and use methods such as vectors (or deques) and references? new/delete can usually be avoided.
The only place I allocate and de-allocate memory is where I load the MS3D Model into memory, I'm pretty sure that isnt broken because I got that directly from NeHe, a couple variable names were changed but only for increased readability, I never had a problem with it until now.
I'll post my whole project if need be :\.....
Question, when creating a pointer to an object, do we have to use the new operator? When I create my two ship objects I use the new operator, I havn't really gotten around to de-allocating them yet...
I attached all files that I can find any relevancy to my problem in.
All global variables are for testing purposes, Ship1 and Ship2 are global variables. As well as Obj.
Last edited by Shamino; 12-19-2005 at 11:43 PM.
Sometimes I forget what I am doing when I enter a room, actually, quite often.
Is memory for Model1 allocated somewhere?Code:struct Models { MS3DModel* Model1; }; class Object { public: virtual ~Object() {} float locx, locy, locz; bool MarkedForDeletion; Models mModels; virtual MS3DModel* GetRenderInformation() = 0; virtual void GetPhysicsInformation() = 0; virtual void GetSoundInformation() = 0; virtual void Update() = 0; }; class Ship : public Object { public: Ship(float x, float y, float z) { x = locx; y = locy; z = locz; } MS3DModel* GetRenderInformation() { return this->mModels.Model1; }
Anonytmouse, you hit the nail on the head, yes it is, but not in a good way...
Let me paste a few bits of code.
Apparently, I'm only loading Ship1's instance of Model1....Code:Ship1->mModels.Model1 = new MS3DModel(); if ( Ship1->mModels.Model1->LoadModelData( "data/model2.ms3d" ) == false )// Loads The Model And Checks For Errors { MessageBox( NULL, "Couldn't load the model data\\model.ms3d", "Error", MB_OK | MB_ICONERROR ); return 0; // If Model Didn't Load Quit }
Problem is, I don't want to do one for Ship2's instance as well, I want them to be able to use a single model pointer from memory...
This is why Ship2 is broken, it doesn't have anything loaded..
What do I do to make it so that any Object can use a single pointer to the Memory allocated for this model?
Do I have to copy a single pointer in the constructor of each of my ship objects?
Sometimes I forget what I am doing when I enter a room, actually, quite often.
If all the objects are of the same class (or inherit from the same base class, which appears to be the case), you could have a static member pointer in that class that holds the model. Just initialize it properly in the constructor:Oh - and at the declaration point of the static member pointer, set it to NULL, so the first object that gets instantiated will initialize the model. After that, all will reference the same model.Code:if (NULL == model){ //initialize model for the class }