Expose the shared pointer instead of the raw pointer in the resource manager and rewrite the custom sheets list to use a vector instead of manual memory management
In particular, this should fix a segmentation fault in the sound system caused by the resource manager pulling a resource that's in use.
This commit is contained in:
@@ -317,7 +317,7 @@ void draw_startup_stats() {
|
||||
to_rect.offset(pc_rect.left,pc_rect.top);
|
||||
pic_num_t pic = univ.party[i].which_graphic;
|
||||
if(pic >= 1000) {
|
||||
const sf::Texture* gw;
|
||||
std::shared_ptr<const sf::Texture> gw;
|
||||
graf_pos_ref(gw, from_rect) = spec_scen_g.find_graphic(pic % 1000, pic >= 10000);
|
||||
rect_draw_some_item(*gw,from_rect,mainPtr,to_rect,sf::BlendAlpha);
|
||||
} else if(pic >= 100) {
|
||||
@@ -1191,7 +1191,7 @@ void draw_trim(short q,short r,short which_trim,ter_num_t ground_ter) {
|
||||
};
|
||||
static std::unique_ptr<sf::Texture> trim_masks[12], walkway_masks[9];
|
||||
rectangle from_rect = {0,0,36,28},to_rect;
|
||||
const sf::Texture* from_gworld;
|
||||
std::shared_ptr<const sf::Texture> from_gworld;
|
||||
sf::Texture* mask;
|
||||
static bool inited = false;
|
||||
if(!inited){
|
||||
|
@@ -62,7 +62,7 @@ bool gave_no_g_error = false;
|
||||
void draw_one_terrain_spot (short i,short j,short terrain_to_draw) {
|
||||
rectangle where_draw;
|
||||
rectangle source_rect;
|
||||
const sf::Texture* source_gworld;
|
||||
std::shared_ptr<const sf::Texture> source_gworld;
|
||||
short anim_type = 0;
|
||||
location l;
|
||||
|
||||
@@ -146,7 +146,7 @@ void draw_monsters() {
|
||||
if(picture_wanted >= 0) {
|
||||
if(picture_wanted >= 1000) {
|
||||
for(short k = 0; k < width * height; k++) {
|
||||
const sf::Texture* src_gw;
|
||||
std::shared_ptr<const sf::Texture> src_gw;
|
||||
graf_pos_ref(src_gw, source_rect) = spec_scen_g.find_graphic(picture_wanted % 1000 +
|
||||
((enc.direction < 4) ? 0 : (width * height)) + k);
|
||||
to_rect = monst_rects[(width - 1) * 2 + height - 1][k];
|
||||
@@ -189,7 +189,7 @@ void draw_monsters() {
|
||||
draw_one_terrain_spot((short) where_draw.x,(short) where_draw.y,10000 + univ.scenario.ter_types[ter].flag1);
|
||||
else if(monst.picture_num >= 1000) {
|
||||
bool isParty = monst.picture_num >= 10000;
|
||||
const sf::Texture* src_gw;
|
||||
std::shared_ptr<const sf::Texture> src_gw;
|
||||
pic_num_t need_pic = (monst.picture_num % 1000) + k;
|
||||
if(monst.direction >= 4) need_pic += width * height;
|
||||
if(combat_posing_monster == i + 100) need_pic += (2 * width * height);
|
||||
@@ -228,7 +228,7 @@ void draw_combat_pc(cPlayer& who, location center, bool attacking) {
|
||||
if(point_onscreen(center, who.combat_pos) && (cartoon_happening || party_can_see(who.combat_pos) < 6)) {
|
||||
location where_draw(who.combat_pos.x - center.x + 4, who.combat_pos.y - center.y + 4);
|
||||
rectangle source_rect;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
pic_num_t pic = who.which_graphic;
|
||||
if(pic >= 1000) {
|
||||
bool isParty = pic >= 10000;
|
||||
@@ -303,7 +303,7 @@ void draw_items(location where){
|
||||
if(univ.town.items[i].variety != eItemType::NO_ITEM && univ.town.items[i].item_loc == where) {
|
||||
if(univ.town.items[i].contained) continue;
|
||||
if(party_can_see(where) >= 6) continue;
|
||||
const sf::Texture* src_gw;
|
||||
std::shared_ptr<const sf::Texture> src_gw;
|
||||
to_rect = coord_to_rect(where_draw.x,where_draw.y);
|
||||
if(univ.town.items[i].graphic_num >= 10000){
|
||||
graf_pos_ref(src_gw, from_rect) = spec_scen_g.find_graphic(univ.town.items[i].graphic_num - 10000, true);
|
||||
@@ -451,7 +451,7 @@ void draw_party_symbol(location center) {
|
||||
|
||||
if((univ.party.in_boat < 0) && (univ.party.in_horse < 0)) {
|
||||
i = first_active_pc();
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
pic_num_t pic = univ.party[i].which_graphic;
|
||||
if(pic >= 1000) {
|
||||
bool isParty = pic >= 10000;
|
||||
|
@@ -424,7 +424,7 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) {
|
||||
base -= 10000;
|
||||
} else base -= 1000;
|
||||
base += step % 4;
|
||||
const sf::Texture* from_gw = nullptr;
|
||||
std::shared_ptr<const sf::Texture> from_gw = nullptr;
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(base, isParty);
|
||||
if(from_gw == nullptr) continue;
|
||||
from_rect.width() = 18;
|
||||
@@ -557,7 +557,7 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) {
|
||||
if(store_booms[i].boom_type >= 0) {
|
||||
if((t + store_booms[i].offset >= 0) && (t + store_booms[i].offset <= 7)) {
|
||||
if(cur_boom_type >= 1000) {
|
||||
const sf::Texture* src_gworld;
|
||||
std::shared_ptr<const sf::Texture> src_gworld;
|
||||
graf_pos_ref(src_gworld, from_rect) = spec_scen_g.find_graphic(cur_boom_type - 1000 + t);
|
||||
rect_draw_some_item(*src_gworld, from_rect, mainPtr, explode_place_rect[i], sf::BlendAlpha);
|
||||
} else {
|
||||
@@ -606,7 +606,7 @@ void click_shop_rect(rectangle area_rect) {
|
||||
graf_pos calc_item_rect(int num,rectangle& to_rect) {
|
||||
if(num >= 1000) return spec_scen_g.find_graphic(num - 1000);
|
||||
rectangle from_rect = {0,0,18,18};
|
||||
const sf::Texture *from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
if(num < 55) {
|
||||
from_gw = &ResMgr::graphics.get("objects");
|
||||
from_rect = calc_rect(num % 5, num / 5);
|
||||
@@ -666,7 +666,7 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) {
|
||||
// Place store icon
|
||||
if(!pressed) {
|
||||
rectangle from_rect = {0,0,32,32};
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
int i = std::max<int>(0, active_shop.getFace());
|
||||
if(i >= 1000) {
|
||||
graf_pos_ref(from_gw, from_rect) = spec_scen_g.find_graphic(i - 1000);
|
||||
@@ -734,7 +734,7 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) {
|
||||
base_item = item.item;
|
||||
std::string cur_name = base_item.full_name, cur_info_str;
|
||||
rectangle from_rect, to_rect = shopping_rects[i][SHOPRECT_GRAPHIC];
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
switch(item.type) {
|
||||
case eShopItemType::ITEM:
|
||||
base_item.ident = true;
|
||||
|
@@ -435,7 +435,7 @@ void place_item_graphic(short which_slot,short graphic) {
|
||||
to_rect.inset(-1,-1);
|
||||
to_rect.offset(20,1);
|
||||
from_rect.inset(2,2);
|
||||
const sf::Texture* src_gw;
|
||||
std::shared_ptr<const sf::Texture> src_gw;
|
||||
if(graphic >= 10000) {
|
||||
graf_pos_ref(src_gw, from_rect) = spec_scen_g.find_graphic(graphic - 10000, true);
|
||||
rect_draw_some_item(*src_gw, from_rect, item_stats_gworld, to_rect,sf::BlendAlpha);
|
||||
@@ -496,7 +496,7 @@ void place_item_bottom_buttons() {
|
||||
to_rect = item_screen_button_rects[i];
|
||||
rect_draw_some_item(invenbtn_gworld, but_from_rect, item_stats_gworld, to_rect, sf::BlendAlpha);
|
||||
pic_num_t pic = univ.party[i].which_graphic;
|
||||
const sf::Texture* from_gw;
|
||||
std::shared_ptr<const sf::Texture> from_gw;
|
||||
if(pic >= 1000) {
|
||||
bool isParty = pic >= 10000;
|
||||
pic_num_t need_pic = pic % 1000;
|
||||
|
@@ -1428,7 +1428,7 @@ void draw_map(bool need_refresh) {
|
||||
if(pic >= 1000) {
|
||||
if(spec_scen_g) {
|
||||
//print_nums(0,99,pic);
|
||||
const sf::Texture* src_gw;
|
||||
std::shared_ptr<const sf::Texture> src_gw;
|
||||
if(drawLargeIcon) {
|
||||
pic = pic % 1000;
|
||||
graf_pos_ref(src_gw, custom_from) = spec_scen_g.find_graphic(pic);
|
||||
@@ -1448,7 +1448,7 @@ void draw_map(bool need_refresh) {
|
||||
rect_draw_some_item(*ResMgr::graphics.get("teranim"), custom_from, map_gworld, draw_rect);
|
||||
} else {
|
||||
int which_sheet = pic / 50;
|
||||
const sf::Texture* src_gw = &ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet));
|
||||
auto src_gw = &ResMgr::graphics.get("ter" + std::to_string(1 + which_sheet));
|
||||
pic %= 50;
|
||||
custom_from = calc_rect(pic % 10, pic / 10);
|
||||
rect_draw_some_item(*src_gw, custom_from, map_gworld, draw_rect);
|
||||
|
Reference in New Issue
Block a user