Skip to content

Commit

Permalink
Fixes bug #24138 and disables SDL_PumpEvent() in grid.cpp
Browse files Browse the repository at this point in the history
This removes the usage of the display::get_singleton() in the event
handling code since it may cause incorrect behaviour (crash) when the
singleton has been incorrectly set to null.

This also removes SDL_PumpEvents() from grid.cpp the rendering code
should not be directly interacting with the event handling and it's
causing instabilities.
  • Loading branch information
aginor committed Dec 5, 2015
1 parent 3a5b122 commit 36456df
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/events.cpp
Expand Up @@ -551,7 +551,7 @@ void peek_for_resize()
for (int i = 0; i < num; i++) {
if (events[i].type == SDL_WINDOWEVENT &&
events[i].window.event == SDL_WINDOWEVENT_RESIZED) {
display::get_singleton()->video().update_framebuffer();
update_framebuffer();

}
}
Expand Down
9 changes: 2 additions & 7 deletions src/gui/widgets/grid.cpp
Expand Up @@ -21,9 +21,6 @@
#include "gui/auxiliary/layout_exception.hpp"
#include "gui/widgets/control.hpp"
#include "utils/foreach.tpp"
#if SDL_VERSION_ATLEAST(2,0,0)
#include "events.hpp"
#endif

#include <numeric>

Expand Down Expand Up @@ -920,9 +917,8 @@ void tgrid::impl_draw_children(surface& frame_buffer)
* Without the call when resizing larger a black area of remains, this is
* the area not used for resizing the screen, this call `fixes' that.
*/
#if !SDL_VERSION_ATLEAST(2,0,0)
SDL_PumpEvents();
#if SDL_VERSION_ATLEAST(2,0,0)
events::peek_for_resize();
#endif


Expand Down Expand Up @@ -962,9 +958,8 @@ tgrid::impl_draw_children(surface& frame_buffer, int x_offset, int y_offset)
* Without the call when resizing larger a black area of remains, this is
* the area not used for resizing the screen, this call `fixes' that.
*/
#if !SDL_VERSION_ATLEAST(2,0,0)
SDL_PumpEvents();
#if SDL_VERSION_ATLEAST(2,0,0)
events::peek_for_resize();
#endif

assert(get_visible() == twidget::tvisible::visible);
Expand Down
2 changes: 1 addition & 1 deletion src/loadscreen.cpp
Expand Up @@ -211,7 +211,7 @@ void loadscreen::draw_screen(const std::string &text)
#if SDL_VERSION_ATLEAST(2,0,0)
if (ev.type == SDL_WINDOWEVENT &&
ev.window.event == SDL_WINDOWEVENT_RESIZED) {
display::get_singleton()->video().update_framebuffer();
update_framebuffer();
}
if (ev.type == SDL_WINDOWEVENT &&
(ev.window.event == SDL_WINDOWEVENT_RESIZED ||
Expand Down
2 changes: 1 addition & 1 deletion src/video.cpp
Expand Up @@ -533,7 +533,7 @@ int CVideo::modePossible( int x, int y, int bits_per_pixel, int flags, bool curr

#if SDL_VERSION_ATLEAST(2, 0, 0)

void CVideo::update_framebuffer()
void update_framebuffer()
{
if (!window)
return;
Expand Down
11 changes: 6 additions & 5 deletions src/video.hpp
Expand Up @@ -49,6 +49,12 @@ GPU_Target *get_render_target();

surface display_format_alpha(surface surf);
surface& get_video_surface();
#if SDL_VERSION_ATLEAST(2, 0, 0)
//this needs to be invoked immediately after a resize event or the game will crash.
void update_framebuffer();
#endif


SDL_Rect screen_area();


Expand All @@ -75,11 +81,6 @@ class CVideo : private boost::noncopyable {
int modePossible( int x, int y, int bits_per_pixel, int flags, bool current_screen_optimal=false);
int setMode( int x, int y, int bits_per_pixel, int flags );

#if SDL_VERSION_ATLEAST(2, 0, 0)
//this needs to be invoked immediately after a resize event or the game will crash.
void update_framebuffer();
#endif

//did the mode change, since the last call to the modeChanged() method?
bool modeChanged();

Expand Down

0 comments on commit 36456df

Please sign in to comment.