Only use references to the screen surface.
This change makes sure that only references are used to the video surface instead of a copy. This will help to avoid stale values after a resize event has occured where it will cause a crash due to a stale pointer.
This commit is contained in:
parent
acc9afe9a9
commit
0c27eb9490
16 changed files with 24 additions and 29 deletions
|
@ -217,7 +217,7 @@ void show_about(display &disp, const std::string &campaign)
|
|||
{
|
||||
boost::scoped_ptr<cursor::setter> cur(new cursor::setter(cursor::WAIT));
|
||||
CVideo &video = disp.video();
|
||||
surface screen = video.getSurface();
|
||||
surface& screen = video.getSurface();
|
||||
if (screen == NULL) return;
|
||||
|
||||
// If the title is multi-line, we need to split it accordingly or we
|
||||
|
|
|
@ -715,7 +715,7 @@ void save_preview_pane::draw_contents()
|
|||
return;
|
||||
}
|
||||
|
||||
surface screen = video().getSurface();
|
||||
surface &screen = video().getSurface();
|
||||
|
||||
SDL_Rect const &loc = location();
|
||||
const SDL_Rect area = sdl::create_rect(loc.x + save_preview_border
|
||||
|
@ -1238,7 +1238,7 @@ void unit_preview_pane::draw_contents()
|
|||
|
||||
GPU_UnsetClip(get_render_target());
|
||||
#else
|
||||
surface screen(video().getSurface());
|
||||
surface& screen(video().getSurface());
|
||||
const clip_rect_setter clipper(screen, &area);
|
||||
|
||||
surface unit_image = det.image;
|
||||
|
|
|
@ -769,7 +769,7 @@ bool display::screenshot(const std::string& filename, bool map_screenshot)
|
|||
bool res = false;
|
||||
|
||||
if (!map_screenshot) {
|
||||
surface screenshot_surf = screen_.getSurface();
|
||||
surface& screenshot_surf = screen_.getSurface();
|
||||
|
||||
res = image::save_image(screenshot_surf, filename);
|
||||
#if 0
|
||||
|
@ -1396,7 +1396,7 @@ void display::flip()
|
|||
return;
|
||||
}
|
||||
|
||||
surface frameBuffer = get_video_surface();
|
||||
surface& frameBuffer = get_video_surface();
|
||||
|
||||
// This is just the debug function "sunset" to progressively darken the map area
|
||||
static size_t sunset_timer = 0;
|
||||
|
@ -2220,7 +2220,7 @@ bool display::scroll(int xmove, int ymove, bool force)
|
|||
font::scroll_floating_labels(dx, dy);
|
||||
labels().recalculate_shroud();
|
||||
|
||||
surface screen(screen_.getSurface());
|
||||
surface& screen(screen_.getSurface());
|
||||
|
||||
SDL_Rect dstrect = map_area();
|
||||
dstrect.x += dx;
|
||||
|
@ -2778,7 +2778,7 @@ const map_labels& display::labels() const
|
|||
|
||||
void display::clear_screen()
|
||||
{
|
||||
surface disp(screen_.getSurface());
|
||||
surface& disp(screen_.getSurface());
|
||||
SDL_Rect area = screen_area();
|
||||
sdl::fill_rect(disp, &area, SDL_MapRGB(disp->format, 0, 0, 0));
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
|
||||
namespace editor {
|
||||
|
||||
std::string item_palette::get_help_string() {
|
||||
std::string item_palette::get_help_string()
|
||||
{
|
||||
return selected_fg_item().name;
|
||||
}
|
||||
|
||||
|
@ -58,9 +59,8 @@ void item_palette::setup(const config& cfg)
|
|||
}
|
||||
}
|
||||
|
||||
void item_palette::draw_item(const overlay& item, surface& image, std::stringstream& tooltip_text) {
|
||||
|
||||
surface screen = gui_.video().getSurface();
|
||||
void item_palette::draw_item(const overlay& item, surface& image, std::stringstream& tooltip_text)
|
||||
{
|
||||
|
||||
std::stringstream filename;
|
||||
filename << item.image;
|
||||
|
|
|
@ -81,8 +81,6 @@ void unit_palette::setup(const config& /*cfg*/)
|
|||
|
||||
void unit_palette::draw_item(const unit_type& u, surface& image, std::stringstream& tooltip_text) {
|
||||
|
||||
surface screen = gui_.video().getSurface();
|
||||
|
||||
std::stringstream filename;
|
||||
filename << u.image() << "~RC(" << u.flag_rgb() << '>'
|
||||
<< team::get_side_color_index(gui_.viewing_side()) << ')';
|
||||
|
|
|
@ -93,7 +93,7 @@ void wait::leader_preview_pane::draw_contents()
|
|||
{
|
||||
bg_restore();
|
||||
|
||||
surface screen = video().getSurface();
|
||||
surface& screen = video().getSurface();
|
||||
|
||||
SDL_Rect const &loc = location();
|
||||
const SDL_Rect area = sdl::create_rect(loc.x + leader_pane_border,
|
||||
|
|
|
@ -539,9 +539,8 @@ void thandler::draw(const bool force)
|
|||
if(!dispatchers_.empty()) {
|
||||
CVideo& video = dynamic_cast<twindow&>(*dispatchers_.back()).video();
|
||||
|
||||
surface frame_buffer = video.getSurface();
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(2,0,0)
|
||||
surface& frame_buffer = video.getSurface();
|
||||
cursor::draw(frame_buffer);
|
||||
#endif
|
||||
video.flip();
|
||||
|
|
|
@ -740,7 +740,7 @@ void twindow::draw()
|
|||
return;
|
||||
}
|
||||
|
||||
surface frame_buffer = video_.getSurface();
|
||||
surface& frame_buffer = video_.getSurface();
|
||||
|
||||
/***** ***** Layout and get dirty list ***** *****/
|
||||
if(need_layout_) {
|
||||
|
@ -789,7 +789,7 @@ void twindow::draw()
|
|||
|
||||
if(dirty_list_.empty()) {
|
||||
if(preferences::use_color_cursors() || sunset_) {
|
||||
surface frame_buffer = get_video_surface();
|
||||
surface& frame_buffer = get_video_surface();
|
||||
|
||||
if(sunset_) {
|
||||
/** @todo should probably be moved to event::thandler::draw. */
|
||||
|
|
|
@ -521,7 +521,7 @@ void help_text_area::draw_contents()
|
|||
{
|
||||
SDL_Rect const &loc = inner_location();
|
||||
bg_restore();
|
||||
surface screen = video().getSurface();
|
||||
surface& screen = video().getSurface();
|
||||
clip_rect_setter clip_rect_set(screen, &loc);
|
||||
for(std::list<item>::const_iterator it = items_.begin(), end = items_.end(); it != end; ++it) {
|
||||
SDL_Rect dst = it->rect;
|
||||
|
|
|
@ -199,7 +199,7 @@ void loadscreen::draw_screen(const std::string &text)
|
|||
}
|
||||
screen_.flip();
|
||||
#else
|
||||
surface gdis = screen_.getSurface();
|
||||
surface& gdis = screen_.getSurface();
|
||||
SDL_Rect area;
|
||||
|
||||
// Pump events and make sure to redraw the logo if there's a chance that it's been obscured
|
||||
|
@ -298,7 +298,7 @@ void loadscreen::clear_screen()
|
|||
int scrx = screen_.getx(); // Screen width.
|
||||
int scry = screen_.gety(); // Screen height.
|
||||
SDL_Rect area = sdl::create_rect(0, 0, scrx, scry); // Screen area.
|
||||
surface disp(screen_.getSurface()); // Screen surface.
|
||||
surface& disp(screen_.getSurface()); // Screen surface.
|
||||
// Make everything black.
|
||||
sdl::fill_rect(disp,&area,SDL_MapRGB(disp->format,0,0,0));
|
||||
update_whole_screen();
|
||||
|
|
|
@ -268,7 +268,7 @@ surface display_format_alpha(surface surf)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
surface get_video_surface()
|
||||
surface& get_video_surface()
|
||||
{
|
||||
return frameBuffer;
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ CVideo::~CVideo()
|
|||
|
||||
void CVideo::blit_surface(int x, int y, surface surf, SDL_Rect* srcrect, SDL_Rect* clip_rect)
|
||||
{
|
||||
surface target(getSurface());
|
||||
surface& target(getSurface());
|
||||
SDL_Rect dst = sdl::create_rect(x, y, 0, 0);
|
||||
|
||||
const clip_rect_setter clip_setter(target, clip_rect, clip_rect != NULL);
|
||||
|
|
|
@ -48,7 +48,7 @@ struct GPU_Target;
|
|||
GPU_Target *get_render_target();
|
||||
|
||||
surface display_format_alpha(surface surf);
|
||||
surface get_video_surface();
|
||||
surface& get_video_surface();
|
||||
SDL_Rect screen_area();
|
||||
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ void progress_bar::set_text(const std::string& text)
|
|||
|
||||
void progress_bar::draw_contents()
|
||||
{
|
||||
surface surf = video().getSurface();
|
||||
surface& surf = video().getSurface();
|
||||
SDL_Rect area = location();
|
||||
|
||||
if(area.w >= 2 && area.h >= 2) {
|
||||
|
|
|
@ -306,8 +306,6 @@ void scrollbar::draw_contents()
|
|||
return;
|
||||
}
|
||||
|
||||
surface const screen = video().getSurface();
|
||||
|
||||
// Draw scrollbar "groove"
|
||||
video().blit_surface(groove.x, groove.y, top_grv);
|
||||
video().blit_surface(groove.x, groove.y + top_grv->h, groove_scaled_);
|
||||
|
|
|
@ -164,7 +164,7 @@ void slider::draw_contents()
|
|||
if (image->w >= loc.w)
|
||||
return;
|
||||
|
||||
surface screen = video().getSurface();
|
||||
surface& screen = video().getSurface();
|
||||
|
||||
SDL_Rect line_rect = sdl::create_rect(loc.x + image->w / 2
|
||||
, loc.y + loc.h / 2
|
||||
|
|
|
@ -185,7 +185,7 @@ void textbox::draw_contents()
|
|||
{
|
||||
SDL_Rect const &loc = inner_location();
|
||||
|
||||
surface surf = video().getSurface();
|
||||
surface& surf = video().getSurface();
|
||||
sdl::draw_solid_tinted_rectangle(loc.x,loc.y,loc.w,loc.h,0,0,0,
|
||||
focus(NULL) ? alpha_focus_ : alpha_, surf);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue