ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Bug Reports (https://www.esoui.com/forums/forumdisplay.php?f=187)
-   -   [notabug] SetText() with gsub operation crashes game (https://www.esoui.com/forums/showthread.php?t=9633)

Phuein 03/16/21 06:26 PM

[notabug] SetText() with gsub operation crashes game
 
I have a couple of undocumented functions from the old author of the Notebook 2018 addon. They look like:
Code:

function NBUI.ProtectText(text)
        return text:gsub([[\]], [[%%92]])
end

function NBUI.UnprotectText(text)
        return text:gsub([[%%92]], [[\]])
end

They are called when changing element text, such as:
Code:

NBUI.NB1RightPage_Title:SetText(NBUI.UnprotectText(title))
Or the other, when saving into variable.

I couldn't load the game with it. Other users reported errors only. I removed them, assuming that by now the game handles string issues better than years ago. This is to help the devs figure out the issue further, to avoid future crashes. :) Thanks!

votan 03/20/21 03:31 AM

Quote:

Originally Posted by Phuein (Post 43484)
I have a couple of undocumented functions from the old author of the Notebook 2018 addon. They look like:
Code:

function NBUI.ProtectText(text)
        return text:gsub([[\]], [[%%92]])
end

function NBUI.UnprotectText(text)
        return text:gsub([[%%92]], [[\]])
end

They are called when changing element text, such as:
Code:

NBUI.NB1RightPage_Title:SetText(NBUI.UnprotectText(title))
Or the other, when saving into variable.

I couldn't load the game with it. Other users reported errors only. I removed them, assuming that by now the game handles string issues better than years ago. This is to help the devs figure out the issue further, to avoid future crashes. :) Thanks!

gsub returns two values: the changed string and the replacement count.
SetText takes two parameters. But the second must be boolean. gsub returns int. => boom
You can not directly use gsub and SetText in one operation.
=>
Lua Code:
  1. local value = gsub(...) -- take first return value only.
  2. edit:SetText(value)

Phuein 03/20/21 09:05 AM

Quote:

Originally Posted by votan (Post 43502)
gsub returns two values: the changed string and the replacement count.
SetText takes two parameters. But the second must be boolean. gsub returns int. => boom
You can not directly use gsub and SetText in one operation.
=>
Lua Code:
  1. local value = gsub(...) -- take first return value only.
  2. edit:SetText(value)

This was used as-is up until the last patch without issue. I assume gsub() is the same, so unless SetText() was changed - do you know that it was? - the other option is the string operation. Either way, breaking-changes without a notification is rough.

sirinsidiator 03/20/21 03:56 PM

Quote:

Originally Posted by Phuein (Post 43506)
This was used as-is up until the last patch without issue. I assume gsub() is the same, so unless SetText() was changed - do you know that it was? - the other option is the string operation. Either way, breaking-changes without a notification is rough.

That's not a breaking change - the addon code was just written naively.
Regardless of language or project, one should never pass variable returns directly into functions that are maintained by a third party. Otherwise there will be surprises like that in case the function is updated to accept new arguments. ;)


All times are GMT -6. The time now is 08:51 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI