Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    [3D] removeObject() // can't use an element from an array as a handle

    Advanced
    3
    11
    795
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • vinicity
      vinicity F last edited by

      Are you sure there is an object in position I + 80?

      What happens if you instead just try to remove the object you just added at position i?

      1 Reply Last reply Reply Quote 2
      • vincent2105
        vincent2105 last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • vincent2105
          vincent2105 last edited by

          with [i] no problem, the object is removed.
          You're right, there was no object in this position. There's a problem with my loop.
          Thank you @vinicity !

          1 Reply Last reply Reply Quote 3
          • vincent2105
            vincent2105 last edited by vincent2105

            Nevertheless, how would you do to test if there's an object in a position before trying to remove it ? Otherwise, is there a way to prevent the program from crashing in this type of case ? (the handle of each object is an index in an array (tilemap)that points to an index in an array of structures. )
            Not sure i'm understandable...

            1 Reply Last reply Reply Quote 0
            • vincent2105
              vincent2105 last edited by

              A little video of my program running a few seconds before crashing... Hope somebody can help me ! :)

              1 Reply Last reply Reply Quote 0
              • Ben 2.0
                Ben 2.0 last edited by

                Have you tried moving the objects to their new positions instead of removing and creating them at the new location? This could get rid of the issue.

                1 Reply Last reply Reply Quote 1
                • vincent2105
                  vincent2105 last edited by

                  No it can't work. :/ Although the displayed area looks repetitive, it is not. In fact, I'm only displaying a 24x24 "tiles" area by moving around in a much larger tilemap. I could have a lot more diversity in the tiles, but I preferred to do it like this, to see if I didn't have row shifts or other problems.

                  1 Reply Last reply Reply Quote 0
                  • vinicity
                    vinicity F last edited by

                    Maybe, instead of keeping 3D objects in your array, you keep structs, that each contains the 3D object and a Boolean flag which indicates wether it has already been removed or not?

                    Or keep a separate array with the same indices that just contains the booleans.

                    1 Reply Last reply Reply Quote 1
                    • vincent2105
                      vincent2105 last edited by

                      Your solution makes sense, you can see that I'm not used to using structures! I will avoid wasting memory with a new array. I'll try as soon as I have some time... Thank you @vinicity !

                      1 Reply Last reply Reply Quote 1
                      • vincent2105
                        vincent2105 last edited by vincent2105

                        Finally, I couldn't wait and chose the fastest solution, I created a separate array to check if the slot was free or not. It works ! It reassures me because I was not sure that there were no other hidden problems.

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post