News:

SimuTranslator
Make Simutrans speak your language.

Text garbling in map window.

Started by Ranran(retired), May 01, 2018, 11:24:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ranran(retired)

Text garbling in map window and this occur in any language. Click "show map scale button", and see under the color scale bar.
This display is not in Simutrans-standard, so it is a unique issue of Simutrans-Extended.


(´・ω・`)
ひめしという日本人が開発者達の助言を無視して自分好みの機能をextendedに"強引に"実装し、
コードをぐちゃぐちゃにしてメンテナンスを困難にし(とりわけ道路と建物関連)、
挙句にバグを大量に埋め込み、それを知らんぷりして放置し(隠居するなどと言って)別のところに逃げ隠れて自分のフォーク(OTRP)は開発を続けている
その事実と彼の無責任さに日本人プレイヤーは目を向けるべき。らんらんはそれでやる気をなくした(´・ω・`)
他人の振り見て我が振り直せ。ひめしのようにならないために、らんらんが生み出したバグや問題は自分で修正しなくちゃね(´・ω・`)

DrSuperGood

It is called stack garbage. In my case resizing the window caused it to show all kinds of crazy text!

if(scale_visible) {
char scale_text[160] = "";
if(1000 % welt->get_settings().get_meters_per_tile() == 0)
{
// Can use integer
sprintf(scale_text, "%i %s %s", (uint16)(1000 / welt->get_settings().get_meters_per_tile()), translator::translate("tiles"), translator::translate("per 1 km"));
}
else
{
// Otherwise, must use float
sprintf(scale_text, "%f %s %s", (1000.0 / welt->get_settings().get_meters_per_tile()), translator::translate("tiles"), translator::translate("per 1 km"));
}
tile_scale_label.set_text(scale_text, false);
}

Kind of obvious why this is happening. The set_text method takes a pointer to a C string to use. Labels do not retain a copy of the C string they were set to, rather keep a pointer to an externally managed C string. In this case you set the label to source its string from the stack. Since the stack frame is destroyed and overwritten, the result is that the label is trying to print out stack garbage.

The solution is to either make the scale_text string buffer static or a member of the map frame. If making it a member of the map frame, one might as well make it a C++ String object, so that memory is managed better.

jamespetts

Splendid, thank you both. I think that I have fixed this based on Dr. Supergood's advice, but I cannot test this, as I could not reproduce the original problem with my debug build. I should be grateful if you could re-test with to-morrow's nightly build.
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

DrSuperGood

Appears fixed.

The likely reason that you could not reproduce it in debug build is that the stack address layout is likely different than release with some variables being optimized away completely in release. Since the entire string was not being overwritten it points towards it being placed very high on the stack, probably so high in the debug builds nothing else was touching that part of the stack.

Ranran(retired)

I confirmed this has been fixed too.
Thank you for fixing this.

(´・ω・`)
ひめしという日本人が開発者達の助言を無視して自分好みの機能をextendedに"強引に"実装し、
コードをぐちゃぐちゃにしてメンテナンスを困難にし(とりわけ道路と建物関連)、
挙句にバグを大量に埋め込み、それを知らんぷりして放置し(隠居するなどと言って)別のところに逃げ隠れて自分のフォーク(OTRP)は開発を続けている
その事実と彼の無責任さに日本人プレイヤーは目を向けるべき。らんらんはそれでやる気をなくした(´・ω・`)
他人の振り見て我が振り直せ。ひめしのようにならないために、らんらんが生み出したバグや問題は自分で修正しなくちゃね(´・ω・`)