Page 1 of 1

"GE Must Close" & Insufficient Memory to Run Game

PostPosted: Tue Jul 07, 2009 6:04 pm
by sirmatthew
Ok...I've spent about a month coding this project and it's not yet complete, but I run it in game mode after each set of changes to make sure it's still working the way I imagine. Every so often I save it as a new file so I have backups of the work in progress and I'm up to file 23 now. I admit there was a learning curve and it took me about a week to grasp the basics of GE, but I'm really impressed with it. I'm sure there are more insights I could learn and I'm hoping some of you can enlighten me about an issue I'm having with GE.

There are no collisions of any kind in my project, but a lot of actors to serve as buttons and messages. There are also a lot of global variables which are dependent upon each other so they constantly change during game play. In that respect, it's math-heavy and I expect this game to be consuming a fair amount of memory. However, based on prior posts, I understand there shouldn't be much memory draw when actors are out of view. I've studied some of the demo codes and don't think my project is all that demanding as far as scripts go.

Out of nowhere I start getting errors when I go into game mode saying GE has encountered a problem and needs to close. Thankfully, the recovery option lets me get my work back. I keep trying to run the game and suspect a memory issue is causing me trouble. Sure enough, one time I get an error saying there is not enough memory to run the game. I went out and bought 1G more RAM and installed it on my PC. I tried running it again and keep having the same issues, even once getting the "not enough memory" error message.

The problem started after I added the "buy home" and "rent home" calculations. For some reason, that caused the "start career" button to trigger the error even though it worked before. Now the game won't even begin to enter game mode.

I've spent two days screening my scripts, replacing some if statements with switch statements, etc. Sometimes I even blocked out large pieces of code with // to see if that helps with the memory issue. Nothing seems to resolve it and I'm out of ideas.

Maybe I've gone about this project with the right idea but with the wrong logic? Surely there is a way to make this work.

I've attached the WinZip file which includes the .ged and data file.

A few questions:

When not using certain actors I move them off-screen, oftentimes pressing a button which quickly calls them back into view again. Would it be better for the memory usage to destroy those actors instead of moving them off-screen?

What are the primary problems associated with the "GE must close" error? Is it mostly a memory issue, a clash of code segments, too much scripting going on at once, etc.?

I'd appreciate any insights to get this project back on track. Thanks.

Re: "GE Must Close" & Insufficient Memory to Run Game

PostPosted: Tue Jul 07, 2009 8:11 pm
by jimmynewguy
i looked over it really fast, and i hate to say this but i couldnt find a problem. I guess your going to have to start from 22 :(
i tried deleting both of the two actors who were said to ruin it and nothing happened. hmmm...

Re: "GE Must Close" & Insufficient Memory to Run Game

PostPosted: Tue Jul 07, 2009 9:10 pm
by skydereign
I had to create a data folder, and insert a font with the same name as the one you were using along with all of the animations.

./gameEditor: malloc(): memory corruption: 0

Is the error that kills it... It isn't instantaneous, gets through two sets a frames, the create, which is probably the first frame and one after. It is really hard to look through your game, as there are so many events, many of them repeated, along with many actors and many variables. If you have 5 things needed to be triggered by one event, then use the script editor. It can do everything you have used it for, and all of them are right there. Also, if you have that many variables, and I see that you have very specific actors, you can use actor variables. This allows all actors to have their own value for the variable, and any actor can see it. Since you have these specific actors, all you would need to do to use them is actorName.variableName. It would be helpful to see your last working copy. I suggest using only script editor, that way you reduce the amount of events gameEditor searches for. Not positive, but if you have 6 mouse button down events, that could all be triggered by one event, gameEditor is looking 6 times, opposed to just once. Another trick, is to use clones instead of new actors. You can differentiate them by using cloneindex, and if need be, getCloneIdx. Then set there actions using switch. This way you don't have all of the repeat actors, though looking into your setup, you would need to do parent manipulation, or use create actor, and change parent there.
Code: Select all
switch(cloneindex)
{
    case 0:
    // code
    break;
    // and so on
}


Creating actors would help instead of having them all there, especially if they have a lot of events. You could also make them not receive events outside of view. You can still make the actors come into view, using events from those already in view. That way you are only dealing with those actors you can see, and gameEditor does not have to remember them.

Re: "GE Must Close" & Insufficient Memory to Run Game

PostPosted: Wed Jul 08, 2009 12:32 am
by makslane
The problem is in the buyAutoCalculations -> Draw Actor
You are trying to put in the text variable a text greater than 255 using the sprintf function:

Code: Select all
sprintf(buyHomeCalculations.text, "Based on your current personal settings, you wish to buy an automobile valued at $%i.\n%s\n%s\n%s\n\nThe total automobile price is %i.\nYou will obtain a loan against your credit line for the purchase.\nYour monthly payment will be %i and your annual interest payment will be %i.  This automobile will be paid in full in about 3 years.\n\nAs an automobile owner, your Fixed Expense level will increase by 10%.\n\nConfirm or Cancel this transaction by clicking the appropriate button below.", AutoAfford, StrNoAuto, StrNoAutoFunding, AutoAfford, tempBalanceDue, QautoPay, tempInterestAmount);


The strcpy function implementation in Game Editor take care of this issue and doesn't allow the game crash.
I haven't put this protection in the sprintf code!

So, make sure put no more than 255 chars in the text actor variable!

Re: "GE Must Close" & Insufficient Memory to Run Game

PostPosted: Wed Jul 08, 2009 7:49 pm
by sirmatthew
I guess this is one of those things that sneak up on you. The sprintf was working fine in earlier versions of my game, but it was under 255 characters then too. As it grew past 255, it also grew into a problem. Thanks for taking a look and pointing this out. Your advice was better than the Nutri-System diet as it allowed me to "get back in the game"! :lol:

Although it hurt to trash a lot of what I've built, sometimes you have to tear something down in order to rebuild it better. I backtracked and found another way of accomplishing the same effect without the heavy sprintf line. I ran with skydereign's suggestion to create actors to display the variable values individually and that is working really well.

Thanks again!!