Skip to content

Commit

Permalink
Fix UnitTests
Browse files Browse the repository at this point in the history
Fix TTask unintentionally deleting itself
  • Loading branch information
AdventureT committed Dec 29, 2023
1 parent b0a6329 commit e27e2a6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 44 deletions.
3 changes: 1 addition & 2 deletions OpenJPOG/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ TBOOL AApplication::OnCreate(TINT argc, TPCHAR* const argv)
m_pInputTask = (ADummyTask*)g_oTheApp.GetKernel()->GetScheduler()->CreateTask(TGetClass(ADummyTask), TNULL);
m_pInputTask->Create();
m_pInputTask->Activate(TTRUE);
TPCHAR str = (TPCHAR)"InputTask";
m_pInputTask->SetName(str);
m_pInputTask->SetName((TPCHAR)"InputTask");

return TApplication::OnCreate(argc, argv);
}
Expand Down
2 changes: 1 addition & 1 deletion Toshi/Include/TKernel/TDList.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class TOSHI_EXPORT TGenericDList
};

template <class T, int C = 0>
class TOSHI_EXPORT TDList : public TGenericDList
class TDList : public TGenericDList
{
public:

Expand Down
2 changes: 1 addition & 1 deletion Toshi/Include/TKernel/TManagedPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
TOSHI_NAMESPACE_BEGIN

template<class T>
class TOSHI_EXPORT TManagedPointer
class TManagedPointer
{
public:
TManagedPointer() : m_pObject(TNULL)
Expand Down
14 changes: 7 additions & 7 deletions Toshi/Include/TKernel/TTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class TOSHI_EXPORT TTask : public TObject, public TNodeTree<TTask>::TNode

virtual TBOOL Create();
virtual TBOOL CreateFailed();
virtual TBOOL OnCreate();
virtual TBOOL OnUpdate(TFLOAT a_fDeltaTime);
virtual void OnDestroy();
virtual TBOOL OnChildDying(TTask* child);
virtual void OnChildDied(TClass* a_pClass, TTask* a_pDeletedTask);
virtual void OnActivate();
virtual void OnDeactivate();
virtual TBOOL OnCreate() { return TTRUE; }
virtual TBOOL OnUpdate(TFLOAT a_fDeltaTime) { return TTRUE; }
virtual void OnDestroy() {}
virtual TBOOL OnChildDying(TTask* child) { return TTRUE; }
virtual void OnChildDied(TClass* a_pClass, TTask* a_pDeletedTask) {}
virtual void OnActivate() {}
virtual void OnDeactivate() {}

void Activate(TBOOL a_bActivate);

Expand Down
53 changes: 20 additions & 33 deletions Toshi/Source/TKernel/TTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,37 @@ TBOOL TTask::Create()
return TFALSE;
}

//auto oldState = m_State;
//m_State |= State_Created;
//Activate(TTRUE);
m_iState |= State_Created;
Activate(TTRUE);
}

return TTRUE;
}

TBOOL TTask::CreateFailed()
{
return TBOOL();
}

TBOOL TTask::OnCreate()
{
return TBOOL();
}

TBOOL TTask::OnUpdate(TFLOAT a_fDeltaTime)
{
return TBOOL();
}

void TTask::OnDestroy()
{
}

TBOOL TTask::OnChildDying(TTask* child)
{
return TBOOL();
}
TASSERT(IsCreated() == TFALSE);

void TTask::OnChildDied(TClass* a_pClass, TTask* a_pDeletedTask)
{
}

void TTask::OnActivate()
{
}
if (!IsCreated()) {
m_Tree->Remove(this, TFALSE);
Delete();
}

void TTask::OnDeactivate()
{
return TFALSE;
}

void TTask::Activate(TBOOL a_bActivate)
{
TUINT8 oldState = m_iState;
TUINT8 newFlags = a_bActivate ? State_Active : 0;
m_iState = (m_iState & ~State_Active) | newFlags;

if (oldState != m_iState) {
if (a_bActivate) {
OnActivate();
}
else {
OnDeactivate();
}
}
}

0 comments on commit e27e2a6

Please sign in to comment.