Game Development Community

FIXED: GDB: Program received signal: "0" & Memory Leak (iTGB 1.2)

by Rob Stiles · in iTorque 2D · 08/25/2009 (6:24 pm) · 46 replies

Hi,

I have the beginnings of a very basic platform game here. I've not modified the engine at all, I'm not allocating memory anywhere in script (other than local variables) and I'm execing my scripts all in one place in startGame() in game.cs, at the beginning of the game (not in a loop somewhere).

I'm using the regular iTGB build target, either in Release or Debug. If I run the game and leave it, it'll crash after about 4 minutes. The debugger just says "GDB: Program received signal: "0"".

If I open Organizer in Xcode and choose the Console tab I see this:

Tue Aug 25 21:52:15 unknown SpringBoard[23] <Warning>: Memory level is urgent (9%) and there are no background apps to ask to exit.
Tue Aug 25 21:53:18 unknown SpringBoard[23] <Warning>: Application 'MyGame' exited abnormally with signal 11: Segmentation fault
Tue Aug 25 21:53:19 unknown ReportCrash[4565] <Error>: Saved crashreport to /Library/Logs/CrashReporter/LowMemory-2009-08-25-215318.plist using uid: 0 gid: 0, synthetic_euid: 0 egid: 0

The crash report shows this:

Incident Identifier: 045BD190-D071-4AFE-B9A6-774503A8F8C3
CrashReporter Key: 5fd95a1e842ebce7c3a80c9d86ed697359c11367
OS Version: iPhone OS 3.0.1 (7A400)
Date: 2009-08-25 21:53:18 +0100

Free pages: 251
Wired pages: 8773
Purgeable pages: 0
Largest process: MyGame

Processes
Name UUID Count resident pages
securityd <8266b85008779d1e28f2509e51d303cf> 90
MyGame <73c36f64f5d4332638d08e312ea9aa84> 11744 (jettisoned) (active)
debugserver <b79865bab3ea06747ce03eaa9f7b7a8f> 109
DTMobileIS <a541ccb799a4e87cb10636268ab1b87b> 1238
notification_pro <09df4bf987a6baaa3e77192c4026bc5e> 61
syslog_relay <4adc9d69d534cb0be0649055b2188c4e> 62
notification_pro <09df4bf987a6baaa3e77192c4026bc5e> 62
notification_pro <09df4bf987a6baaa3e77192c4026bc5e> 62
afcd <08d114ca35c3e862bdb56df371c5d197> 64
ptpd <e1c6f82741b354c1086e373473131824> 172
MobilePhone <9517d3db1b487371c5a64e41bfd19eda> 589 (jettisoned)
debugserver <b79865bab3ea06747ce03eaa9f7b7a8f> 82
debugserver <b79865bab3ea06747ce03eaa9f7b7a8f> 82
mediaserverd <cc588f963f30bd34296bf8beeb803f8a> 435
SCHelper <fb330a127ccd71984188d2ce28d62716> 94
BTServer <3ae1c6fbcb29741b4a609b02f3c5a127> 178
iapd <3204da63503dec0812fa062678c61743> 246
notifyd <69e04d13344f1c006227422dbf18dde8> 108
CommCenter <e2b77989cdd88779b25322e1ef82b126> 419
SpringBoard <e0166bb2d42cbc489ace07849c959088> 2987 (active)
configd <2950435c092830011e402b4ac8ea86fe> 71
configd <2950435c092830011e402b4ac8ea86fe> 295
fairplayd <ec3c2c10efbb2e7a7b9d7130ecb1e2c6> 73
IQAgent <0c8ec49a509e684ffd4cae7729e2dcc9> 155
mDNSResponder <21273afce237d1ff8e79ab819a130e3c> 110
lockdownd <374e220ffb0f06ac0f7aa024a979e31f> 366
syslogd <4eae063fb35192e82cf5c47df1063443> 83
launchd <09ab79ab1b390e1fee1309f58948f17c> 105

**End**

