Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Access violation error in UnDelphiX

  1. #1

    Access violation error in UnDelphiX

    Can someone please explain why I'm getting this error and how to fix it,it only happens once in a while for some reason... Thanks for your help.

    Error EACCESS VIOLATION with message ACCESS VIOLATION at address 00479966 in DXSprite class :
    procedure TSprite.Dead;
    begin
    if (FEngine <nil> error line here
    end;
    end;

    FEngine.FDeadList.Add(Self); ------ > error line here


    My code to kill sprites:
    Code:
    procedure TFormGame.RenderPlay;
    begin
      DXSpriteEngine.Engine.Collisions;
      DXSpriteEngine.engine.Dead;
      DXSpriteEngine.Draw;
    ...
    
    _psStarting  &#58; begin
                          dxSpriteEngine.Engine.Clear;
    ...
    
     _psPlaying   &#58; begin
    FormGame.DxdrawGame.Surface.BltFast&#40;0, 0, backscreen.clientrect,1, backscreen&#41;;
    DxSpriteEngine.Engine.Move&#40;1&#41;;
    if &#40;player.Deaded&#41; and &#40;Lives <0>= 100000&#41; then
    begin
    fGameState &#58;= _gsEnd;
    fEndState&#58;=_esPlaySelected;
    formGame.DXWaveList.Items.Find&#40;'BlownUp'&#41;.Play&#40;False&#41;;
    DXSpriteEngine.Dead;
    dxspriteEngine.Engine.Dead;
    formHigh.ShowModal;
    end
    else
    if &#40;Player.Deaded&#41; and &#40;Lives <= 0&#41; then
    begin
    fGameState&#58;=_gsEnd;
    fEndState&#58;=_esPlaySelected;
    formGame.DXWaveList.Items.Find&#40;'BlownUp'&#41;.Play&#40;False&#41;;
    DXSpriteEngine.Dead;
    dxspriteEngine.Engine.Dead;
    end
    else
    RenderPlay;
    end;....
    Wake up from the dream and live your life to the full

  2. #2

    Access violation error in UnDelphiX

    look at my other thread, jaro and I belieev it is a fault of spriteengine.Clear.

  3. #3

    Access violation error in UnDelphiX

    Thanks, I thought that I was calling dead in the wrong place or something...Anyway I'm trying your suggestion :

    For I:=0 to mainfm.DXSpriteEngine1.Engine.allcount-1 do
    begin
    mainfm.DXSpriteEngine1.Engine.Items[i].dead;
    end;

    It seems to work, will do some tests. Will watch this space for updates :-)
    Wake up from the dream and live your life to the full

  4. #4

    Access violation error in UnDelphiX

    Ok so I did some tests with seiferalmasy's suggestion to count the items and then call dead but I get the same error :-(

    FEngine.FDeadList.Add(Self) in procedure TSprite.Dead;

    So, I changed the call to Clear and the error is still there.....must be something wrong in my code? Help please :-)
    Wake up from the dream and live your life to the full

  5. #5

    Access violation error in UnDelphiX

    Quote Originally Posted by Wizard

    [pascal]
    For I:=0 to mainfm.DXSpriteEngine1.Engine.allcount-1 do
    begin
    mainfm.DXSpriteEngine1.Engine.Items[i].dead;
    end;
    [/pascal]
    I'm no expert on DelphiX but..

    Wouldn't the call to items[i].dead change the value of allcount? or does allcount return a count of all the sprites including dead ones?

    If the count changes (i.e reduces by 1 after calling dead) then you need to loop the other way.

    [pascal]
    For I:= mainfm.DXSpriteEngine1.Engine.allcount-1 downto 0 do
    begin
    mainfm.DXSpriteEngine1.Engine.Items[i].dead;
    end;
    [/pascal]

    This would protect you from accessing indexes that have been removed in a previous iteration of the loop.
    <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>

  6. #6

    Access violation error in UnDelphiX

    Thanks technomage, I tried your way (which makes a bit more sense to me) but I get the same error. It is very difficult to see which line of my code is causing it but it shows that the error is in DXSprite:

    FEngine.FDeadList.Add(Self) in procedure TSprite.Dead;

    So I suppose it must have something to do with the calls to dead?
    Wake up from the dream and live your life to the full

  7. #7

    Access violation error in UnDelphiX

    I suspect the problem is not in the Dead Method , but that item in the sprite list is not valid. Somehow one of the items in your mainfm.DXSpriteEngine1.Engine.Items list is an invalid instance or nil.

    When calling a method on a invalid instance the access violation will appear to be in the method you called (usually when trying to access something that
    has not be created/initialized etc). I would check that

    [pascal]
    For I:= mainfm.DXSpriteEngine1.Engine.allcount-1 downto 0 do
    begin
    if (mainfm.DXSpriteEngine1.Engine.Items[i] <> nil) then
    begin
    mainfm.DXSpriteEngine1.Engine.Items[i].dead;
    end;
    end;
    [/pascal]

    That might help :?:
    <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>

  8. #8

    Access violation error in UnDelphiX

    OK :-)

    I did as you suggested and after some testing it seems that the error has vanished into thin air

    I am very happy indeed, thanks for your help
    Wake up from the dream and live your life to the full

  9. #9

    Access violation error in UnDelphiX

    hmmm I havent had any trouble with the code I used, but I am killing all and creating all in 1 move , after one another.

    Your code is probably a better idea.

    The way I saw it was I is the number of the item. All count gives the total number and then each will be killed in turn. Allcount must show also dead ones? There is another called count (not allcount) . You are right t.mage, you made a good point!

    Hopefully clear will be sorted soon anyway...

  10. #10

    Access violation error in UnDelphiX

    So the error returned but I managed to pinpoint the problem. I was calling dxSpriteEngine.Engine.Dead, whereas it should be:
    dxSpriteEngine.Dead.
    Wake up from the dream and live your life to the full

Page 1 of 2 12 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
  •