Page 1 of 1

Importance of debug.txt

Posted: Thu Dec 18, 2008 1:49 pm
by cypher1554R
I just want to say that sometimes.. or most of the time, I is dumb as hell.
I spent last 4 days figuring what the heck is wrong with my editor all the sudden working like FDR's legs ( :shock: too soon?).
Well anyway.. Today it just came to my upper part of the body (which looks like a head, except there's not much in it) that I should check my debug.txt file, which I worked so hard on to get every detail in most descriptive way out. In just a few seconds I found the bug. It was a messed up -assign- operator that I wrote for Vec3 class.

There. If you don't use this or some other kind of method, you should start right now. Cause after 5000 lines, you is going to be blind as a bat. And I'm not talking about that creepy animal. I'm talking about the fat stick that is used in baseball game.

Re: Importance of debug.txt

Posted: Thu Dec 18, 2008 2:09 pm
by trufun202
Speaking of debugging with txt files...

A friend and I were having a friendly argument about one of our apps at work. I was trying to prove him wrong, and if a particular error occured, I logged the error and created a file called "KentSucks.txt"

Well..months had gone by and we forgot about this little "feature"... So, we're in the client's office setting up the application. After hours of pounding our heads against the wall, trying to figure out why it's not working - someone on the client side said, "Hey, what's this KentSucks.txt file do!?"

Problem solved! :mrgreen:

Re: Importance of debug.txt

Posted: Fri Dec 19, 2008 12:36 pm
by dandymcgee
I always use some sort of debug when I can't get something to work. If I want it there permanently I use a text file, otherwise I use console output or main()'s return value.

Re: Importance of debug.txt

Posted: Wed Dec 24, 2008 3:00 am
by Arce
I enable debugging via environmental variable. That way I simply change a value before distributing to the team. (my dubug stuff is quite messy, though it's intended for my eyes only. ;P)

Re: Importance of debug.txt

Posted: Wed Jan 14, 2009 9:37 am
by aamesxdavid
So I was about to post a new thread in regards to the mention of it in the Adventures videos, but I figured I'd revive an older thread instead.

Falco mentions that the text file they use logs every file the game is trying to access, etc. I was wondering how exactly that was done, and if a similar thing is possible in Python, which is what I'm currently working with. I can write to text files, but the only thing I know of dealing with an error is the "try" and "except" functions in Python. Assuming that every file load doesn't have a "try" (or the C++ equivalent) and individually write to the text file, how is this file written? I don't mind if you only have the C++ answer, as it's more of the programming theory that I'm looking for I suppose. Thanks!

Re: Importance of debug.txt

Posted: Wed Jan 14, 2009 9:51 am
by ismetteren
I dont know how falco handles it, and i dont know how phyton handles files. In C++ a file is represented by a stream (fstream, ifstream of ofstream).

You can create a ifstream(inputStream) object, and then open a file with it(i guees you actully just tells i were to read data from, but i am not sure)

Code: Select all

ifstream stream;
stream.open(file.txt);
now you can do something like:

Code: Select all

//i am not sure if this is correct, but it works atleast very simmilar to this
string txt;
getline(stream, txt);
To write out witch file the code is accessing, you could have made another file stream before this code, and output the file(as a string(the pathname)) that was being opened(file.txt) to it. If you wanted to know if it was successful i guess you could check if stream hat an valid file open, and output if it (not)hat.

I am not sure if that was what you meant. And sorry for my bad english

Re: Importance of debug.txt

Posted: Wed Jan 14, 2009 11:50 am
by MarauderIIC
aamesxdavid wrote:So I was about to post a new thread in regards to the mention of it in the Adventures videos, but I figured I'd revive an older thread instead.

Falco mentions that the text file they use logs every file the game is trying to access, etc. I was wondering how exactly that was done, and if a similar thing is possible in Python, which is what I'm currently working with. I can write to text files, but the only thing I know of dealing with an error is the "try" and "except" functions in Python. Assuming that every file load doesn't have a "try" (or the C++ equivalent) and individually write to the text file, how is this file written? I don't mind if you only have the C++ answer, as it's more of the programming theory that I'm looking for I suppose. Thanks!
I get what you're saying. We have a Debug class (I think it's a singleton) with a function that works like fprintf() does. Debug is initialized like so:

Code: Select all

void Debug::Initialize() {
    debugFile,open("debug.txt", ios::out); //Clear the existing file or create a new one
    debugFile.close(); //Don't leave it open (we might not actually do this, see end of post)
}
We also have a function that works like printf does in Debug, so then, for instance, our Level::Load is something like

Code: Select all

Debug& debug = Debug::GetInstance();
levelFile.open(filename...);
if (!levelFile) { //there was some sort of error while opening the file
    debug.write("Error loading %s\n", filename);
    return ERROR; //where error is just some constant or error code or something
}
...
if (!(something = new Something)) {
    debug.write("Out of memory!\n");
    return ERROR;
}
Our write() fn would open debugFile for append (ios::app) and then close it after writing to it. This is terribly slow. It would be faster to open the file once and then close it when the program terminates. Which we might actually do, I'm not totally sure anymore :)

We just write to it when something doesn't go our way, in other words, and the Debug class handles the file I/O. We don't do anything with exceptions, which is what try { } except { } says to me, but you would basically do the same thing but in your except block instead of with ifs.

Hopefully I answered your question. If you want to see how to do an ellipsis function (replace like %s with an argument, no definite number of arguments passed to the function), I can help you with that. Also, sorry for the ambiguity, I'm too lazy to open the source :D

Re: Importance of debug.txt

Posted: Wed Jan 14, 2009 12:57 pm
by aamesxdavid
Wow, that's awesome, thanks guys! I'll be doing some Python tests with this tonight. This is the kind of stuff I need to work on, because I get the syntax and general flow of things, but I wouldn't have thought to make a class to handle it. Well, I'm a step in the right direction now. :)

