Fixed sprite allocation bugs

* Fixed bug that would cause the renderer for sprites to be corrupted on when the sprite vector is resized
* Changed deleted_sprites variable to deleted_animation in sprite object
* Changed sprite pointer vector to sprite id vector in canvas object
* Changed the value stored in Fixture UserData pointer to sprite id rather than sprite pointer because pointer would change on resize anyway
This commit is contained in:
n00b
2024-12-22 13:05:23 -05:00
parent ac2cb91b18
commit 0ef552910a
9 changed files with 85 additions and 54 deletions

View File

@@ -1055,6 +1055,7 @@ int rc_canvasOpen(int w, int h, int vx, int vy, int vw, int vh, int mode, int ca
canvas.physics2D.enabled = true;
canvas.physics2D.contact_listener = new rc_contactListener_obj();
canvas.physics2D.world->SetContactListener(canvas.physics2D.contact_listener);
canvas.sprite_id.clear();
}
switch(mode)
@@ -1133,13 +1134,14 @@ void rc_canvasClose(int canvas_id)
}
//sprites are destroyed when the world is deleted so I just to set the active attribute to false and set the body to NULL
for(int i = 0; i < rc_canvas[canvas_id].sprite.size(); i++)
for(int i = 0; i < rc_canvas[canvas_id].sprite_id.size(); i++)
{
rc_canvas[canvas_id].sprite[i]->active = false;
rc_canvas[canvas_id].sprite[i]->physics.body = NULL;
int spr_id = rc_canvas[canvas_id].sprite_id[i];
rc_sprite[spr_id].active = false;
rc_sprite[spr_id].physics.body = NULL;
}
rc_canvas[canvas_id].sprite.clear();
rc_canvas[canvas_id].sprite_id.clear();
if(rc_active_canvas == canvas_id)
rc_active_canvas = -1;
@@ -1177,25 +1179,6 @@ void rc_setCanvasPhysics2D(int canvas_id, bool flag)
rc_canvas[canvas_id].physics2D.enabled = flag;
}
void rc_clearCanvas()
{
if(rc_active_canvas >= 0 && rc_active_canvas < rc_canvas.size())
{
if(rc_canvas[rc_active_canvas].texture)
switch(rc_canvas[rc_active_canvas].type)
{
case RC_CANVAS_TYPE_2D:
VideoDriver->clearBuffers(true, true, true, rc_clear_color);
break;
default:
VideoDriver->clearBuffers(true, true, true, rc_clear_color);
break;
}
}
}
void rc_setCanvasVisible(int canvas_id, bool flag)
{
if(canvas_id <= 0 || canvas_id >= rc_canvas.size()) //canvas 0 is being excluded because its the back buffer