Merge lp:~widelands-dev/widelands/bug-1741779-map-description-edit-cutoff into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8723
Proposed branch: lp:~widelands-dev/widelands/bug-1741779-map-description-edit-cutoff
Merge into: lp:widelands
Diff against target: 156 lines (+20/-22)
8 files modified
src/graphic/CMakeLists.txt (+1/-0)
src/graphic/graphic.cc (+9/-0)
src/graphic/graphic.h (+1/-3)
src/graphic/text/rendered_text.cc (+1/-5)
src/graphic/text/rt_render.cc (+1/-6)
src/graphic/text_layout.cc (+2/-1)
src/ui_basic/editbox.cc (+3/-4)
src/ui_basic/multilineeditbox.cc (+2/-3)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1741779-map-description-edit-cutoff
Reviewer Review Type Date Requested Status
Notabilis Approve
kaputtnik (community) testing Approve
Review via email: mp+345495@code.launchpad.net

Commit message

Removed texture size restrictions from editboxes. We no longer need them thanks to the RenderedText class.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3514. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/378610485.
Appveyor build 3319. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1741779_map_description_edit_cutoff-3319.

Revision history for this message
Notabilis (notabilis27) wrote :

I am not quite sure what to make out of this branch. If I guess right, that means that text in editboxes should be able to become as long as I want. However, when typing long texts I get (both here and in trunk):

Texture (2051, 18) too big! Maximum size is 2048.
terminate called after throwing an instance of 'RT::TextureTooBig'
  what(): Texture (2051, 18) too big! Maximum size is 2048.

Tested with the host-ip box in the LAN lobby, the edit field when saving a game and the map description when using the editor by entering one long string (i.e., keeping key pressed for 10 seconds). When entering multiple "words" in the editor it does not crash in either branch but starts lagging after some time.

Some remarks about the code:

- In Editbox the maximum length can also be set by set_max_length(). I guess the condition there has to be adapted, too?

  m_->maxLength = std::min(g_gr->max_texture_size() / UI_FONT_SIZE_SMALL, static_cast<int>(n));

(Also a small documentation bug: the function is called set_max_length() but the in the documentation of set_text() it is called setMaxLength().)

- It seems like MultilineEditbox::Data::maxbytes can be removed completely since it is only used as read-only upper bound and is now fixed at "infinite". I think the conditions where it is used will never trigger now.

Revision history for this message
GunChleoc (gunchleoc) wrote :

YOu're right, somebody leaning endlessly on a key will eventually crash it, because there are no word breaks for splitting the text into separate textures.

I have brought back the limit and fixed it for the Multilineeditbox - the bug there was that we forgot to square the texture size.

I haven't tested my last commit yet, it's still compiling.

Revision history for this message
Notabilis (notabilis27) wrote :

Hm, seems to behave as with the commit before. Only tested the map description edit box, but long inputs still crash and I seem to be able to input ... well, at least very long texts.

On a side note: Tab key has a strange order in that dialog.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have tied the calculation to actual rendered font height now - this fixes the Editbox for me.

The problem in Multilineeditbox was the text_width function used by the WordWrap class - I have added a safeguard there too.

I have also opened a new bug for the tabbing order:

https://bugs.launchpad.net/widelands/+bug/1772561

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3533. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/381985250.
Appveyor build 3337. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1741779_map_description_edit_cutoff-3337.

Revision history for this message
Notabilis (notabilis27) wrote :

Thanks for the bug report.

