Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Delphi skipping lines during run..

  1. #1

    Delphi skipping lines during run..

    Hi all,

    I have a problem, i dont know if its to do with delphi or my app, but its not the first time i had the problem..

    basiclly i have some code in my apps initialization:

    [pascal]
    procedure InitXShell;
    begin
    Clear world;
    Load world from file;
    Set Camera;
    ..
    ..
    end;

    procedure TxsWorld.LoadFromFile(const Filename: String);
    begin
    Create Stream
    Check Header
    Clear textures + shaders
    Load world data
    Free stream
    end;
    [/pascal]

    My problem is while i run my app it goes to load the world from a file, creates the stream and checks the header then it goes to the end of the function (Free stream), then to another function (my finalization function) then runs several other functions and then goes back to my world loading function and trys to load the worlds data, but now of course the stream and everything has been freed and causes an error..

    Does any one else have a similar problem? if so how can i stop this from happening?

    Thanx for any help
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #2

    Delphi skipping lines during run..

    You can get wierd results like this if an error occurs early in your LoadFromFile method. I would put a few exception handlers in and see if you get any errors. It sounds like something might be going wrong in the read header section.

    On the few occasions I have seen something similar, it's usually when I'm doing something with Pointers or reading from stream into a buffer and somethings goes wrong (buffer overrun or the variable I'm passing in is incorrect).

    Hope this helps

    Dean
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  3. #3

    Delphi skipping lines during run..

    Thanx for the reply,

    iv had a look through my functions but cant see anything wrong, delphi wont let me put and exceptions actually in the load function for some reason, it just ignours them when i run the app.

    I use the same functions in another app and the same file but i dont have these problems...

    i'l try and get more information when i get back home..
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  4. #4
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    Delphi skipping lines during run..

    Check that you dont have another function with the same name in another file somewhere. From your explanation it sounds as though the functions you are looking at are not the ones being called.

    Try put a break point BEFORE the function is called and the step into the function to make sure it is the right one being called.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  5. #5

    Delphi skipping lines during run..

    Hi,

    The correct function is being called, its just half way through loading my world file it just goes to the end of the worlds main loadfromfile function to early, below is a more complete code:

    [pascal]
    procedure XShellLoadDefaultWorld;
    begin
    Log(PChar('loading default world..'));
    World.LoadFromFile(XShellDataDir+'defaultworld.xsw ');
    SetupDefaultSpawn;
    SetupActor;
    end;

    procedure TxseWorld.LoadFromFile(const Filename: String);
    var
    Stream: TxnStream;
    i,Cnt: Integer;
    oClass: String;
    begin
    Stream := TxnStream.Create(Filename, xmOpenRead);
    If ValidHeader(Stream, WORLD_HEADER) Then
    Begin
    Clear;
    Worldspawn.LoadFromStream(Stream);
    Stream.ReadInteger(Cnt);
    For i := 0 To Cnt-1 Do
    Begin
    Stream.ReadString(oClass);
    Objects.Add('', oClass);
    Objects[i].LoadFromStream(Stream);
    End;
    End;
    Stream.Free;
    end;

    function TxseObjects.Add(const Name,Classname: String): Integer;
    var
    nObject: TxseBaseObject;
    begin
    Result := -1;
    If fOwner = Nil Then
    Begin
    If Not xseObjectRegister.IsAllowed('', Classname) Then Exit;
    End Else
    Begin
    If Not xseObjectRegsiter.IsAllowed(fOwner.oClassname, Classname) Then Exit;
    End;
    nObject := xseObjectRegister.GetClass(Classname).Create(Self) ;
    If nObject = Nil Then Exit;
    nObject.Name := Name;
    nObject.oClassname := Classname;
    Result := inherited Add(nObject);
    nObject.Index := Result;
    end;

    procedure TxseBaseObject.LoadFromStream(const Stream: TxnStream);
    var
    i,Cnt,Index: Integer;
    oClass: String;
    begin
    Stream.ReadString(Name);
    Stream.ReadInteger(Cnt);
    If Children <> Nil Then
    Begin
    Children.Clear;
    For i := 0 To Cnt-1 Do
    Begin
    Stream.ReadString(oClass);
    Children.Add('', oClass);
    Children[i].LoadFromStream(Stream);
    End;
    End;
    end;

    begin
    //main application code
    while GameRunning Do
    Begin
    //code
    End;
    // finalize code
    end.
    [/pascal]

    The xseObjectRegister is a list of all my world class types, such as groups, polygons, faces, particle systems, lights, etc..

    Both Objects and Children are TxseObjectList class types (which is derived from TList), which are a list of TxseBaseObject.

    In the world.loadfromfile procedure the app runs in to the for statement and starts to load the objects, the first object has 11 children some with a child, when it trys to load the 5th child it then exits this procedure and goes back into world.loadfromfile to stream.free, then goes to the end of my applications code where the //finalize code is and then goes back to where it was in the objects loadfromstream procedure, but by this time it crashes because it trys to read something from the stream, but it has been released :s

    I have renamed all the procedures to check see if they are being called some where else but this isnt happening.. :s
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  6. #6

    Delphi skipping lines during run..

    I would suggest getting rid of any intermediary files like *.dcu and doing a "Build All". Also make sure that you have exceptions turned *on* when debugging your code as it sounds like an AV may be happening in that function and it then throws you out. The only other possiblity that comes to mind would relate to multi-threading. Are you using anything in another thread that may be causing a problem?
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  7. #7

    Delphi skipping lines during run..

    hi,

    i have tried what you suggested, i deleted ALL my sources dcu files and then re-built my app, how ever the same problem occours..
    I have also checked my project exception options and they are all turned on except the bottom 3 (unsafe type, unsafe code and unsafe typecast) i turned these on and it shows warnings for everything thats uses pointers by the looks of things (including dglOpenGL.pas), over 7000 warnings so far and still hasnt got to my code yet :s

    I have added my load function into a while statement to check if it is a problem with the load function being called more than once but still same problem, and the function isnt being called several times :s

    Urm im not using any threads at the moment in my app..

    If anyones intrested and willing, i could email the source and see if the problems are at my end or not?!?
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  8. #8

    Delphi skipping lines during run..

    hmm,
    i got around to having another play with it and decided to comment out my world loading code, but the same problem comes up so of course it cant be my world file or loading code...

    i guess i'l just have to go line by line now :s

    thanx for your help though guys..
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  9. #9

    Delphi skipping lines during run..

    i saw you were reading a string from your own steam class

    you do remember not to read a string of undefined length?
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  10. #10

    Delphi skipping lines during run..

    Iv managed to round it down to 3 functions that the problem is in, think i know what it could be now


    Yeah my stream class does read and write a string,
    its not that cause i use it in all my class types,

    when i write a string, say 'SAMPLE' then it writes each character and then adds #0 to then end, when i read it it just reads a character at a time until it reaches the #0 character..

    source (TxnStream is based on TFileStream):
    [pascal]
    procedure TxnStream.WriteChar(const Value: Char);
    begin
    Write(Value, SizeOf(Char));
    end;

    procedure TxnStream.ReadChar(var Value: Char);
    begin
    Read(Value, SizeOf(Char));
    end;

    procedure TxnStream.WriteString(const Value: String);
    var
    i: Integer;
    begin
    For i := 1 To Length(Value) Do WriteChar(Value[i]);
    WriteChar(#0);
    end;

    procedure TxnStream.ReadString(var Value: String);
    var
    c: Char;
    begin
    Value := '';
    Repeat
    ReadChar(c);
    If c <> #0 Then Value := Concat(Value, c);
    Until c = #0;
    end;
    [/pascal]
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •