forked from 0ad/0ad
Fix profiler crash differently
This was SVN commit r8967.
This commit is contained in:
parent
a155809447
commit
ee8b193cdb
@ -626,9 +626,9 @@ bool CProfileNode::Return()
|
||||
}
|
||||
|
||||
CProfileManager::CProfileManager() :
|
||||
root(NULL)
|
||||
root(NULL), current(NULL), needs_structural_reset(false)
|
||||
{
|
||||
StructuralReset();
|
||||
PerformStructuralReset();
|
||||
}
|
||||
|
||||
CProfileManager::~CProfileManager()
|
||||
@ -652,12 +652,8 @@ void CProfileManager::StartScript( const char* name )
|
||||
|
||||
void CProfileManager::Stop()
|
||||
{
|
||||
if( current->Return() )
|
||||
{
|
||||
// (jw: for reasons unknown, current == root when called from main.cpp:293)
|
||||
if(current != root)
|
||||
current = current->GetParent();
|
||||
}
|
||||
if (current->Return())
|
||||
current = current->GetParent();
|
||||
}
|
||||
|
||||
void CProfileManager::Reset()
|
||||
@ -669,6 +665,12 @@ void CProfileManager::Frame()
|
||||
{
|
||||
ONCE(alloc_hook_initialize());
|
||||
|
||||
if (needs_structural_reset)
|
||||
{
|
||||
PerformStructuralReset();
|
||||
needs_structural_reset = false;
|
||||
}
|
||||
|
||||
root->time_frame_current += (timer_Time() - root->start);
|
||||
root->mallocs_frame_current += (get_memory_alloc_count() - root->start_mallocs);
|
||||
|
||||
@ -684,6 +686,16 @@ void CProfileManager::Turn()
|
||||
}
|
||||
|
||||
void CProfileManager::StructuralReset()
|
||||
{
|
||||
// We can't immediately perform the reset, because we're probably already
|
||||
// nested inside the profile tree and it will get very confused if we delete
|
||||
// the tree when we're not currently at the root.
|
||||
// So just set a flag to perform the reset at the end of the frame.
|
||||
|
||||
needs_structural_reset = true;
|
||||
}
|
||||
|
||||
void CProfileManager::PerformStructuralReset()
|
||||
{
|
||||
delete root;
|
||||
root = new CProfileNode("root", NULL);
|
||||
|
@ -67,7 +67,7 @@ class CProfileNode
|
||||
std::vector<CProfileNode*> children;
|
||||
std::vector<CProfileNode*> script_children;
|
||||
CProfileNodeTable* display_table;
|
||||
|
||||
|
||||
public:
|
||||
typedef std::vector<CProfileNode*>::iterator profile_iterator;
|
||||
typedef std::vector<CProfileNode*>::const_iterator const_profile_iterator;
|
||||
@ -112,6 +112,10 @@ class CProfileManager : public Singleton<CProfileManager>
|
||||
CProfileNode* root;
|
||||
CProfileNode* current;
|
||||
|
||||
bool needs_structural_reset;
|
||||
|
||||
void PerformStructuralReset();
|
||||
|
||||
public:
|
||||
CProfileManager();
|
||||
~CProfileManager();
|
||||
@ -130,7 +134,7 @@ public:
|
||||
// Resets turn timing information
|
||||
// (Must not be called before Frame)
|
||||
void Turn();
|
||||
// Resets absolutely everything
|
||||
// Resets absolutely everything, at the end of this frame
|
||||
void StructuralReset();
|
||||
|
||||
inline const CProfileNode* GetCurrent() { return( current ); }
|
||||
|
Loading…
Reference in New Issue
Block a user