Game Development Community

[SOLVED] BUG ALL ITGB VERSIONS - Serious Memory leaks on objects collisions system

by Edoardo · in iTorque 2D · 06/28/2010 (3:07 am) · 60 replies

Build: All iTGB versions

Platform: OS X 10.6.4, Simulator iPhone

Target: On Device and on Simulator

Issues: Serious Memory leaks on objects collisions system possible cause Dictionary.cc

Steps to Repeat:
1. Run "iphoneTest" project on simulator or on device
2. remove PUAP_SCRIPT_CHANGE definition.
3. run the game with leaks instruments
4. Click "bounce" on the game screen

Suggested Fix: The problem the dealloc of mHashTable into Dictionary.cc

------------------------------------------------------------------------------------------------------------------------------
Hi all,

I've discovered serious memory leaks on collition systems when i remove from definitions PUAP_SCRIPT_CHANGE... .I did the tests from version 1.1 to version 1.4 of iTgb (and all have the same problem)

In my game I've memory leaks of approximately 1 MB per minute... :-(

If anyone can solve it.... to recreate the problem simply install the "iPhoneTest", with leaks Instruments and use the bounce mode.

After a few minutes you will notice a significant loss of memory.

In a game like mine where there are many collisions per second causes a crash after a few minutes.

I can't use PUAP_SCRIPT_CHANGE because my game is based on PSK: www.torquepowered.com/community/forums/viewthread/112599/1#comment-733991

I USE IN TEST THIS DEFINITIONS:
__IPHONE__
TORQUE_PLAYER
TORQUE_RELEASE
TORQUE_DISABLE_MEMORY_MANAGER
PUAP_OPTIMIZE
USE_COMPONENTS

This is a screenshoot of my instruments :

www.iquilibriumstudios.com/screenshoot.jpg


#21
06/28/2010 (3:44 pm)
Edoardo, is the project in your first post based on stock iTGB? Maybe you could make it available for the IA guys to download and use as a test case?
#22
06/28/2010 (3:47 pm)
@Phillip

The project "iPhoneTest"? it is a standard test game relased by garagegames...
#23
06/28/2010 (3:48 pm)
Does that come with iTGB? Sorry, I've hardly touched iTGB =P
#24
06/28/2010 (3:50 pm)
It come with iTGB 1.2 or 1.3.1 you can download it....
#25
06/28/2010 (3:57 pm)
I've tried to remove all "#ifdef PUAP_SCRIPT_CHANGE" only from Dictionary.cc but the game after the default.png crash (EXC_BAD_ACCESS)... on the first passage in the method "delete mHashTable"
#26
06/29/2010 (1:37 am)
Edoardo, I think you are getting null pointers there ... you can try this code ... but I think you may have many more places to fix as well:

template<typename Key, typename Value>  
void tHashTable<Key,Value>::_destroy()  
{  
   // SWB - check for NULL
   if (mTable != NULL) {
      for (S32 i = 0; i < mTableSize; i++)  
          for (Node* ptr = mTable[i]; ptr; ) //<----This generate the EXC_BAD_ACCESS  
          {  
             Node *tmp = ptr;
             // SWB - check for NULL
             if (ptr != NULL) {  
                 ptr = ptr->mNext;
             }
             // SWB - check for NULL
             if (tmp != NULL) {
                  delete tmp;
              }  
          }  
         delete[] mTable;  
         mTable = NULL;
    }  
}
#27
06/29/2010 (1:45 am)
@Scott I already tried your code and "if (mTable[i] != NULL)" into for cycle... but nothing....

I think that exist a "Index of bound Exception" while cycle the mHashTable. ( I'm expert in Java language :-) ) but I'vent "Know how" in C++ to resolve this issue...

but have you tested this problem with instruments and iPhoneTest?
#28
06/29/2010 (1:59 am)
Edoardo, sorry I haven't tested it - I always build with the script optimize flag. It's odd it still fails because that loop shouldn't run if the table is empty - assuming of course that mTableSize is set correctly?
#29
06/29/2010 (2:09 am)
Scott, How Can I print the size of mTable?

printf("mTable size %d\n", mTable->??????);
#30
06/29/2010 (2:28 am)
The size of the table is kept in an external variable so you can print it like this:

printf("table size is %d\n", mTableSize);
#31
06/29/2010 (4:56 am)
@Scott when the game crash I've this result:

The size of this hashtable is 243351169

but it's abnormal?
#32
06/29/2010 (10:24 am)
That large number looks like mTableSize has not been initialized to zero to me, which is why the loop triggers. What happens if you set it to zero in the constructor ?
#33
06/29/2010 (10:28 am)
are these the constructors?

template<typename Key, typename Value> tHashTable<Key,Value>::tHashTable()
{
   mTableSize = 0;
   mTable = 0;
   mSize = 0;
}

template<typename Key, typename Value> tHashTable<Key,Value>::tHashTable(const tHashTable& p)
{
   mSize = 0;
   mTableSize = 0;
   mTable = 0;
   *this = p;
}
#34
06/29/2010 (2:01 pm)
Yep, I just looked at the code and it seems fine to me. I think we need somebody who really understands the complexity of the engine and how the dictionary works in optimize/non-optimize mode as I'm way outside my dabbling depth with this stuff ;-)
#35
06/30/2010 (3:23 am)
Phillip have you found a solution for this issue?
#36
06/30/2010 (3:46 am)
While I am keeping an eye on this thread, I am not actively trying to fix this issue. I don't believe it relates to the PlatformerKit itself.

However, if there is any part of my code that is identified to cause issue then I will dedicate time to rectify it.
#37
06/30/2010 (3:58 am)
@Phillip / @Michael

GarageGames must be modify the engine code to permit the optimal run without the PUAP_SCRIPT_CHANGE?

or

Phillip must be adapt the PSK to execute with PUAP_SCRIPT_CHANGE?

---------------

Be or not to be this is the problem!!!!

----------------

I've a serious problem with this issue I can't publish my game if i can't resolve this problem!!!!

Who should I contact to resolve this issue???????
#38
06/30/2010 (10:28 am)
The first one will not run.
PUAP_SCRIPT_CHANGE was implemented to make it run optimal for limited cache limited memory limited cpu environments like the iphone.

if it is a bug, then they need to fix it but otherwise its either up to Phillip or you to solve the shortcommings you are facing
#39
06/30/2010 (10:36 am)
I think that PUAP_SCRIPT_CHANGE is an optimization and it is "optional" but if you take it off should not cause problems.

For me the problem must be resolved from garagegames.... actually no one can port PSK on iPhone so it is NOT REAL that on the ITGB banner I see PSK running on iPhone with this issue
#40
07/01/2010 (1:31 am)
When I run my game on the iPad (iT2D 1.4 beta 2) it only leaks 1 or 2kB/minute. This isn't using PSK.