It seems fairly obvious it's a memory leak but where from? I'm hoping other people here have had the same problem and fixed it - it must be a common thing since i'm using a virgin iTGB 1.2. I've only just bought it and I promise I've not changed any source code!
Page «Previous 1 2 3 Last »
#1
08/26/2009 (1:40 pm)
The same game works fine on 1.1 and I'm not seeing a memory leak, so it must be something in 1.2 methinks.
#2
08/26/2009 (6:00 pm)
I decided I'd rather use the latest and greatest offering so I thought I'd revisit iTGB 1.2. I recompiled TGEGame with PUAP_OPTIMIZE and PUAP_SCRIPT_CHANGE so the options set are now

__MACOSX__
TORQUE_DISABLE_MEMORY_MANAGER
TORQUE_PLAYER
TORQUE_RELEASE
PUAP_SCRIPT_CHANGE
PUAP_OPTIMIZE
USE_COMPONENTS

I *may* have added the 'R' on to the end of TORQUE_DISABLE_MEMORY_MANAGER. There was a typo in some of the projects. Mostly on release configs but I can't remember which ones.

Then I opened the Xcode_iPhone project and switched to the iTGB_Script_Optimize target. In release build I made sure these were set:

__IPHONE__
TORQUE_DISABLE_MEMORY_MANAGER
TORQUE_PLAYER
TORQUE_RELEASE
PUAP_SCRIPT_CHANGE
PUAP_OPTIMIZE
USE_COMPONENTS

I'm pretty sure I added the 'R' on the end of TORQUE_DISABLE_MEMORY_MANAGER this time.

Then I made sure Compiler Version was set to GCC 4.0 and under Linking I changed C++ Standard Library Type from Static to Dynamic.

I also set my iPhone OS Deployment Target and Base SDK to iPhone OS 3.0. You probably don't need to do that but I'm mentioning it anyway. If you're having trouble compiling for 3.01 even though you have the latest non-beta iPhone SDK then you may need to create a symbolic link from your Terminal / shell.

cd /Developer/Platforms/iPhoneOS.platform/DeviceSupport
ln -s 3.0 3.0.1

I don't have the big memory leak any more :)
#3
08/27/2009 (1:36 am)
It's actually required (or recommended strongly, mafia-style ;) by Apple to build against SDK 3.0, no matter what your deployment target is.

Glad you figured it out - the symlink thing is listed right at the top of the official iPhone entry page AND the forums at apple.com. I recommend (strongly ;) that people visit Apple's forums now and then to get an update on new bugs, or sort out provisioning problems. The latter is usually problem #1, once you have compiling sorted.
#4
08/27/2009 (5:43 am)
Wow, Thanks for this Rob. It's just saved me waiting for iTGB 1.3!

No more memory leaks! GREAT!
#5
08/30/2009 (9:18 pm)
@John and Rob: What settings did you use to get this all to work right? Whenever I try and run my app compiled in anything except for iTGB_Optimize, the game instantly crashes with "EXC_BAD_ACCESS".
#6
09/01/2009 (6:29 am)
You have to compile TGBGame with the __MACOSX__ settings that were given above, TGBGame is the normal Xcode project and not the Xcode_iPhone project.

This will give you the basis for your game, if you copy your resource and common folders and Main.cs into this folder and then run the game with the TGBGame.exe, this will compile the game with the PUAP_OPTIMIZE and the other flags which allows your game to run with the iTGB_Script_Optimize settings. and no more memory leaks!

I always have to play through the game and make sure every level loads otherwise i get the 'EXC_BAD_ACCESS' error when it changes level. I guess this is because it compiles some things when a level loads, still unsure why I have to do it, but it works.
#7
09/01/2009 (10:08 am)
@John

You need to execute the levels because they are not compiled by default at startup.

You can get around this with this little bit of code added to game.cs (or anywhere that gets executed at startup).

Note I'm not the original author of this bit of code, I found it here: http://www.garagegames.com/community/forums/viewthread/95945

