Game Development Community

dev|Pro Game Development Curriculum

Fixing the iTorque2D script stack (missing script variables)

by Drew Parker · 07/31/2012 (8:00 pm) · 4 comments

iTorque2D has a bug in the script stack, which under certain situations, can make function parameter script variables randomly disappear, thus breaking your game.

This resource provides a fix for this issue. It is tested on iT2D 1.5 but should work for all versions.


Overview of problem


Over time a number of people have noticed the problem of disappearing script variables in iTorque2D, both on the PC simulator and on the device.

www.garagegames.com/community/forums/viewthread/128264
www.garagegames.com/community/forums/viewthread/126306
www.garagegames.com/community/forums/viewthread/126820

The problem was introduced during an optimization pass for the iPhone. The optimizations were done with good intentions and deemed necessary at the time, but created unforeseen consequences.

Script variables can disappear at runtime (they become empty strings) or in the Torsion debugger. They can be local variables, but the most damaging ones are engine callbacks that have empty parameters, like onCollision() or onTouchDown().

If you have this problem, you'll know because your whole game will probably stop working, and you'll see a lot of console errors complaining about missing objects.


The answer


First, thanks to Michael Perry, Tim Newell, John Vanderbeck, Petr Vodak, and Hugo Matsumoto for their very informing posts. Otherwise, I would've had no clue what to do.

There are probably better solutions, but knowing how stable the Torque codebase has been for the past 8-9 years I've been using it, I decided to simply replace the low-level script stack processing code with Torque 2D (TGB) 1.7.6.

This 100% solved the issue for the project I'm working on.

The only drawback is iTorque will run a little slower on the device. For me, sacrificing a little speed for stability is definitely worth it.

Since this fix deals with low-level source code I would recommend for an experienced programmer to do the work for your project. However, the steps are fairly straightforward on the PC side.



Steps to fix


Since the files affected are low-level implementations and rarely changed for game logic, the easiest approach is just to copy over them with the working versions.

NOTE: consoleFunctions.cc is often modified by developers. Make sure you take note of any changes your team has made to this file before overwriting it. WinMerge is EXCELLENT for this type of thing.

(Thanks to Michael Perry and GarageGames for allowing me to redistribute the T2D 1.7.6 source files in this resource. It makes my life WAY easier.)


Step 1 - Delete some files


Delete the following files from your project:

/engine/source/console/Dictionary.cc
/engine/source/console/Dictionary.h
/engine/source/console/Namespace.cc
/engine/source/console/Namespace.h
/engine/source/console/Package.cc
/engine/source/console/Package.h


Step 2 - Replace some files


Download the .zip file iT2D_scriptStackFix.zip, and unzip it to this directory in your project and OVERWRITE the existing files:

/<MyGameDirectory>/engine/source/console/


The list of files you will be overwriting:

/engine/source/console/astNodes.cc
/engine/source/console/codeBlock.cc
/engine/source/console/codeBlock.h
/engine/source/console/compiledEval.cc
/engine/source/console/compiler.h
/engine/source/console/console.cc
/engine/source/console/console.h
/engine/source/console/consoleDoc.cc
/engine/source/console/consoleFunctions.cc
/engine/source/console/consoleInternal.cc
/engine/source/console/consoleInternal.h
/engine/source/console/consoleObject.cc
/engine/source/console/consoleObject.h
/engine/source/console/simBase.cc
/engine/source/console/telnetDebugger.cc
/engine/source/console/telnetDebugger.h


Step 3 - Update your project settings


Now, you need to do two things in your C++ project settings:
- remove the deleted files listed in Step 1 from your project
- remove a few Preprocessor definitions

Here we will cover the process for Visual Studio 2010 on PC.

Open the iTorque2DGame.sln file in this directory:

<MyGameDirectory> / MyProjects / <SomeProject> / buildFiles / VisualStudio2010


Remove deleted files from your project

From the menu, choose:

View -> Solution Explorer

In the tree pane, double-click the following entries to get to the right directory:

iTorque2DGame -> Source Files -> Console

Look for the files listed in Step 1, and delete them by clicking them then hitting the Delete key.


Remove the Preprocessor definitions

From the menu, open up the Property Pages dialog by choosing:

Project -> iTorque2DGame Properties...

In the new window, in the tree pane on the left go to:

Configuration Properties -> C/C++ -> Preprocessor

Click the drop down arrow for Preprocessor Definitions, and choose <Edit...>





www.drewparker.com/refimages/preprocessor.png




Delete these two lines from the list:

PUAP_OPTIMIZE
PUAP_SCRIPT_CHANGE

Now click OK.





www.drewparker.com/refimages/remove_definitions.png



Click OK to close the Property Pages dialog.



www.drewparker.com/refimages/configuration.png
NOTE: You need to do this part for ALL configurations you tend to use (dropdown box in upper left corner, typically Debug and Release).



Rebuild the project

Do a rebuild all from the menu:

Build -> Rebuild Solution


NOTE: You can also apply these fixes to the editor!


Open the T2D SDK.sln file here:

<MyGameDirectory>enginecompilersVisualStudio 2010

Now repeat everything from Step 3, except when deleting files from the project, instead of going to iTorque2DGame -> Source Files -> Console, go here:

TorqueGameBuilder -> Source Files -> Console



You're done!


The problem should be resolved on the PC simulator.

Now, you just have to update the same settings in XCode on Mac as you did in Visual Studio, and the problem will be resolved for all iOS devices too.

Good luck!
- Drew

#1
08/02/2012 (10:20 pm)
Excellent. Just to add that regarding the replacement of files, the best is always to have all the code base in a version control system (I use subversion with a trac web interface).
#2
08/10/2012 (5:32 am)
Thank you, looks good. We will try it soon...
#3
08/10/2012 (7:19 am)
Sorry some of the characters got garbled, like this:

<MyGameDirectory> / MyProjects / <SomeProject> / buildFiles / VisualStudio2010

It didn't show up that way in the preview!
#4
08/20/2012 (12:52 pm)
Hi Drew.
Thanks for this great thread!
I'll try it soon!