PDA

View Full Version : Unknow General exception..



M109uk
26-07-2004, 01:33 PM
Hi all,

I have a bit of a weird problem,
i have a basic debugger unit that i use with my games engine, it works fine but when ever i turn the debugger off it causes a general exception, but works fine when it is on.

The debugger is just a Stringlist with functions to write to it.

Debugger unit:

uses
Classes;

var
Log: TStringList;
LogFilename: String;
LogInitialized: Boolean = False;

..

procedure IintializeLog(const Filename: String);
begin
LogFilename := Filename;
Log := TStringList.Create;
If FileExists(LogFilename) Then DeleteFile(LogFilename);
LogInitialized := True;
LogDetails;
end;

procedure OpenLog;
begin
If Not LogInitialized Then Exit;
If FileExists(LogFilename) Then Log.LoadFromFile(LogFilename);
end;

procedure CloseLog;
begin
If Not LogInitialized Then Exit;
Log.SaveToFile(LogFilename);
end;

procedure WriteToLog(const Value: String);
begin
If Not LogInitialized Then Exit;
OpenLog;
Log.Add(Value);
CloseLog;
end;

procedure LogDetails;
begin
WriteToLog('Log version **** ');
end;


When my engine starts it calls InitializeLog if i want the debugger enabled (which runs ok) but if i dont then i get the exception!

Maybe i have missed something but i can not see anything wrong with it :s

If any one can help it would be great :)

cairnswm
26-07-2004, 01:45 PM
I Presume it is the fact that LogInitialized is never initialized which means it might be true when one of the functions is called.

Add at the bottom of the unit


Initialization
LogInitialized := False;
Log := Nil;

Finalization
If Assigned(Log) then
Log.Free;

End.


I didnlt test it exactly but its something like that.

M109uk
26-07-2004, 01:57 PM
I have just tried your code but the same exception appears.

I have found another wierd thing about it, i commented out ALL the code inside of my WriteToLog procedure and the exception happens wether or not i initialize the log :?

I cant understand why this happens because this is the only procedure calling to the log, and with out the code how can it cause an exception :?

Harry Hunt
26-07-2004, 02:44 PM
post more code, like from the main app. From what I've seen your log thing should work fine... maybe you're accessing the string list somewhere outside of that unit or something.

M109uk
26-07-2004, 04:05 PM
The main application's code is:


function winMain(hInstance: HINST; hPrevInstance: HINST; lpCmdLine: PChar; nCmdShow: Integer); stdcall;
var
Msg: TMsg;
DemoStart: DWord;
LastTime: Cardinal;
begin
KInitializeLog(KLogFilename);

KLog('Init OpenGL..');

.. OpenGL Initialize code ..
.. Main OpenGL loop ..

.. Free OpenGL code ..

KFinalizeLog;
Result := Msg.wParam;
end;

procedure InitializeKngine;
begin
KLog('Initializing engine');

KLog('Create classes..');
Cameras := TknCameras.Create;
Textures := TknTextures.Create;
Fonts := TknFonts.Create;
Console := TknConsole.Create;

KLog('Add camera');
Cameras.Add('Player', Vertex3f(0,0,0), Vertex3f(0,90,0));

KLog('Load all available fonts');
Fonts.LoadAllFonts;

KLog('Load console scheme..');
Console.LoadFromFile('default.knc'); // <- EXCEPTION CREATED HERE

KLog('Finished engine intialization');
end;


The complete Debug/log unit:

procedure KInitializeLog(const Filename: String);
procedure KFInalizeLog;

procedure KLog(const Value: String);
procedure KLogError(const Value: String);
procedure KLogLine;
procedure KLogDetails;

implementation

var
Log: TStringList;
LogFilename: String;
kDebug_Iint: Boolean;

procedure KInitializeLog(const Filename: String);
begin
If Filename = '' Then Exit;
Log := TStringList.Create;
If FileExists(Filename) Then DeleteFile(Filename);
LogFilename := Filename;
kDebug_Init := True;
KLogDetails;
end;

procedure SaveLog;
begin
If Not kDebug_Init Then Exit;
Log.SaveToFile(LogFilename);
end;

procedure KLog(const Value: String);
begin
If Not kDebug_Init Then Exit;
Log.Add(Value);
SaveLog;
end;

procedure KLogError(const Value: String);
begin
If Not kDebug_Init Then Exit;
KLog('Error :: '+Value);
end;

procedure KLogLine;
begin
If Not kDebug_Init Then Exit;
KLog('******************************************** *****');
end;

procedure KLogDetails;
begin
If Not kDebug_Init Then Exit;
KLogLine;
KLog('Kngine Debugger');
KLog('Version ***');
KLogLine;
end;

initialization
kDebug_Init := False;

finalization



Console loading routine:

KLog('Loading console scheme');
Fs := TknStream.Create(Filename, fmOpenRead);
Try
Fs.Read(Animation, SizeOf(TConsoleAnimation));
Fs.Read(Direction, SizeOf(TConsoleDirection));
Fs.ReadInteger(MaxLines);
For i := 0 To MaxLines-1 Do Fs.ReadVertex4f(LinePositions[i]);
Fs.ReadVertex4f(cmdPosition);
Fs.ReadSingle(OpenPos);
Fs.ReadSingle(ClosePos);
Fs.ReadSingle(XPos);
Fs.ReadSingle(YPos);

Fs.ReadString(Fontname); // < EXCEPTION RAISED HERE

Fs.ReadVertex3f(FontColour);
Fs.ReadString(Texturename);
Except
raise Exception.Create('Failed to load console!');
End;
Fs.Free;
end;


At the moment im re-writting my console editor, it seems to be a problem with that.. The editor was using the debugger while i saved the console file, i turned it off and the exception message changed.. But i cant see why this will be the problem :?

Harry Hunt
26-07-2004, 05:07 PM
I guess this happened when you posted it here

you declare
kDebug_Iint: Boolean;

but you use
kDebug_Init: Boolean;


Other than that I don't see anything that might be causing problems. My suggestion is to place your debug stuff into its own object. That way you can be sure that nothing from "outside" intereferes with it. Then I'd test it in a separate app and see if it works. If it does, the problem is somewhere else.
Sorry, I wish I could be more helpful :?

M109uk
26-07-2004, 05:14 PM
you declare
kDebug_ Iint : Boolean;

but you use
kDebug_ Init : Boolean;


lol yeah thats my posting (thank borland for syntax checking :roll:)

I have rebuilt the editor from scratch, that didnt solve the problem so i re-written the consoles file stucture (even though nothing much has changed except for the names of the variables), it does seem to work now, but i just cant see how my debugger managed to cause this problem when its switched off :? oh well at least it works!

Thanx for your help anyway :D