//---------------------------------------------------------------------------------------------
// Force script compilation
//---------------------------------------------------------------------------------------------
function compileScripts( %path ) {    
     //setModPaths( %path );    
     %search = %path @ "*.cs";    
     for( %file = findFirstFile(%search); %file !$= ""; %file = findNextFile(%search) ) {    
        if( $echo ) {    
           echo( "Compiling" SPC %file @ "..." );    
        }    
       compile( %file );    
       $CompileCount++;    
    }    
        
    %search = %path @ "*.gui";    
    for( %file = findFirstFile(%search); %file !$= ""; %file = findNextFile(%search) ) {    
        if( $echo ) {    
            echo( "Compiling" SPC %file @ "..." );    
        }    
        compile( %file );    
        $CompileCount++;    
    }    
    %search = %path @ "*.t2d";    
    for( %file = findFirstFile(%search); %file !$= ""; %file = findNextFile(%search) ) {    
        if( $echo ) {    
            echo( "Compiling" SPC %file @ "..." );    
        }    
        compile( %file );    
        $CompileCount++;    
    }    
  
}   

// If we're in the editor, compile everything
if( $platform !$= "iphone" ) {    
    compileScripts( "common" );    
    compileScripts( "game" );    
}
#8
09/05/2009 (4:55 pm)
@Rob
Sorry, but I don’t get where you enter these options? Which scripts?
Any help on this would be handy thanks as I’m sick of my game crashing every 20 mins.
Thanks again for posting this as it will help so many people.
#9
09/05/2009 (5:27 pm)
Hi Mike,

You need to open up the Xcode_iPhone project.

In the top left of the project window you'll see 2 drop down menus - Active Target and Active Build Configuration. I was playing with iTGB_Script_Optimize in Release build so set Active Target to iTGB_Script_Optimize and Active Build Configuration to Release.

On the Project menu you'll find Edit Active Target "iTGB_Script_Optimize". Choose that and an info window will pop up. Make sure the Build tab is selected. The options I mentioned are all in there. The #defines like TORQUE_DISABLE_MEMORY_MANAGER are in the Preprocessor Macros.


#10
09/05/2009 (9:27 pm)
First of, thanks a hell of a lot for helping with this problem.

Secondly though I feel like I'm not really getting it. I'm getting the same error as Dave with the "EXC_BAD_ACCESS".

I think this may be because I have no idea what you're talking about in the first bit where you talk about how
"I recompiled TGEGame with PUAP_OPTIMIZE and PUAP_SCRIPT_CHANGE so the options set are now".

I don't know where you did all that stuff. I read what John said about it but that just confused me more. I really want to get this figured out because its the only thing stopping me from submitting my game.

Also do you guys get like 5000 warnings when you compile like this?

EDIT:
I finally got it to work by reinstalling it a couple times, rebuilding it yadda yadda. Thank you so much for working on this. This thread should be stickied and included in the official documentation. At least until 1.3, whenever that occurs. I'm a little alarmed that GG didn't give 1.2 a quick update to deal with this.

One last thing, I think GCC is required to be 4.2 by apple. Can someone tell me if I'm wrong about that, because so far I'm loving this fix.

#11
09/16/2009 (4:25 am)
This all seems cool in theory, but I'm having no luck at all here. I've reinstalled, rebuilt, cleaned, rebuilt, reinstalled, cleaned, cleaned, cleaned some more, rebuilt some more, but no matter what, I still get EXC_BAD_ACCESS as soon as the game goes to run. I also can't compile for OS 3.0 - I get over 350 errors.

Here is what I am doing.... maybe someone else can point out where I'm going wrong:

1.) Open up the TGBGame project.
2.) Go to "Project -> Edit Active Target "TGBGame".
3.) Go to the Build tab.
4.) Change the Compiler Version to GCC 4.0
5.) Change the 'Linking' to Dynamic.
6.) Scroll down to the Preprocessor Macros. These were blank for me, so I double clicked the entry and filled it out to read as follows:

__MACOSX__
TORQUE_DISABLE_MEMORY_MANAGER
TORQUE_PLAYER
USE_COMPONENTS
PUAP_OPTIMIZE
PUAP_SCRIPT_CHANGE

7.) Do a full Clean All Targets.
8.) Delete the Build Directory.
9.) Delete the Game and Common folders in the project.
10.) Reimport the Game and Common folders in the project.
11.) Do a full Clean All Targets again.
12.) Delete the build directory again.
13.) Build and Go.
14.) Run the game for a bit. Go through the various levels. Make sure everything works.
15.) Close XCode.
16.) Open XCode with the iTGB project.
17.) Make sure that iTGB_Script_Optimize is selected, and Release.
18.) Go to "Project -> Edit Active Target "iTGB_Script_Optimize".
19.) Go to the Build tab.
20.) Change the Compiler Version to GCC 4.0
21.) Change the 'Linking' to Dynamic.
22.) Scroll down to the Preprocessor Macros. Fill these out to read as follows:

