Log in to reply
 

Blips aren't getting removed.



  •         private void Main_Aborted(object sender, EventArgs e)
            {
                DispseWave();
                UI.ShowSubtitle("LOL");
                if(ShouldDisplayBlips)
                {
                    foreach(Blip blip in GasStationBlips)
                    {
                        if (blip == null) return;
                        blip.Remove();
                        GasStationBlips.Remove(blip);
                    }
                }
            }
    

    Don't mind that LOL its just my way of debugging.

    So, this is called when the script is aborted, so I can destroy/remove all my created blips. Problem? They dont get removed! I've put the ShowSubtitle method in the if statement, and even after the null reference check. They still work.

    What basically happens is that the blips add up. I have 23 blips total and whenever I press Insert, that gets doubled :(

    I think I've heard people having problems with blips not being removed so any help would be very appreciated.



  • My bad lol. I got it working forgot to update the thread.





  • Wait, this is your thread?

    I made a very similar thread... Hold on let me find it. XD

    I can't find it, I thought for certain I made one. I had a problem with the Toggle Police blips mod when I first downloaded it and when I hit the end key, it wasn't working. I was about to make a thread, and thought I did, and then got it working. I just saw this thread in my notifications?! Thought it was my thread, and that I forgot to update the thread. But now I see that this is for a script you're working on. I seriously thought I made a thread with the exact same name.
    XD



  • OK, so for anyone still having this problem, I had a way for a workaround... so basically, when I spawn the blips I put in a specific Alpha value (since you can't check for the name for whatever reason) which I set to 254 and before spawning I check if any blips with that sprite and alpha exist. If they do, I don't create the blips.

    I know, it might stop working if some other mod uses the exact same method... but who cares.



  • The problem comes from this piece of code.

    @AHK1221 said in Blips aren't getting removed.:

    foreach(Blip blip in GasStationBlips)
    {
    if (blip == null) return;
    blip.Remove();
    GasStationBlips.Remove(blip);
    }

    You can't modify a list inside an for each iteration (more information).

    In fact, it is useless to remove the Blip object from your object list because C# will do it for you each time your script is destroyed. The process that is reponsible is called the Garbage collector (see this link for further information).

    Here is a way that should work with your list :

            /// <summary>
            /// Remove all blips from the selected list
            /// </summary>
            /// <param name="blips"></param>
            private void CleanBlips(List<Blip> blips)
            {
                foreach(Blip b in blips)
                {
                    if (b != null)
                    {
                        if (b.Exists()) b.Remove();
                        else throw new Exception("Something's wrong!");
                    }
                }
            }


  • @winject If you take out the removing from list code yours and my code doesnt have any difference.

    The problem is in blip.Remove() because the blips arent getting removed from the game world, not the list. blip.Remove() is not interacting with the list in any way, so your code won't make any difference.


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.