Game Development Community

dev|Pro Game Development Curriculum

Bug fix for SimBase text writing of datablocks (fixed Particle Editor scripts)

by J "hplus" W · 11/13/2006 (4:43 pm) · 4 comments

The built-in particle editor writes out scripts that you can load in as particle data. However, if you do, you actually get a crash, because it turns out that it creates data blocks with "new" rather than "datablock," because, in turn, the serialization support in SimBase is not smart enough to tell the difference.

I'm sorry if I seem ornery, but this is quite frustrating. Each time I try to use something, it turns out to be broken and un-tested. Last week, it was the Linux build; this week, it was object serialization AND cross-platform communication. I'd really like to be able to actually write some content code, rather than debug the core product...

Fix:
===================================================================
--- console/simBase.cc  (revision 648)
+++ console/simBase.cc  (working copy)
@@ -446,6 +446,14 @@
       mFieldDictionary->writeFields(this, stream, tabStop);
 }

+static char const * getNewFunction(SimObject * so)
+{
+  if (dynamic_cast<SimDataBlock *>(so) != NULL) {
+    return "datablock";
+  }
+  return "new";
+}
+
 void SimObject::write(Stream &stream, U32 tabStop, U32 flags)
 {
    // Only output selected objects if they want that.
@@ -454,7 +462,8 @@

    writeTabs(stream, tabStop);
    char buffer[1024];
-   dSprintf(buffer, sizeof(buffer), "new %s(%s) {\r\n", getClassName(), getName() ? getName() : "");
+   dSprintf(buffer, sizeof(buffer), "%s %s(%s) {\r\n", getNewFunction(this),
+      getClassName(), getName() ? getName() : "");
    stream.write(dStrlen(buffer), buffer);
    writeFields(stream, tabStop + 1);
    writeTabs(stream, tabStop);


By the way: the default key for the particle editor (F9) needs to change, given that the debug render mode uses F9.

#1
11/13/2006 (10:24 pm)
Awesome. That was driving me nuts! Thanks for the fix.
#2
12/18/2006 (8:25 pm)
I get this warning with your fix:

c:\torque\sdk\engine\console\simbase.cc(467) : warning C4715: 'getNewFunction' : not all control paths return a value
#3
02/09/2007 (10:27 pm)
Yeah um disregard what I said earlier. Yeah, the secret was to actually ready and follow the instructions and it works extremely well then. Thanks.
#4
09/11/2009 (12:44 am)
This was marked for merge for 1.5.1 way back in the day (like two years ago) -- but 1.5.2 still doesn't have it integrated.
What gives?