__IPHONE__
TORQUE_PLAYER
TORQUE_RELEASE
TORQUE_DISABLE_MEMORY_MANAGER
PUAP_SCRIPT_CHANGE
PUAP_OPTIMIZE
USE_COMPONENTS

23.) Do a full Clean All Targets.
24.) Delete the Build Directory.
25.) Delete the Game and Common folders in the project.
26.) Reimport the Game and Common folders in the project.
27.) Do a full Clean All Targets again.
28.) Delete the build directory again.
29.) Build and Go.
30.) When the game launches on your iPhone, it will instantly crash with an EXC_BAD_ACCESS error.

I'm assuming step 30 is not the expected step. ;)
So... what am I doing wrong here? Feeling a bit left out at this apparent awesome, hairline redefining change that on my end only seems to break the project to the point it won't even run, LOL...

Thanks for any help anyone can give!
#12
09/16/2009 (6:12 am)
Hi Dave. I really don't know why they were blank for you in step 6. Were they blank for you in step 22 as well?

I've never actually had the EXC_BAD_ACCESS error - these steps are what I took to fix a large memory leak that I was having when my game was running on the iPhone.

Incidently, I seem to be able to compile using GCC 4.2 perfectly fine as well (again, by setting the linking to 'Dynamic').
#13
09/16/2009 (2:01 pm)
GCC 4.2... okay, trying that.

Are you also compiling the MacOSX version with GCC 4.2? I'm wondering because that gives me 1307 errors....
#14
09/16/2009 (2:02 pm)
can't compile with gcc 4.2 unless you only want to support OS 3.0 and higher.
#15
09/16/2009 (2:40 pm)
Ah. Okay. Compiling for OS 3.0 gives me over 300 errors anyway, so I guess that's not a good idea with iTGB1.2, lol.
#16
09/16/2009 (4:06 pm)
Apparently now I've managed to break it even further, lol. I now get over 7000 errors when trying to compile for iTGB_Script_Optimize.

Okay. I'm burning way too much time on this. Who has already gotten this to work and wants to make $50 and take a look at my project and see what I'm doing wrong?

Specifically, I'm paying for someone to...

- Fix my project so it will compile for OS 3.0 using the iTGB_Script_Optimize setting in Release mode, using the tweaks listed in this thread to help reduce the memory leaks I am seeing in my game, and when finished explain to me what was done so I know what I was doing wrong.
#17
09/16/2009 (5:09 pm)
@Dave to compile 1.2 for OS 3.0 all you need should be in the top of this thread. Anything missing should be trivial from the message shown.

http://www.garagegames.com/community/forums/viewthread/91531

#18
09/16/2009 (7:37 pm)
@Bret: After going through those, I'm now getting 381 errors, mostly about the AbstractClassRep. I'm getting the exact problems as described in this thread:

www.garagegames.com/community/forums/viewthread/89841


Update: Though I'm noticing that I'm getting "extra qualification" errors also on the TiXmlDeclaration, which is listed in the 3.0 post. I'm not familiar with what this means however... anyone mind giving me a quick overview on what they are saying needs fixed?
#19
09/16/2009 (11:46 pm)
Ok! Some progress. I've now got it compiling for OS 3.0 in GCC 4.2 with 0 errors! The game still does not run, however. It runs 'maininit' then instantly crashes with EXC_BAD_ACCESS.

Hrm... so what are the reasons that an iPhone app could crash with EXC_BAD_ACCESS? We know it's not timing out during the load because it's running through XCode, and the exact same game will load if I compile for iTGB_Optimize using Device 2.1. So what's different here that consistently causes an EXC_BAD_ACCESS crash...
#20
09/17/2009 (12:25 am)
debugger should show you the bad line when it crashes. only thing is if it's a script call then it's nearly impossible to figure out what the hell it's complaining about.
Page «Previous 1 2 3 Last »