Objects in non-static instances of classes

edited July 2012 in Help request
Hello again :)

I've encountered a very weird problem that is probably caused by my little programming experience^^

I've tried to do some bad OOP without Scroll for "fun" :P
(I'll probably have to overthink that :blush: )


In my "game" there are these 4 old guys standing on something.
Everyone of them is an instance of the same class
#include "Held.h"
/*
If I would put -right- in the update function 4 old man would make the game crash, but 2 would still work :D :O 
*/
orxVECTOR right = {50.0f, 0.0f, 0.0f}; 

Held::Held()
{
	heldobj = orxObject_CreateFromConfig( "Held" );
	orxObject_SetUserData (heldobj, this);
	orxCLOCK* AnimationClock = orxClock_Create( 0.2f, orxCLOCK_TYPE_USER );
	orxClock_Register( AnimationClock, Update, heldobj , orxMODULE_ID_MAIN, orxCLOCK_PRIORITY_NORMAL );
	//orxEvent_AddHandler( orxEVENT_TYPE_ANIM, Held::EventHandler );
	
}

void Held::Update(const orxCLOCK_INFO *_pstClockInfo, void *_pstContext)
{
	orxOBJECT *pstObject = orxOBJECT( _pstContext );
	Held *prtObj = (Held *)orxObject_GetUserData(pstObject);
	
	
	if( orxInput_IsActive( "right" ) )
	{
		
		orxObject_SetSpeed ( prtObj->heldobj, &right );
		orxObject_SetTargetAnim( prtObj->heldobj, "WalkRight" );
		
	}
	else
	{
		orxObject_SetTargetAnim( prtObj->heldobj, orxNULL );
		//orxVECTOR right = {0.0f, 0.0f, 0.0f};
		//orxObject_SetSpeed ( prtObj->heldobj, &right);
	}

}

I've tried to create a static instance of the "Held" Class wich worked fine.
But if I created not-static instances the first instance(old man) wouldn't move if orxInput_IsActive( "right" ).
If I added a second not-static old man he would move just fine :OOO
The third too. The fourth not.
The game would crash at exit with 4 old men
and crash at start with 5 old men.
I totally don't know what is happening to me. :S

For more information you can download the project here:
Dropbox download

I am using the latest SVN version.

Comments

  • edited July 2012
    I'll check your issue either tonight or tomorrow night! :)
  • edited July 2012
    At the end of spiel::load, all the non-static Held objects get deleted and their memory available to use again. The reason it was almost working is because the orxObjects don't get deleted (because there is no destructor for the Held class).

    You could probably make them pointers in the spiel class and delete them in an unload/exit function later? Something along those lines should work.
  • edited July 2012
    At the end of spiel::load, all the non-static Held objects get deleted and their memory available to use again. The reason it was almost working is because the orxObjects don't get deleted (because there is no destructor for the Held class).
    Thanks for that very much :laugh:

    At least I've now made my game crash how it should be :)
    I didn't figure out how to get an non-static Held object working though.
    But I don't want to bother you with such basic things anymore.

    I thank you very much for your help :cheer:
  • edited July 2012
    As everything looks to have been said, I'm just popping here to welcome restricter among us! :)
Sign In or Register to comment.