Unfortunately, I am still unable to notice any changes. :(
Maybe I am understanding the purpose of this branch wrong or are testing something unrelated.
Can you describe a testcase that works different in this branch than in trunk?

Setting maxLength and maxBytes to 3 in the source does restrict the number of characters I am able to enter, so it seems to me as if the calculations show different results for you than for me. Sounds strange, though, since I am assuming that the font and its height is everywhere the same. Does it help if I try to figure out restrictions that do not lead to crashes for me?

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3543. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/382558005.
Appveyor build 3347. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1741779_map_description_edit_cutoff-3347.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Open the "Last bastion" map in the editor, open "Map Options" and scroll down to the bottom of the description. Some text is missing here in trunk.

Font and its height is not the same everywhere - we get bigger textures for Arabic.

By all means, change the restrictions so it won't crash for you. I would expect the results to be identical for the default fontset, so this is strange indeed.

I would like to rework all this stuff again once we get rid of the old renderer - at the moment, the WordWrap class is used by both renderers, so I don' want to touch it. Too many complications.

Revision history for this message
Notabilis (notabilis27) wrote :

Okay, thanks. I think I finally understand what is happening on my system.
Regarding the primary bug, I am unfortunately unable to reproduce it on my system. But the code is looking okay and if it fixes the bug for you, that is enough testing for me.

Are you by chance testing in release mode? Or has your system only limited texture memory? My RT::TextureTooBig exception is not triggered in release mode since another restriction is used there. My exception is triggered due to graphic/text/rt_render.cc:266 where different values for debug and release are used. When using the release version your restrictions work fine. The problem in debug mode is that the exception uses the smaller (hardcoded) value while your checks are using the real (hardware) value which is seemingly bigger on my system. Maybe we should move the restriction from rt_render.cc:266 into graphic/graphic.cc:91 ? (If you do: render_text.cc:183 can then be cleaned up, too.) Except for the text rendering no-one seems to care about the maximum texture size so moving this should be safe.

I added some questions regarding int-casting in the diff, but they haven't been introduced by your changes and someone probably had a reasons for the casts.

Revision history for this message
kaputtnik (franku) wrote :

The main bug is solved, IMHO.

review: Approve (testing)
Revision history for this message
GunChleoc (gunchleoc) wrote :

I introduced that condition in check_size to make sure that the texture size would be OK for everybody. That was especially important before we had the RenderedText class. I have now shifted the difference to Graphic, which will hopefully fix the bug in debug builds.

Revision history for this message
Notabilis (notabilis27) wrote :

Thanks, it is no longer crashing for me now.
One nit: In rendered_text.cc:183 the DEBUG-check is done twice, once there and once inside the called max_texture_size_for_font_rendering().

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

That line needs to be fixed

Revision history for this message
GunChleoc (gunchleoc) wrote :

Done :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/graphic/CMakeLists.txt'
2--- src/graphic/CMakeLists.txt 2018-05-11 04:42:13 +0000
3+++ src/graphic/CMakeLists.txt 2018-05-31 16:50:31 +0000
4@@ -300,6 +300,7 @@
5 text_layout.cc
6 text_layout.h
7 DEPENDS
8+ graphic # TODO(Gunchleoc): For text_width safety only - rewrite that function
9 graphic_align
10 graphic_color
11 graphic_surface
12
13=== modified file 'src/graphic/graphic.cc'
14--- src/graphic/graphic.cc 2018-04-27 06:11:05 +0000
15+++ src/graphic/graphic.cc 2018-05-31 16:50:31 +0000
16@@ -171,6 +171,15 @@
17 return render_target_.get();
18 }
19
20+int Graphic::max_texture_size_for_font_rendering() const {
21+// Test with minimum supported size in debug builds.
22+#ifndef NDEBUG
23+ return kMinimumSizeForTextures;
24+#else
25+ return max_texture_size_;
26+#endif
27+}
28+
29 bool Graphic::fullscreen() {
30 uint32_t flags = SDL_GetWindowFlags(sdl_window_);
31 return (flags & SDL_WINDOW_FULLSCREEN) || (flags & SDL_WINDOW_FULLSCREEN_DESKTOP);
32
33=== modified file 'src/graphic/graphic.h'
34--- src/graphic/graphic.h 2018-04-27 06:11:05 +0000
35+++ src/graphic/graphic.h 2018-05-31 16:50:31 +0000
36@@ -81,9 +81,7 @@
37 return sdl_window_;
38 }
39
40- int max_texture_size() const {
41- return max_texture_size_;
42- }
43+ int max_texture_size_for_font_rendering() const;
44
45 ImageCache& images() const {
46 return *image_cache_.get();
47
48=== modified file 'src/graphic/text/rendered_text.cc'
49--- src/graphic/text/rendered_text.cc 2018-04-07 16:59:00 +0000
50+++ src/graphic/text/rendered_text.cc 2018-05-31 16:50:31 +0000
51@@ -180,11 +180,7 @@
52
53 // Draw Solid background Color
54 if (rect.has_background_color()) {
55-#ifndef NDEBUG
56- const int maximum_size = kMinimumSizeForTextures;
57-#else
58- const int maximum_size = g_gr->max_texture_size();
59-#endif
60+ const int maximum_size = g_gr->max_texture_size_for_font_rendering();
61 const int tile_width = std::min(maximum_size, rect.width());
62 const int tile_height = std::min(maximum_size, rect.height());
63 for (int tile_x = blit_point.x; tile_x + tile_width <= blit_point.x + rect.width();
64
65=== modified file 'src/graphic/text/rt_render.cc'
66--- src/graphic/text/rt_render.cc 2018-04-07 16:59:00 +0000
67+++ src/graphic/text/rt_render.cc 2018-05-31 16:50:31 +0000
68@@ -264,12 +264,7 @@
69 /// Throws a TextureTooBig exception if the given dimensions would be bigger than the graphics
70 /// can handle
71 void check_size(int check_w, int check_h) {
72-// Test for minimum supported size in debug builds.
73-#ifndef NDEBUG
74- const int maximum_size = kMinimumSizeForTextures;
75-#else
76- const int maximum_size = g_gr->max_texture_size();
77-#endif
78+ const int maximum_size = g_gr->max_texture_size_for_font_rendering();
79 if (check_w > maximum_size || check_h > maximum_size) {
80 const std::string error_message =
81 (boost::format("Texture (%d, %d) too big! Maximum size is %d.") % check_w % check_h %
82
83=== modified file 'src/graphic/text_layout.cc'
84--- src/graphic/text_layout.cc 2018-05-05 17:10:37 +0000
85+++ src/graphic/text_layout.cc 2018-05-31 16:50:31 +0000
86@@ -26,6 +26,7 @@
87 #include <boost/format.hpp>
88
89 #include "graphic/font_handler1.h"
90+#include "graphic/graphic.h"
91 #include "graphic/image.h"
92 #include "graphic/text/bidi.h"
93 #include "graphic/text/font_set.h"
94@@ -49,7 +50,7 @@
95 }
96
97 int text_width(const std::string& text, int ptsize) {
98- return UI::g_fh1->render(as_editorfont(text, ptsize - UI::g_fh1->fontset()->size_offset()))
99+ return UI::g_fh1->render(as_editorfont(text.substr(0, g_gr->max_texture_size_for_font_rendering() / text_height() - 1), ptsize - UI::g_fh1->fontset()->size_offset()))
100 ->width();
101 }
102
103
104=== modified file 'src/ui_basic/editbox.cc'
105--- src/ui_basic/editbox.cc 2018-04-27 06:11:05 +0000
106+++ src/ui_basic/editbox.cc 2018-05-31 16:50:31 +0000
107@@ -97,8 +97,7 @@
108 m_->caret = 0;
109 m_->scrolloffset = 0;
110 // yes, use *signed* max as maximum length; just a small safe-guard.
111- m_->maxLength =
112- std::min(g_gr->max_texture_size() / UI_FONT_SIZE_SMALL, std::numeric_limits<int32_t>::max());
113+ set_max_length(std::numeric_limits<int32_t>::max());
114
115 set_handle_mouse(true);
116 set_can_focus(true);
117@@ -124,7 +123,7 @@
118 * Set the current text in the edit box.
119 *
120 * The text is truncated if it is longer than the maximum length set by
121- * \ref setMaxLength().
122+ * \ref set_max_length().
123 */
124 void EditBox::set_text(const std::string& t) {
125 if (t == m_->text)
126@@ -146,7 +145,7 @@
127 * its end is cut off to fit into the maximum length.
128 */
129 void EditBox::set_max_length(uint32_t const n) {
130- m_->maxLength = std::min(g_gr->max_texture_size() / UI_FONT_SIZE_SMALL, static_cast<int>(n));
131+ m_->maxLength = std::min(g_gr->max_texture_size_for_font_rendering() / text_height(), static_cast<int>(n));
132
133 if (m_->text.size() > m_->maxLength) {
134 m_->text.erase(m_->text.begin() + m_->maxLength, m_->text.end());
135
136=== modified file 'src/ui_basic/multilineeditbox.cc'
137--- src/ui_basic/multilineeditbox.cc 2018-05-13 07:15:39 +0000
138+++ src/ui_basic/multilineeditbox.cc 2018-05-31 16:50:31 +0000
139@@ -97,7 +97,7 @@
140 background_style(style),
141 cursor_pos(0),
142 lineheight(text_height()),
143- maxbytes(std::min(g_gr->max_texture_size() / UI_FONT_SIZE_SMALL, 0xffff)),
144+ maxbytes(std::min(g_gr->max_texture_size_for_font_rendering() * g_gr->max_texture_size_for_font_rendering() / (text_height() * text_height()), std::numeric_limits<int32_t>::max())),
145 ww_valid(false),
146 owner(o) {
147 scrollbar.moved.connect(boost::bind(&MultilineEditbox::scrollpos_changed, &o, _1));
148@@ -133,8 +133,7 @@
149 d_->erase_bytes(d_->prev_char(d_->text.size()), d_->text.size());
150 }
151
152- d_->set_cursor_pos(d_->text.size());
153-
154+ d_->set_cursor_pos(0);
155 d_->update();
156 d_->scroll_cursor_into_view();
157

Subscribers

People subscribed via source and target branches

to status/vote changes: