Results 1 to 5 of 5

Thread: how to debug access violation?

  1. #1

    how to debug access violation?

    Delphi2005 Pro on Windows XP SP3
    Access Violation Exception after call to free

    I am getting an access violation (some number) in an application i am developeing with delphi2005pro.
    The problem the access violation is raised after freeandnill(someobjec) is called.

    This is the situation. In an onclick event for an button an object is created, used an finaly freeandnil is called. Only after the freeandnill is called the access violation is thrown.
    Also i tried stepping through the code all the way butt all went well and after the freeandnill call the exception is there again. Now how do i debug that?

    I do suspect something is going wrong in the object. But i am unable to debug it for now.

    Any pointers to where i should look debug it in another way?

    The offending class/object is the vfs i am developing.

    Thanks for your help in advance.
    http://3das.noeska.com - create adventure games without programming

  2. #2

    how to debug access violation?

    Well I am quite rusty and more of a trial and error debugger myself .

    But the first thing I would check is that the object is not being referenced in any way after or potentially during your free and nil call.

    Also you tried commenting out 1 statement or the other and seeing what sort of effect it has (I don't think you really need to nil these days do you?).

    But if you can free and comment out nil and no error, well, do you really need to nil in that case lol.

  3. #3

    how to debug access violation?

    The calling part looks like this:
    Code:
    procedure TForm1.bDynWriteClick(Sender: TObject);
    var
      MyStream: TVirtualFileStream;
    begin
      MyStream:= TVirtualFileStream.Create(eMemoName.Text, fmCreate, TestDataFile);
      mTest.Lines.SaveToStream(MyStream);
      FreeAndNil(MyStream);
      lTest.Caption := 'OK';
    end;
    Even lTest.Captions is executed and then on end; the access violation error is shown. So no more calling to MyStream after the free.
    http://3das.noeska.com - create adventure games without programming

  4. #4

    how to debug access violation?

    Solved.

    The offending line was:
    procedure TVirtualFileSystem.GetBlockId(var existingblock: Boolean; iEndBlock: Integer; var blocklistsize: Integer; var BlockList: TBlockList; i: Integer; var b: Int64; var nb: Int64);
    Where i did not make blocklistsize var.
    As a result of that i and blocklistsize went out of sync. And when writing outside of BlockList it destroys the object based on TVirtualFileSystem.
    Wow this was a hard one to debug. Better take more care in the future when using refactoring. And for now give i a more meaningfull name.
    http://3das.noeska.com - create adventure games without programming

  5. #5

    how to debug access violation?

    Haha yep, the deeper you go, the harder it is to get back out again lol.

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
  •