euddraft
euddraft copied to clipboard
f_println, f_printAt, f_simpleprint bug
I'm reading the source code of StringBuffer
.
f_println
, f_printAt
, f_simpleprint
have the following bug:
main.eps:
const me = getuserplayerid();
function afterTriggerExec() {
const cp = getcurpl();
setcurpl(me);
printAt(1, "Always display");
if(getgametick() > 100) {
printAt(0, "game tick > 100");
}
setcurpl(cp);
}
Everything goes normally:
But if I change the order of the two printAt
:
const me = getuserplayerid();
function afterTriggerExec() {
const cp = getcurpl();
setcurpl(me);
if(getgametick() > 100) {
printAt(0, "game tick > 100");
}
printAt(1, "Always display");
setcurpl(cp);
}
Result: "game tick > 100" and "Always display" are displayed at the same time (when getgametick() > 100
):
All three functions f_println
, f_printAt
, f_simpleprint
behave exactly the same. As long as "one function is called within a sub-environment, one function is called outside the environment afterwards", the bug occurs.
I think there may be some bug in GetGlobalStringBuffer()
This is known bug; initialization of local StringBuffer happens on first usage (GlobalStringBuffer
is local in some expect that it is declared only when there is any usage.) So init triggers which run once is located before printAt(0, "game tick > 100");
. It can be fixed by intializing lazily created EUDObject on game start just like IsUserCP()
condition or etc does.
So you mean I could write the following code in FixPrintBug.eps
function onPluginStart() {
const cp = getcurpl();
setcurpl(getuserplayerid());
GetGlobalStringBuffer();
setcurpl(cp);
}
and make FixPrintBug.eps
the first plugin in main.edd
. This can fix all the print bugs?
Yes it does. It makes GlobalStringBuffer for map which does not use it though. Btw you don't need any CurrentPlayer triggers.
What I've thinking is making GetMapStringAddr
to const function. STR section address is fixed in SC:R and so are every string. This will eliminate any need for init trigger.
Thx. Looking forward to the fix
Fixed in armoha/eudplib@537080a75f0814175b9dbe0882ff4b5741d85710
No longer have to call GetGlobalStringBuffer()
in onPluginStart
This is completely fixed with armoha/euddraft#112 in next euddraft version, GetMapStringAddr
becomes constant function, no need to run any trigger at all to initialize StringBuffer
.