widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #07319
[Merge] lp:~widelands-dev/widelands/bug-1571308-fh1-texture-size into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1571308-fh1-texture-size into lp:widelands.
Commit message:
Graphic now has its max_texture_size publicly available. Restricted text size in edit boxes to prevent crashes with too large textures.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1571308 in widelands: "Crash when EditBox text exceeds maximum width"
https://bugs.launchpad.net/widelands/+bug/1571308
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1571308-fh1-texture-size/+merge/292355
Fixed crashes with long text input.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1571308-fh1-texture-size into lp:widelands.
=== modified file 'src/graphic/graphic.cc'
--- src/graphic/graphic.cc 2016-03-08 12:54:46 +0000
+++ src/graphic/graphic.cc 2016-04-20 09:59:54 +0000
@@ -86,10 +86,12 @@
SDL_CreateWindow("Widelands Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
window_mode_width_, window_mode_height_, SDL_WINDOW_OPENGL);
- GLint max_texture_size;
+ GLint max;
gl_context_ = Gl::initialize(
trace_gl == TraceGl::kYes ? Gl::Trace::kYes : Gl::Trace::kNo, sdl_window_,
- &max_texture_size);
+ &max);
+
+ max_texture_size_ = static_cast<int>(max);
resolution_changed();
set_fullscreen(init_fullscreen);
@@ -113,7 +115,7 @@
}
std::map<std::string, std::unique_ptr<Texture>> textures_in_atlas;
- auto texture_atlases = build_texture_atlas(max_texture_size, &textures_in_atlas);
+ auto texture_atlases = build_texture_atlas(max_texture_size_, &textures_in_atlas);
image_cache_->fill_with_texture_atlases(
std::move(texture_atlases), std::move(textures_in_atlas));
}
=== modified file 'src/graphic/graphic.h'
--- src/graphic/graphic.h 2016-01-31 21:03:15 +0000
+++ src/graphic/graphic.h 2016-04-20 09:59:54 +0000
@@ -74,6 +74,8 @@
void refresh();
SDL_Window* get_sdlwindow() {return sdl_window_;}
+ int max_texture_size() const {return max_texture_size_;}
+
ImageCache& images() const {return *image_cache_.get();}
AnimationManager& animations() const {return *animation_manager_.get();}
@@ -98,6 +100,9 @@
SDL_Window* sdl_window_;
SDL_GLContext gl_context_;
+ /// The maximum width or height a texture can have.
+ int max_texture_size_;
+
/// A RenderTarget for screen_. This is initialized during init()
std::unique_ptr<RenderTarget> render_target_;
=== modified file 'src/graphic/text/rt_errors.h'
--- src/graphic/text/rt_errors.h 2016-03-14 19:49:52 +0000
+++ src/graphic/text/rt_errors.h 2016-04-20 09:59:54 +0000
@@ -47,6 +47,7 @@
DEF_ERR(InvalidColor)
DEF_ERR(RenderError)
DEF_ERR(SyntaxError)
+DEF_ERR(TextureTooBig)
DEF_ERR(WidthTooSmall)
#undef DEF_ERR
=== modified file 'src/graphic/text/rt_render.cc'
--- src/graphic/text/rt_render.cc 2016-03-14 19:49:52 +0000
+++ src/graphic/text/rt_render.cc 2016-04-20 09:59:54 +0000
@@ -36,6 +36,7 @@
#include "base/rect.h"
#include "base/wexception.h"
#include "graphic/align.h"
+#include "graphic/graphic.h"
#include "graphic/image_cache.h"
#include "graphic/image_io.h"
#include "graphic/text/bidi.h"
@@ -598,6 +599,13 @@
uint16_t hotspot_y() override {return height();}
Texture* render(TextureCache* texture_cache) override {
+ if (width() > g_gr->max_texture_size() || height() > g_gr->max_texture_size()) {
+ const std::string error_message =
+ (boost::format("Texture (%d, %d) too big! Maximum size is %d.")
+ % width() % height() % g_gr->max_texture_size()).str();
+ log((error_message + "\n").c_str());
+ throw TextureTooBig(error_message);
+ }
Texture* rv = new Texture(width(), height());
rv->fill_rect(Rect(0, 0, rv->width(), rv->height()), RGBAColor(255, 255, 255, 0));
=== modified file 'src/ui_basic/editbox.cc'
--- src/ui_basic/editbox.cc 2016-04-05 14:42:33 +0000
+++ src/ui_basic/editbox.cc 2016-04-20 09:59:54 +0000
@@ -25,9 +25,11 @@
#include <boost/format.hpp>
#include "graphic/font_handler1.h"
+#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/text/bidi.h"
#include "graphic/text/font_set.h"
+#include "graphic/text/rt_errors.h"
#include "graphic/text_constants.h"
#include "ui_basic/mouse_constants.h"
@@ -93,7 +95,8 @@
m_->caret = 0;
m_->scrolloffset = 0;
// yes, use *signed* max as maximum length; just a small safe-guard.
- m_->maxLength = std::numeric_limits<int32_t>::max();
+ m_->maxLength = std::min(g_gr->max_texture_size() / UI_FONT_SIZE_SMALL,
+ std::numeric_limits<int32_t>::max());
set_handle_mouse(true);
set_can_focus(true);
@@ -155,7 +158,7 @@
*/
void EditBox::set_max_length(uint32_t const n)
{
- m_->maxLength = n;
+ m_->maxLength = std::min(g_gr->max_texture_size() / UI_FONT_SIZE_SMALL, static_cast<int>(n));
if (m_->text.size() > m_->maxLength) {
m_->text.erase(m_->text.begin() + m_->maxLength, m_->text.end());
=== modified file 'src/ui_basic/multilineeditbox.cc'
--- src/ui_basic/multilineeditbox.cc 2016-04-03 18:47:55 +0000
+++ src/ui_basic/multilineeditbox.cc 2016-04-20 09:59:54 +0000
@@ -22,6 +22,7 @@
#include <boost/bind.hpp>
#include "base/utf8.h"
+#include "graphic/graphic.h"
#include "graphic/rendertarget.h"
#include "graphic/text_layout.h"
#include "graphic/wordwrap.h"
@@ -102,7 +103,7 @@
:
scrollbar(&o, o.get_w() - Scrollbar::kSize, 0, Scrollbar::kSize, o.get_h(), false),
cursor_pos(0),
-maxbytes(0xffff),
+maxbytes(std::min(g_gr->max_texture_size() / UI_FONT_SIZE_SMALL, 0xffff)),
ww_valid(false),
owner(o)
{
Follow ups