mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Fixed a nasty order of destruction bug, where the memory pool for ScriptInts was destroyed before the PackageManager
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@20 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -64,6 +64,14 @@ class ParseError : public Error {
|
||||
inline ParseError(const String& str) : Error(str) {}
|
||||
};
|
||||
|
||||
/// Parse error in a particular file
|
||||
class FileParseError : public ParseError {
|
||||
public:
|
||||
inline FileParseError(const String& err, const String& file) :
|
||||
ParseError(_("Error while parsing file '") + file + _("':\n") + err)
|
||||
{}
|
||||
};
|
||||
|
||||
/// Parse error in a script
|
||||
class ScriptParseError : public ParseError {
|
||||
public:
|
||||
|
||||
@@ -24,9 +24,9 @@ template <> void GetMember::store(const unsigned int& v) { value = toScript((int
|
||||
template <> void GetMember::store(const double& v) { value = toScript(v); }
|
||||
template <> void GetMember::store(const bool& v) { value = toScript(v); }
|
||||
|
||||
template <> void GetMember::store(const ScriptValueP& v) { value = v; }
|
||||
template <> void GetMember::store(const ScriptP& v) { value = v; }
|
||||
|
||||
template <> void GetMember::store(const Vector2D& v) {
|
||||
value = toScript(String::Format(_("(%.10lf,%.10lf)"), v.x, v.y));
|
||||
}
|
||||
|
||||
void GetMember::store(const ScriptValueP& v) { value = v; }
|
||||
void GetMember::store(const ScriptP& v) { value = v; }
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <util/prec.hpp>
|
||||
|
||||
DECLARE_INTRUSIVE_POINTER_TYPE(ScriptValue);
|
||||
DECLARE_INTRUSIVE_POINTER_TYPE(Script);
|
||||
inline void intrusive_ptr_add_ref(ScriptValue* p);
|
||||
inline void intrusive_ptr_release(ScriptValue* p);
|
||||
|
||||
@@ -54,6 +55,8 @@ class GetMember {
|
||||
template <typename T> void store(const shared_ptr<T>& pointer) {
|
||||
value = toScript(pointer);
|
||||
}
|
||||
void store(const ScriptValueP&);
|
||||
void store(const ScriptP&);
|
||||
|
||||
private:
|
||||
const String& targetName; ///< The name we are looking for
|
||||
|
||||
@@ -379,11 +379,11 @@ Packaged::Packaged() {
|
||||
void Packaged::open(const String& package) {
|
||||
Package::open(package);
|
||||
Reader reader(openIn(typeName()), absoluteFilename() + _("/") + typeName());
|
||||
// try {
|
||||
try {
|
||||
reader.handle(*this);
|
||||
// } catch (const ParseError& err) {
|
||||
// throw FileParseError(err.what(), filename+_("/")+typeName()); // more detailed message
|
||||
// }
|
||||
} catch (const ParseError& err) {
|
||||
throw FileParseError(err.what(), absoluteFilename() + _("/") + typeName()); // more detailed message
|
||||
}
|
||||
}
|
||||
void Packaged::save() {
|
||||
//writeFile(thisT().fileName, thisT());
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : PackageManager
|
||||
|
||||
String programDir() {
|
||||
String program_dir() {
|
||||
return _("."); //TODO
|
||||
}
|
||||
|
||||
@@ -20,18 +20,22 @@ PackageManager packages;
|
||||
|
||||
PackageManager::PackageManager() {
|
||||
// determine data directory
|
||||
dataDirectory = programDir();
|
||||
data_directory = program_dir();
|
||||
// check if this is the actual data directory, especially during debugging,
|
||||
// the data may be higher up:
|
||||
// exe path = mse/build/debug/mse.exe
|
||||
// data path = mse/data
|
||||
while (!wxDirExists(dataDirectory + _("/data"))) {
|
||||
String d = dataDirectory;
|
||||
dataDirectory = wxPathOnly(dataDirectory);
|
||||
if (d == dataDirectory) {
|
||||
while (!wxDirExists(data_directory + _("/data"))) {
|
||||
String d = data_directory;
|
||||
data_directory = wxPathOnly(data_directory);
|
||||
if (d == data_directory) {
|
||||
// we are at the root -> 'data' not found anywhere in the path -> fatal error
|
||||
throw Error(_("The MSE data files can not be found, there should be a directory called 'data' with these files"));
|
||||
}
|
||||
}
|
||||
dataDirectory += _("/data");
|
||||
data_directory += _("/data");
|
||||
}
|
||||
|
||||
void PackageManager::destroy() {
|
||||
loaded_packages.clear();
|
||||
}
|
||||
@@ -28,11 +28,11 @@ class PackageManager {
|
||||
/// Open a package with the specified name (including extension)
|
||||
template <typename T>
|
||||
shared_ptr<T> open(const String& name) {
|
||||
wxFileName fn(dataDirectory + _("/") + name);
|
||||
wxFileName fn(data_directory + _("/") + name);
|
||||
fn.Normalize();
|
||||
String filename = fn.GetFullPath();
|
||||
// Is this package already loaded?
|
||||
PackagedP& p = loadedPackages[filename];
|
||||
PackagedP& p = loaded_packages[filename];
|
||||
shared_ptr<T> typedP = dynamic_pointer_cast<T>(p);
|
||||
if (typedP) {
|
||||
return typedP;
|
||||
@@ -48,9 +48,14 @@ class PackageManager {
|
||||
/// the type of package is determined by its extension!
|
||||
PackagedP openAnyPackage(const String& filename);
|
||||
|
||||
/// Empty the list of packages.
|
||||
/** This function MUST be called before the program terminates, otherwise
|
||||
* we could get into fights with pool allocators used by ScriptValues */
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
map<String, PackagedP> loadedPackages;
|
||||
String dataDirectory;
|
||||
map<String, PackagedP> loaded_packages;
|
||||
String data_directory;
|
||||
};
|
||||
|
||||
/// The global PackageManager instance
|
||||
|
||||
@@ -92,11 +92,11 @@ inline shared_ptr<T> new_shared7(const A0& a0, const A1& a1, const A2& a2, const
|
||||
|
||||
#else
|
||||
#define DECLARE_INTRUSIVE_POINTER_TYPE DECLARE_POINTER_TYPE
|
||||
#define intrusive_ptr smart_ptr
|
||||
#define new_intrusive new_smart
|
||||
#define new_intrusive1 new_smart1
|
||||
#define new_intrusive2 new_smart2
|
||||
#define new_intrusive3 new_smart3
|
||||
#define intrusive_ptr shared_ptr
|
||||
#define new_intrusive new_shared
|
||||
#define new_intrusive1 new_shared1
|
||||
#define new_intrusive2 new_shared2
|
||||
#define new_intrusive3 new_shared3
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
Reference in New Issue
Block a user