euddraft icon indicating copy to clipboard operation
euddraft copied to clipboard

f_println, f_printAt, f_simpleprint bug

Open Chromowolf opened this issue 3 years ago • 4 comments

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: image

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): image

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()

Chromowolf avatar Apr 02 '21 09:04 Chromowolf

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.

armoha avatar Apr 02 '21 09:04 armoha

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?

Chromowolf avatar Apr 02 '21 10:04 Chromowolf

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.

armoha avatar Apr 02 '21 10:04 armoha

Thx. Looking forward to the fix

Chromowolf avatar Apr 02 '21 13:04 Chromowolf

Fixed in armoha/eudplib@537080a75f0814175b9dbe0882ff4b5741d85710

No longer have to call GetGlobalStringBuffer() in onPluginStart

armoha avatar Dec 25 '22 05:12 armoha

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.

armoha avatar Jun 17 '23 07:06 armoha