Re: Importance of debug.txt

Posted: Wed Jan 14, 2009 1:55 pm
by MarauderIIC
aamesxdavid wrote:So I was about to post a new thread in regards to the mention of it in the Adventures videos, but I figured I'd revive an older thread instead.
Thanks!
aamesxdavid wrote:Wow, that's awesome, thanks guys!
You're welcome =)

Re: Importance of debug.txt

Posted: Wed Jan 14, 2009 4:56 pm
by eatcomics
MarauderIIC wrote:
Gyrovorbis wrote:eatcomics could single handedly destroy the universe
What's that all about... I don't want to destroy it I want to rule it :mrgreen:
But seriously where did that come from???

Re: Importance of debug.txt

Posted: Wed Jan 14, 2009 6:26 pm
by MarauderIIC
eatcomics wrote:
MarauderIIC wrote:
Gyrovorbis wrote:eatcomics could single handedly destroy the universe
What's that all about... I don't want to destroy it I want to rule it :mrgreen:
But seriously where did that come from???
Staff forum. Old post talking about horrible typing =)

Re: Importance of debug.txt

Posted: Wed Jan 14, 2009 9:34 pm
by Falco Girgis
Yeah, Marauder broke it down pretty much exactly as it is.

And currently (until we're ready for release) the debug output is also wrapped back to the Adventure Log (in game text box) so that we can see our debug output during run time without having to exit out. (That's why there's lots of random numbers outputting sometimes during AiGD videos. Debug is also wrapped to Lua, and that's Peter's cout/printf() equivalent).

And welcome! (though I've seen/talked to you already!)

Re: Importance of debug.txt

Posted: Thu Jan 15, 2009 4:35 pm
by eatcomics
MarauderIIC wrote:
eatcomics wrote:
MarauderIIC wrote:
Gyrovorbis wrote:eatcomics could single handedly destroy the universe
What's that all about... I don't want to destroy it I want to rule it :mrgreen:
But seriously where did that come from???
Staff forum. Old post talking about horrible typing =)
Ahhhh....
Gyrovorbis in those days I could have taken over hell if I wanted to :mrgreen: :lol: