diff --git a/docs/changelog.txt b/docs/changelog.txt index 14efc37d1a..9ad9dd18dd 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -59,6 +59,8 @@ Template for new versions: ## New Features ## Fixes +- a safety check was added to ``Screen::doSetTile_char`` fur out of bound pen color values +- ``TextArea`` widget corrected to use ``COLOR_BLACK`` instead of ``COLOR_RESET`` as default background color ## Misc Improvements diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index f729be2743..e8a1cd9f67 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -3754,6 +3754,9 @@ environment by the mandatory init file dfhack.lua: ``COLOR_GREY`` and ``COLOR_DARKGREY`` can also be spelled ``COLOR_GRAY`` and ``COLOR_DARKGRAY``. + Note: ``COLOR_RESET`` is not valid in a `Pen `, and using it in a Pen color field + will result in runtime warnings and may result in color flashing or other unexpected results. + * State change event codes, used by ``dfhack.onStateChange`` Available only in the `core context `, as is the event itself: diff --git a/library/lua/gui/widgets/text_area/text_area_content.lua b/library/lua/gui/widgets/text_area/text_area_content.lua index 83099fac76..cd35f751ee 100644 --- a/library/lua/gui/widgets/text_area/text_area_content.lua +++ b/library/lua/gui/widgets/text_area/text_area_content.lua @@ -37,7 +37,7 @@ function TextAreaContent:init() self.cursor = nil self.main_pen = dfhack.pen.parse({ - bg=COLOR_RESET, + bg=COLOR_BLACK, bold=true }, self.text_pen) diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index 338a66925e..c5451ce806 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -54,6 +54,8 @@ distribution. #include "df/renderer.h" #include "df/plant.h" +#include +#include #include #include #include @@ -209,14 +211,15 @@ static bool doSetTile_char(const Pen &pen, int x, int y, bool use_graphics) *texpos_lower = df::global::init->texpos_border_interior; // basic black background } - auto rgb_fg = &gps->uccolor[fg][0]; - auto rgb_bg = &gps->uccolor[bg][0]; - screen[1] = rgb_fg[0]; - screen[2] = rgb_fg[1]; - screen[3] = rgb_fg[2]; - screen[4] = rgb_bg[0]; - screen[5] = rgb_bg[1]; - screen[6] = rgb_bg[2]; + if (fg >= 0 && fg <= COLOR_MAX) + std::ranges::copy(gps->uccolor[fg], &screen[1]); + else + WARN(screen).print("in doSetTile_char, fg {} out of range\n", fg); + + if (bg >= 0 && bg <= COLOR_MAX) + std::ranges::copy(gps->uccolor[bg], &screen[4]); + else + WARN(screen).print("in doSetTile_char, bg {} out of range\n", bg); return true; }