See the Animation.Get / Set lines?Code:template<typename T> class CUIButton : public CUIObject { public: CUIButton () { CUITask::AddToList( this ); } void Activate(int index=0) { // RUN whatever the button does if ( !Object || !Function ) // prevent calling a null return; if ( Animation.GetCurrentFrame() == 0 ) Animation.SetCurrentFrame(1); else Animation.SetCurrentFrame(0); //(Object->*Function)(); } void ChangeFunctionPointer( T * NewObject, void (T::*NewFunction)(void) ) { Function = NewFunction; } void ( T::*Function )( void ); T * Object; }
The (Object->*Function)() causes it to crash if I run those lines in it. This seems to be that Object isn't copying properly, which leads me to show you this:
Code:class CTestTask : public ITask { public: AUTO_SIZE; bool Start(); void Update(); void Stop(); void Test(); private: CSprite MySprite; CUIButton<CTestTask> MyButton; };Why does the function pointer crash it?Code:bool CTestTask::Start() { MyButton.ChangeFunctionPointer( this, Test ); return true; } void CTestTask::Test() { if ( MyButton.Animation.GetCurrentFrame() ) MyButton.Animation.SetCurrentFrame(0); else MyButton.Animation.SetCurrentFrame(1); }
Edit:
If I do that, then it works. Problem? I'd have to also store the index. But I don't think I need that, do I?Code:void CTestTask::Test() { if ( CUITask::Objects[0]->Animation.GetCurrentFrame() ) CUITask::Objects[0]->Animation.SetCurrentFrame(0); else CUITask::Objects[0]->Animation.SetCurrentFrame(1); }



LinkBack URL
About LinkBacks


