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.

DarkBASIC Professional Discussion / DBP 'forgetting' variables (take two)

Author
Message
Jambo B
16
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 11th May 2010 21:22
Posted this in the wrong board initially, I'm looking for advice on my most frustrating and headbanging fight with DBP v1.074: it's been 'forgetting' variables.

It seems to have happened since my project got larger than 3500 lines. Take the code below:



Pretty simple, and worked OK. Until today, that is. Passing "cmdpass" and "cmdreturn" both give the result '6'. How can that be? I tried replacing the select..case statements with if..thens but this had the same effect.

Also, when the main prog called this function, and tried to do something with the result...



...the IntParm2 var would reset to zero at the IF statement! (it wasn't zero before the IF - I printed it!)

I'm quite an old hand at this programming lark; I know what I'm doing; and to me there seems to be some sort of corruption going on behind the scenes.

I am jumping up and down with frustration while typing this

Does anyone have any advice on how to combat this problem? Is it a known issue? (I've searched the bug forum)... Eee, I dunno.

Thanks

James
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th May 2010 22:16
Quote: "I know what I'm doing"


Where've I heard that before?

Quote: "and to me there seems to be some sort of corruption going on behind the scenes"


I'm sure you're right - and tracking down that sort of problem can be hard work.

There used to be a bug in functions where strange results occur if variables are not explicitly initialised in the function. That bug may have been fixed, but I'm not sure. In case it hasn't I'd suggest you make sure that every variable is initialised correctly. For example, avoid things like:



What happens if you call



for example?

The symptoms you describe usually indicate that the wrong bit of memory is being modified. That's hard to do usually, but there can be situations where an error isn't detected at run-time. IanM probably knows more about the details of this sort of thing.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 11th May 2010 22:51
What I'd advise first is that Jambo downloads my plug-ins ( ) and uses the logging plug-in to record within that function every time it gets called, what it's input parameters are, and what it's return value is.

http://www.matrix1.demon.co.uk/Matrix1Utils_Help/Matrix1Util_10_index.html
Use 'OPEN LOG "filename.txt"' to open the log file.
Use 'WRITELN LOG "%d %s", iTheVarNumber, VarName$' just before you return.

I'd also suggest changing 'iTheVarNumber as integer' to 'local iTheVarNumber as integer' in that function too, just to eliminate the possibility of it being affected by a global with the same name.

Visigoth
21
Years of Service
User Offline
Joined: 8th Jan 2005
Location: Bakersfield, California
Posted: 11th May 2010 23:31
the function works fine as stand alone, on my end anyway. And if you put in gibberish or just "", it returns 0.
So, it makes me think that the input variable is getting set to "cmdPass" prior to the call. Do like IanM suggested, his plugins are fantastic. Lots of very useful stuff in there.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th May 2010 09:55
I'd insert this just to be safe...



My signature is NOT a moderator plaything! Stop changing it!
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 12th May 2010 15:00
You know, I'm starting to wonder if there's a bug with typed arrays. I've been dealing with a bug for about a week that I just can't fathom, and have thought a few times that it could only be internal. Basically a 2D, typed array I'm using keeps getting set, almost like the values are somehow remembered then resurrect to the previous values when changing them. Weird. I'm gonna do more experiments tonight, then go the whole hog and swap to non-typed arrays, if that resolves the issue then it could only be internal.

I'm sure I'm using the latest update. The last game I did was in the same update, but I don't think I used types in that, the game was a lot more straightforward and never needed very complex data storage - I had no issues with arrays in that at all. Maybe it happens if you have more than one typed array, like the may overlap!, something crazy like that is my bet.


Health, Ammo, and bacon and eggs!
Jambo B
16
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 13th May 2010 22:48
Thanks everyone for your replies; I'll try the plugins, er, plugged by IanM

Spent a whole day trying to track down this bug or work around it. Every time I thought I might be getting somewhere, it blindsided me in some other way.

There's a handy pond at the bottom of my garden that I might just chuck DBP into. I wonder when the next update will happen, and if this heinous variable problem will be fixed.

*sigh* <frustrated>
Jambo B
16
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 13th May 2010 22:52
Quote: "GG: Where've I heard that before? "


Haha! Touché sir!
Jambo B
16
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 15th May 2010 18:00
Just a follow-up to this, in case anyone else is having the same problem. The 'local' declaration seems to have done the trick.

I'd also like to add that IanM's Matrix plug-ins are fantastic

Login to post a reply

Server time is: 2026-07-26 04:28:17
Your offset time is: 2026-07-26 04:28:17