Results 1 to 9 of 9

Thread: Handle Destruction Blowing Up My Bots

  1. #1
    Basic Member
    Join Date
    Dec 2016
    Posts
    731

    Unhappy Handle Destruction Blowing Up My Bots

    Ugh... yes. I think it is happening to me under certain circumstances and ugh, it's going to be a headache / annoying to fix.

    A while ago I made the decision to try and be efficient in my bot design and basically obtain the handle to my own bot only once per Think() frame using "local bot = GetBot()" and pass that handle around to all my subsequent functions without calling GetBot() again. This is because passing a handle around while using a bit more memory eliminates the necessarily for one extra call (which in reality is very tiny, but it is still higher than passing the handle around). I decided on this since as I make my bot more and more sophisticated every sliver of millie-second time use will become precious, whereas I have plenty of memory.

    However, the issue is that the patch that was deployed to address illusion hero and destructions of handles when illusions are made or heroes disappear from line of sight affect your own bots too. I haven't run into this before b/c obviously your own bots NEVER disappear from your line-of-sight and all the bots I have been using are not illusion-based and have not every bought a manta. As a result I was oblivious to the fact that as soon as your bots spawn illusions or step on an illusion rune.. say bye-bye to your own "local bot" handle being valid and say hello to the game silently crashing when you do any other bot-scoped operation within that frame.

    I guess an "easy" fix will be for me to terminate the "frame" for that bot upon doing any illusion-related operation and just wait until next frame when I will have a fresh bot handle.. I mean I'm basically just making my bot inefficient for 8 milliseconds under infrequent circumstances. It was just a surprise to me is all. For anyone else passing bot handles around, be aware of this.

    SIDE DISCUSSION: I was recently thinking about why the console warns you anytime any of your bot logic exceeds 2 milliseconds of time. So from a math perspective it works out that at 60 FPS you have approximately 16.6 milliseconds of time per frame. So with 5 bots under your control if you consider even time split... each bot at maximum should complete in under 3.3 milliseconds. When you exceed 2 milliseconds you have consumed already over half the allotted time, so start caring. If you exceed the 16.6ms then you will start dropping frames... making your bot "stupid" in some respect, so do it rarely.


    EDIT: It looks like my interpretation of what happened might be wrong and my crash was more related to not properly testing for illusions using my Think() code and doing things illusions are not allowed to do.
    Last edited by nostrademous; 02-08-2017 at 10:38 AM.

  2. #2
    I think this needs a fix: the handle of your own bots shouldn't be destroyed, ever!

  3. #3
    Basic Member
    Join Date
    Nov 2015
    Posts
    108
    I just ran some quick tests and manta or illusions do not destroy friendly handles at all as they shouldn't. Are you sure your not grabbing the handle of the illusion itself and getting errors with that? When illusions are created, as far as I can tell they run copies of some of the bot files, no clue how this affects you with a total control bot (bot_botname.lua) but I know that files like item_purchase_botname.lua are ran for illusions of heroes.

  4. #4
    Basic Member
    Join Date
    Dec 2016
    Posts
    731
    So... if friendly handles are not destroyed than I encountered another error. I can correlate the "silent" crash to the presence of an illusion rune. It is possible you are correct and it was one of the illusions doing stuff that I never intended for it to do b/c I haven't written any code to handle illusions yet on my team.

    I will have to add a check for "IsIllusion()" to anytime I iterate over the GetUnitList( <ALLIES> ) to eliminate illusions I guess for now, and the same in each bot's Think() function incase an Illusion handle tries to exercise coded behavior.

  5. #5
    Valve Developer
    Join Date
    Sep 2011
    Posts
    1,704
    If you have an example of code that causes a crash when used on an illusion, please let me know -- ideally your worst-case from scripting is a console warning, not a crash.

  6. #6
    Basic Member
    Join Date
    Dec 2016
    Posts
    731
    Quote Originally Posted by ChrisC View Post
    If you have an example of code that causes a crash when used on an illusion, please let me know -- ideally your worst-case from scripting is a console warning, not a crash.
    I will try to find this... shot in the dark is that my bot had a ward and was about to place it but ran over the Illusion Rune, picked it up, spawned two illusions, and one of the illusions tried to put the ward too (since it was in the action queue) but didn't have a ward (or valid ward). But this is guess work.

  7. #7
    Basic Member
    Join Date
    Nov 2015
    Posts
    108
    Quote Originally Posted by ChrisC View Post
    If you have an example of code that causes a crash when used on an illusion, please let me know -- ideally your worst-case from scripting is a console warning, not a crash.
    That's simple just call about anything on an expired illusion handle

    Throw this in your favorite bot_botname.lua
    Code:
    local breakThings
    
    function Think()
    	npcBot = GetBot()
    
    	local tableUnits = GetUnitList(UNIT_LIST_ALLIES)
    
    	for _,v in pairs(tableUnits) do
    		if v:IsIllusion() and not breakThings then
    			breakThings = v
    		end
    	end
    
    	if breakThings then
    		local loc = breakThings:GetLocation()
    	end
    end
    jump in the game on the bots team, pick naga and make clones, cheat in a manta and cast, whatever makes illusions works. ~5 seconds or so after illusions despawn the handle will disappear and your at desktop

    Update: Also summonables like npc_dota_witch_doctor_death_ward etc. will also crash to desktop this way, just change the code above from IsIllusion to GetUnitName() == "unit_name"
    Last edited by ironmano; 02-08-2017 at 12:36 PM.

  8. #8
    Basic Member
    Join Date
    Nov 2015
    Posts
    108
    Quote Originally Posted by nostrademous View Post
    I will try to find this... shot in the dark is that my bot had a ward and was about to place it but ran over the Illusion Rune, picked it up, spawned two illusions, and one of the illusions tried to put the ward too (since it was in the action queue) but didn't have a ward (or valid ward). But this is guess work.
    I really doubt the action queue would carry over to an illusion. Illusions are created from scratch on spawn. The even receive new copies of their appropriate files on spawn. Create an empty bot_botname.lua and just print something at the top of the file outside the Think() then have the Think() cast an illusion and you'll see all the illusions print that statement themselves on spawn.

  9. #9
    Basic Member
    Join Date
    Dec 2016
    Posts
    123
    ah I didn't notice that those time are added up. Is that something related to your CPU or it depend on server side?

Posting Permissions

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