Tiny issue - spurious code in ConsoleFunction Compile()
by Orion Elenzil · in Torque Game Engine · 09/14/2007 (11:09 am) · 1 replies
We're having this issue where sometimes our .cs files are not recompiling when they should,
and in the course of looking into it i found what seems like some spurious calls to getFileTimes() in the console function compile().
correct me if i'm wrong, but in the following function, comModifyTime and srcModifyTime are in fact inutile ?
tia,
orion
and in the course of looking into it i found what seems like some spurious calls to getFileTimes() in the console function compile().
correct me if i'm wrong, but in the following function, comModifyTime and srcModifyTime are in fact inutile ?
tia,
orion
ConsoleFunction(compile, bool, 2, 2, "compile(fileName)")
{
argc;
char nameBuffer[512];
char* script = NULL;
U32 scriptSize = 0;
Stream *compiledStream = NULL;
FileTime comModifyTime, scrModifyTime;
Con::expandScriptFilename(scriptFilenameBuffer, sizeof(scriptFilenameBuffer), argv[1]);
dSprintf(nameBuffer, sizeof(nameBuffer), "%s.dso", scriptFilenameBuffer);
ResourceObject *rScr = ResourceManager->find(scriptFilenameBuffer);
ResourceObject *rCom = ResourceManager->find(nameBuffer);
if(rCom)
rCom->getFileTimes(NULL, &comModifyTime);
if(rScr)
rScr->getFileTimes(NULL, &scrModifyTime);
Stream *s = ResourceManager->openStream(scriptFilenameBuffer);
if(s)
{
scriptSize = ResourceManager->getSize(scriptFilenameBuffer);
script = new char [scriptSize+1];
s->read(scriptSize, script);
ResourceManager->closeStream(s);
script[scriptSize] = 0;
}
if (!scriptSize || !script)
{
delete [] script;
Con::errorf(ConsoleLogEntry::Script, "exec: invalid script file %s.", scriptFilenameBuffer);
return false;
}
// compile this baddie.
Con::printf("Compiling %s...", scriptFilenameBuffer);
CodeBlock *code = new CodeBlock();
bool res = code->compile(nameBuffer, scriptFilenameBuffer, script);
delete code;
code = NULL;
delete[] script;
return res;
}About the author
Associate Orion Elenzil
Real Life Plus
fixed our problem w/ scripts not recompiling -
this was because of a call similar to:
dStrcat((char*)(Platform::getWorkingDirectory()), "foo"),
which made subsequent calls to getWorkingDirectory() return an additional "foo",
and of course overwrote some random memory.
remember folks:
if you find yourself casting a const char* to a char*, you might be making a mistake !