Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / !! Critical bug - variable corruption !!

Author
Message
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 10th Aug 2013 23:15
Many weeks ago, I have had this particular bug reported by a beta tester and didn't make a huge effort to track it down at the time.
I have since had the same inexplicable error where a global variable obtains an unexpected value.
When I experienced it myself, I have been very thorough in locking it down.

The following global variables are declared in the main unit:



The ONLY place where e.g. "HumanoidsInWorld" is incremented is in the createHumanoid() function.
I wrote out to a log file when code in the function was executed (logged from within the function).

Next, I had to play around in the game for about 10 minutes killing humanoids until the amount left was 0 and restarting, trying again.

Eventually, at an arbitrary amount left (maybe 2) the variable now contains 6! Checking my log file, there is only the expected evidence that the initial 10 were created as expected.
There is no other code where these variables are incremented.

Now, I put this down to a compile error initially (I have seen this before where certain datatypes aren't on certain memory boundaries etc, but it can happen intermittently here on the same compile).

There is a complex structure preceding these global variables:



(and quite a lot more dimensional declarations above that).

I don't see this corruption anywhere else apart from this bunch of variables.
I've checked that I'm not overflowing my arrays (and anyway, won't that raise an exception anyway?)

This has been happening for months, but I've never dug into it until now. I don't write repeatedly into the preceding variables (only at load time). Anyway, I doubt if the variables are stored in the same order in memory as they are in my code.

I'll do some more testing, examine the frequency as well as try the same debug on the surrounding variables.
I'm on 1.08.14 now, but this was happening back at 1.07.6 as well.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 10th Aug 2013 23:32
Do you initialise the globals before you use them? Uninitialised variables can contain junk data and so one should never assume they're set to 0 upon declaration. Always make it explicit (assign them a value) before using them.

nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 10th Aug 2013 23:36
Yea, good idea. However, the variable in question has plenty of other values in it over time.. 10,9,8,7 etc. before going wrong.
I'll definately initialise them to zero to make sure.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 10th Aug 2013 23:52
The other thing is to check for typos. One thing I don't like about the basic language is that a typo = new variable and that can throw a spanner in the works if you didn't mean to create a new one. I've been bitten by it a few times.

nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 11th Aug 2013 00:29
Yea, me too.
Give us strict var naming in AppGameKit!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Aug 2013 09:18
Explicit variable declaration as an option was suggested ie. the option to enforce it. Maybe it could be requested as part of the new IDE if enough of us wanted it?

Anyway, back to your problem. Could you share the function containing the increment? One thing I did notice was the 64x20 in your array declaration, try changing that to 1280 maybe? It's vaguely possible this might screw something up.

Doesn't really sound like a compiler error to me though, not questioning your testing/code it just doesn't sit right with me.

If GetDayOfWeek()=5 then initParty()
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 11th Aug 2013 11:23
nz0,

Ive seen some issues like this before. As a test, highlight your entire code, then use the built in replace function of the ide to change the variable name to something completely different (best work on a backup here).

Another good option is to have a text object on screen and every loop update it to be the value of the variate you wish to check.

Finally, and this only works if the variable generally only changes by one per code loop, but at the very start use a temp variable, such as oldhumanoidsinworld, and make it equal the normal humanoidsinworld variable. Then periodically throughout your main loop put in a check to make sure the two variables are not more than 1different to each other, highlighting a unique message for each check if it is different ("error, updating enemies", "error, updating score" etc). Once the code is picking up the unexpected change, put more and more of these checks in until you find the specific point that it's changing. Once you have that, sometimes simply changing the structure of the code fixes it (I think agk/android does some stuff in the background or threaded, and timing very occasionally seems to be an issue).
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 11th Aug 2013 13:16 Edited at: 11th Aug 2013 13:17
my Explicit variable declaration workaround
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 11th Aug 2013 14:01
There was an issue in the past with compound function calls losing passed data, since this I have tended to use intermediate variables just in case.

eg, Replacing something like;

with;

These can be recombined down during optimization if necessary.
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 13th Aug 2013 23:26
Thanks all.
It appears to have gone, but I've used a combination of the suggestions here and not too keen to go searching for the exact cause now as it takes ages to debug it.

I'm very aware of the lack of strict var names and it will worry me for ever until that's changed.

cheers for the various ideas!

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 13th Aug 2013 23:38
I like strict. That's one reason I haven't used Basic since about 1979. Loose typing imposes a much higher level of discipline on the programmer. I much prefer to have the compiler fail to compile and tell me why than have it cheerfully carry on and produce obscure run-time errors.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 13th Aug 2013 23:49
Definately Jim. That's why I love delphi

Also, I really like free basic, as this has optional strict var defs and delphi like procedure and function definitions.

You can also call c funcs and use inline assembler. Funny, I stopped using it a couple of years ago, but I always fancied writing a game in it.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 14th Aug 2013 00:20
nz0 - If you like Delphi, why not use AppGameKit for Pascal and completely sidestep the problems with AppGameKit (or any other) Basic?

I get a little annoyed with the idea that Basic is "easier." It isn't, because everything is effectively a variant.

Pascal:

var X1 : integer;

X2 := 4.5;

ERROR - not declared.

Basic
X1 as integer
X2 = 4.5

Basic - no error. X2 is now a float. We didn't mean that, but we made a typo. References to X1 will probably contain zero.

If you see what I mean. As many errors as possible should be caught by the compiler.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 14th Aug 2013 00:22
Quote: "X2 is now a float"

Actually, X2 is an integer, containing 4

X2# would be an undeclared float...

nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 14th Aug 2013 00:26
I know what he meant

I thought about AppGameKit for pascal, but I don't have the right delphi.

I still have Delphi 5 enterprise!

Also, I would be a little worried about the future support etc. I did see somewhere about a free pascal compiler which could be used with it, but I wouldn't want to convert in the middle of a project.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 14th Aug 2013 00:27
Thanks, Mobiius - That illustrates the point beautifully. Can you really assign a truncated FP value to a mistakenly referenced non-existent variable? Even more stupid than I thought.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 14th Aug 2013 00:29
ooh mobiius - you into performance cars?
Just clicked on your website link.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 14th Aug 2013 00:39
nz0 - Free Pascal Compiler is - errr - free. If you haven't used Delphi since D5 you're just a teeny bit behind the times!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 14th Aug 2013 00:44
Well, I still write stuff with D5 even now. My world highscore web server is powered by D5 and I still write various tools with it. I will probably write the level designer for my current game with it too.

My company still has systems developed in D5, but they are all going end of life at the moment (I have to support a lot of them as there's hardly any of us left to do so!)

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 14th Aug 2013 09:55
I understand. My main language lab is in D7 - I have a computer dedicated to it and remote-desktop into it to update stuff. New stuff uses XE3.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 14th Aug 2013 21:15
Quote: "ooh mobiius - you into performance cars?"

Indeed I am! (I own far too many cars... )

Login to post a reply

Server time is: 2024-11-24 17:30:22
Your offset time is: 2024-11-24 17:30:22