Results 1 to 9 of 9

Thread: Evil crash bites my butt again

  1. #1

    Default Evil crash bites my butt again

    But this time I found a script that actually trigger it rather easily...

    function OnInit() //run upon initialization
    end

    function OnPostInit() //run during the entity's first logic update
    thisMap = this:GetMap();
    --if --thisMap == GetMapManager:GetActiveMap() and
    --not thisMap:GetName() == "Gui_Stuff" then
    SpawnDefaultGui(); -- I am using a function in case I decide to support multiple GUIs
    --end
    end

    function OnKill() //run when removed
    DeleteDefaultGui();
    end

    function SpawnDefaultGui()
    BigBar = GetEntityByName("power_up_bar_big_template");
    YellowBar = GetEntityByName("power_up_bar_yellow_template");
    PinkBar = GetEntityByName("power_up_bar_pink_template");
    WhiteBar = GetEntityByName("power_up_bar_white_template");
    GreenBar = GetEntityByName("power_up_bar_green_template");

    GuiCover = GetEntityByName("gui_cover_template");

    big_bar = BigBar:Clone(thisMap, Vector2(0, 0));
    yellow_bar = YellowBar:Clone(thisMap, Vector2(0, 0));
    pink_bar = PinkBar:Clone(thisMap, Vector2(0, 0));
    white_bar = WhiteBar:Clone(thisMap, Vector2(0, 0));
    green_bar = GreenBar:Clone(thisMap, Vector2(0, 0));
    gui_cover = GuiCover:Clone(thisMap, Vector2(58, -6));
    end

    function DeleteDefaultGui()
    safe_delete(big_bar);
    safe_delete(yellow_bar);
    safe_delete(pink_bar);
    safe_delete(white_bar);
    safe_delete(green_bar);
    safe_delete(gui_cover);
    end

    function safe_delete(entity)
    if entity then entity:SetDeleteFlag(true); end
    end


    First, the "safe_delete" is totally non-safe, because it generate a error when entity is nil "big_bar does not exist"

    Anyway, it sorta worked, but as soon as I delete some object and re-loaded the script, the engine crashed...

    The same crash as the mentioned "random" crash in other topic.

    I realized that the engine hates when you call SetDeleteFlag(true) twice, it plainly crashes sometimes when you do that... So, there are a way to fix any of the issues I mentioned here? Including a way to allow me to "delete" stuff that is not even created yet?

  2. #2
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default

    Cant you check if the Entity exists before trying to remove it?

    If !(GetEntityByName('big_bar-)=nil
    {
    safe_delete(big_bar);
    }

  3. #3

    Default

    I guess I will have to edit the C++ later, doing that in Lua totally don't work.

    But for now I am managing to avoid it with careful (VERY) lua coding.

  4. #4
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    4,682

    Default

    Calling entity:SetDeleteFlag(true) twice in a row shouldn't crash the engine as "entity" still exists until the end of the logic cycle. (if it does, that is a bug)

    However, refering an entity pointer after an entity has been deleted would - as it's just a pointer to random memory at that point.

    You should probably be doing:

    safe_delete(big_bar); big_bar = nil;

    to make sure you don't do that, otherwise the "safe_delete" function really has no meaning.
    Seth A. Robinson
    Robinson Technologies

  5. #5

    Default

    I noticed the crashes are triggered when I delete something, and the engine was going to delete it for another reason, like deleting a entity and then unloading the map.

    This trigger two deletes (and thus a deletion of a random pointer).

  6. #6

    Default

    The game is not frequently crashing, it crashes when closing, it crashes when unloading a map, it crashes when manipulating Watch Manager, and so on...

    But in all crashes, no matter how the stack trace looks (sometimes it look wildly different) one line is ALWAYS present:


    sig_delete(m_ID); (BaseGameEntity.cpp line 52)



    This is greatly bothering me, obviously the deleteflag thing is deleting invalid stuff, but I am not figuring how to figure if something is valid or not (specially because m_ID is a int, not a pointer, thus I cannot just verify if m_ID is valid or not).

  7. #7
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    4,682

    Default

    Hey Speeder, I'm back at the computer in IRC if you want to try again there btw..

    I think you are using Novashell in a way that I didn't plan, because the examples don't seem to have this problem.

    Is it possible for you to make a tiny test project that shows the error and attach it? If so I'd be glad to take a look at it. This test should cause the crash on my version of Novashell. (if it doesn't, it might point to a chance you made as the culprit)
    Seth A. Robinson
    Robinson Technologies

  8. #8

    Default

    Hello

    No need to make a test case, I found out how exactly how it happen (usually... that is...)


    Create two entities (entity A and entity B).

    Put on the OnKill of EntityB: referenceToEntityA:SetDeleteFlag(true)

    Then unload the map or reload the engine or quit the engine.

    If you are unlucky (or lucky :P), EntityA will get deleted when Screen is deleted on C++ before EntityB.

    Then during EntityB deletion, it calls OnKill, that calls SetDeleteFlag on the non-existing EntityA.

    C++ actually allows you to call a method of a non-existing object, and the function runs fine until it actually need data on EntityA, then it crashes.


    The workaround solution is: Don't delete stuff on "OnKill" (what I did).

    But this does not guarantee you won't trigger this bug by accident in other manner.

    The other solution is somehow prevent any call to SetDeleteFlag on a non-existing object, on C++ calls this is done (you check if the pointer is null), but on Lua it blindly calls the method...

    I thought of many possibilities, but I could not figure a way to prevent a dangling pointer on Lua to call a method of a non-existing thing, at least not without causing a error message.


    EDIT: I am not hanging on IRC because someone on Ludumdare dislike me, and keep complaining to ops (even of other channels), once even I said something on Ludumdare that a op in Gamedev disagreed, and I got banned from there... Since Afternet banned msot of IPs of my country, I won't go to the hassle of getting on Afternet to get banned on Ludumdare or Gamedev because of some guy that never cared to show himself.

  9. #9
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    4,682

    Default

    No need to make a test case, I found out how exactly how it happen (usually... that is...)
    Good, but that is the test case, and if you make the project (dead simple, crashes when you hit the unload map button or whatever) I'll take a look.
    Seth A. Robinson
    Robinson Technologies

Similar Threads

  1. CRASH
    By Hawk in forum Funeral Quest
    Replies: 4
    Last Post: 04-18-2010, 03:11 PM
  2. Crash this bug
    By huntercool in forum ClanLib: Developer Chat
    Replies: 2
    Last Post: 09-29-2009, 02:40 PM
  3. Evil Apprentice On Jewel Mountain
    By jenni53 in forum Dink Smallwood HD
    Replies: 2
    Last Post: 11-08-2004, 07:52 AM
  4. Saving Milder? Beating the Evil guy? HELP
    By in forum Dink Smallwood HD
    Replies: 2
    Last Post: 08-13-2004, 01:37 AM
  5. The evil &current_sprite
    By redink1 in forum Dink Smallwood HD
    Replies: 2
    Last Post: 10-09-2002, 06:23 PM

Bookmarks

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
  •