Bug #23908 - Don't hold copies of the window surface

Change more copies of the window surface to be references
instead. This will make sure they do not contain a stale version that
has a pointer that points to freed memory.
This commit is contained in:
Andreas Löf 2015-10-14 23:00:43 +13:00
parent 5890e3c167
commit da98c62d4f
9 changed files with 15 additions and 13 deletions

View file

@ -344,7 +344,7 @@ void battle_prediction_pane::draw_unit(int x_off, int damage_line_skip, int left
const std::string& label, int label_width,
surface& hp_distrib, int hp_distrib_width)
{
surface screen = resources::screen->get_screen_surface();
surface& screen = resources::screen->get_screen_surface();
int i;
// NOTE. A preview pane is not made to be used alone and it is not

View file

@ -1336,7 +1336,7 @@ void display::drawing_buffer_commit()
GPU_UnsetClip(get_render_target());
#else
SDL_Rect clip_rect = map_area();
surface screen = get_screen_surface();
surface& screen = get_screen_surface();
clip_rect_setter set_clip_rect(screen, &clip_rect);
/*
@ -1833,7 +1833,7 @@ void display::draw_init()
#ifdef SDL_GPU
draw_background(screen_, clip_rect, theme_.border().background_image);
#else
const surface screen = get_screen_surface();
const surface& screen = get_screen_surface();
clip_rect_setter set_clip_rect(screen, &clip_rect);
draw_background(screen, clip_rect, theme_.border().background_image);
#endif
@ -2791,7 +2791,7 @@ const SDL_Rect& display::get_clip_rect()
void display::draw_invalidated() {
// log_scope("display::draw_invalidated");
SDL_Rect clip_rect = get_clip_rect();
surface screen = get_screen_surface();
surface& screen = get_screen_surface();
clip_rect_setter set_clip_rect(screen, &clip_rect);
BOOST_FOREACH(const map_location& loc, invalidated_) {
int xpos = get_location_x(loc);

View file

@ -205,7 +205,7 @@ public:
CVideo& video() { return screen_; }
/** return the screen surface or the surface used for map_screenshot. */
surface get_screen_surface() { return map_screenshot_ ? map_screenshot_surf_ : screen_.getSurface();}
surface& get_screen_surface() { return map_screenshot_ ? map_screenshot_surf_ : screen_.getSurface();}
virtual bool in_game() const { return false; }
virtual bool in_editor() const { return false; }

View file

@ -885,7 +885,7 @@ surface get_rendered_text(const std::string& str, int size, const SDL_Color& col
return render_text(str, size, color, style, false);
}
SDL_Rect draw_text_line(surface gui_surface, const SDL_Rect& area, int size,
SDL_Rect draw_text_line(surface& gui_surface, const SDL_Rect& area, int size,
const SDL_Color& color, const std::string& text,
int x, int y, bool use_tooltips, int style)
{

View file

@ -76,7 +76,7 @@ inline int relative_size(int size)
// Returns a SDL surface containing the text rendered in a given color.
surface get_rendered_text(const std::string& text, int size, const SDL_Color& color, int style=0);
SDL_Rect draw_text_line(surface gui_surface, const SDL_Rect& area, int size,
SDL_Rect draw_text_line(surface& gui_surface, const SDL_Rect& area, int size,
const SDL_Color& color, const std::string& text,
int x, int y, bool use_tooltips, int style);

View file

@ -557,7 +557,7 @@ void create::draw_level_image()
draw_centered_on_background(image, image_rect_, back_color,
video().getSurface());
} else {
surface display(disp_.get_screen_surface());
surface& display(disp_.get_screen_surface());
sdl::fill_rect(display, &image_rect_,
SDL_MapRGB(display->format, 0, 0, 0));
update_rect(image_rect_);

View file

@ -232,7 +232,7 @@ bool halo_impl::effect::render()
return false;
}
surface screen = disp->get_screen_surface();
surface& screen = disp->get_screen_surface();
const clip_rect_setter clip_setter(screen, &clip_rect);
if(buffer_ == NULL || buffer_->w != rect.w || buffer_->h != rect.h) {
@ -265,7 +265,7 @@ void halo_impl::effect::unrender()
return;
}
surface screen = disp->get_screen_surface();
surface& screen = disp->get_screen_surface();
SDL_Rect clip_rect = disp->map_outside_area();
const clip_rect_setter clip_setter(screen, &clip_rect);

View file

@ -190,7 +190,7 @@ SDL_Rect text_area(const std::string& text, int size, int style)
return draw_text(NULL, area, size, font::NORMAL_COLOR, text, 0, 0, false, style);
}
SDL_Rect draw_text(surface dst, const SDL_Rect& area, int size,
SDL_Rect draw_text(surface& dst, const SDL_Rect& area, int size,
const SDL_Color& color, const std::string& txt,
int x, int y, bool use_tooltips, int style)
{
@ -241,7 +241,9 @@ SDL_Rect draw_text(CVideo* gui, const SDL_Rect& area, int size,
const SDL_Color& color, const std::string& txt,
int x, int y, bool use_tooltips, int style)
{
return draw_text(gui != NULL ? gui->getSurface() : NULL, area, size, color, txt, x, y, use_tooltips, style);
surface null_surf = surface(NULL);
return draw_text(gui != NULL ? gui->getSurface() : null_surf, area, size, color, txt, x, y, use_tooltips, style);
}
bool is_format_char(char c)

View file

@ -76,7 +76,7 @@ std::string::const_iterator parse_markup(std::string::const_iterator i1,
* A bounding rectangle of the text is returned. If dst is NULL, then the
* text will not be drawn, and a bounding rectangle only will be returned.
*/
SDL_Rect draw_text(surface dst, const SDL_Rect& area, int size,
SDL_Rect draw_text(surface& dst, const SDL_Rect& area, int size,
const SDL_Color& color, const std::string& text,
int x, int y, bool use_tooltips = false, int style = 0);