1
0
forked from 0ad/0ad

fix crash that happened after editing file while game is running. vfs_tree's tree_root object was being destroyed but not recreated when rebuilding the VFs tree. fixed that as well as correctly freeing all TNode memory upon rebuild.

This was SVN commit r3458.
This commit is contained in:
janwas 2006-02-02 05:20:33 +00:00
parent 7862e79e84
commit 8ed6965d18

View File

@ -258,6 +258,11 @@ static void* node_alloc()
return pool_alloc(&node_pool, 0);
}
static inline void node_free_all()
{
pool_free_all(&node_pool);
}
//////////////////////////////////////////////////////////////////////////////
//
@ -407,14 +412,22 @@ static LibError lookup(TDir* td, const char* path, uint flags, TNode** pnode)
//
//////////////////////////////////////////////////////////////////////////////
static const PathName pn = { "", "" };
static TDir tree_root(pn);
static TDir* tree_root;
// rationale: can't do this in tree_shutdown - we'd leak at exit.
// calling from tree_add* is ugly as well, so require manual init.
void tree_init()
{
node_init();
void* mem = node_alloc();
if(mem)
{
const PathName V_root_path = { "", "" };
#include "nommgr.h"
tree_root = new(mem) TDir(V_root_path);
#include "mmgr.h"
}
}
@ -426,14 +439,15 @@ void tree_shutdown()
void tree_clear()
{
tree_root.clearR();
tree_root->clearR();
node_free_all();
}
// write a representation of the VFS tree to stdout.
void tree_display()
{
displayR(&tree_root, 0);
displayR(tree_root, 0);
}
@ -482,7 +496,7 @@ LibError tree_lookup_dir(const char* path, TDir** ptd, uint flags)
if(path[0] != '\0' && path[strlen(path)-1] != '/')
return ERR_NOT_DIR;
TDir* td = (flags & LF_START_DIR)? *ptd : &tree_root;
TDir* td = (flags & LF_START_DIR)? *ptd : tree_root;
TNode* node;
CHECK_ERR(lookup(td, path, flags, &node));
// directories should exist, so warn if this fails
@ -498,7 +512,7 @@ LibError tree_lookup(const char* path, TFile** pfile, uint flags)
return ERR_NOT_FILE;
TNode* node;
LibError ret = lookup(&tree_root, path, flags, &node);
LibError ret = lookup(tree_root, path, flags, &node);
RETURN_ERR(ret);
*pfile = (TFile*)node;
return ERR_OK;