MV Replace a bitmap with another one | Rectangles | Arrays

In the painting game, I'm making u can change colors. I didn't want to stack bitmaps on top of each other so I've decided to replace one bitmap with another If they shape the same coordinates:
I'm deleting the old rectangle, drawing a new one, and assigning it the old one's value in the array.
Now I've checked everything but this problem seems to be here:

Code:
var bitmap = new Bitmap(816, 624);
bitmap.fillRect(x, y, size, size, color)
var sprite = new Sprite(bitmap);
SceneManager._scene.addChildAt(sprite, self(this)["brush index"])
window.myRectList.splice(self(this)["id saved"], 0, sprite);

After this, my array breaks and stops detecting rectangles correctly.
self(this)["id saved"] is the old rectangles' index
SOLVED.
I just ended up destroying old bitmaps and creating new ones instead.

window.myRectList[self(this)["id saved"]].destroy()

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/replace-a-bitmap-with-another-one-rectangles-arrays.139864/