This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Vilsol's profile picture

[1.74] Major Window API Bug

Started by Vilsol, 21 August 2015 - 06:37 PM
Vilsol #1
Posted 21 August 2015 - 08:37 PM
Hello. I looked all around the forums and I couldn't find anyone creating a topic about this, so here it goes.

Here is a GIF of it in action. This is the program that is available on the wiki: http://www.computerc...ndow.reposition



As you can see, there is a really weird bug where the window size is drawn sometimes larger and sometimes smaller than it actually is.

I ran another test, and really, it draws it larger than it actually is. Here is a GIF of where I iterate from 1 to 20 and set it as the width of the window, then loop over the width of the window and color each column in a different color. As you can see, it draws the box exactly twice minus one as wide as I set it.



Looking at the Window API source, I figured it is because each time the window is re-positioned, the contents of it are multiplied, not just added a blank space.

Here are the lines 402 to 404 in the source:

text = tOldLine.text .. string_sub( sEmptyText, 1, nWidth + 1, nNewWidth ),
textColor = tOldLine.textColor .. string_sub( sEmptyTextColor, 1, nWidth + 1, nNewWidth ),
backgroundColor = tOldLine.backgroundColor .. string_sub( sEmptyBackgroundColor, 1, nWidth + 1, nNewWidth ),

Here is what they should be

text = tOldLine.text .. string_sub( sEmptyText, 1, nNewWidth - (nWidth + 1)),
textColor = tOldLine.textColor .. string_sub( sEmptyTextColor, 1, nNewWidth - (nWidth + 1)),
backgroundColor = tOldLine.backgroundColor .. string_sub( sEmptyBackgroundColor, 1, nNewWidth - (nWidth + 1)),

If they are changed, this is the result:



The same DOES NOT apply to the height, as that is calculated differently from the width.

I really hope this is fixed in the future versions.
Edited on 21 August 2015 - 08:45 PM
Wojbie #2
Posted 11 December 2015 - 01:01 AM
Still valid. Reposted to github for latest beta. https://github.com/dan200/ComputerCraft/issues/31
dan200 #3
Posted 11 December 2015 - 11:26 AM
Could you post a pastebin to the test program used in your gifs?
Vilsol #4
Posted 11 December 2015 - 11:30 AM
I'm at insomnia right now, but I will try to find it for Monday or Tuesday.

You can also test all that with the wiki test program.
Edited on 11 December 2015 - 10:31 AM
dan200 #5
Posted 11 December 2015 - 03:11 PM
Oh, enjoy Insomnia! Haven't been to one of those in a while. I've managed to obtain a similar program and fix the bug,
Vilsol #6
Posted 11 December 2015 - 03:15 PM
Thanks and awesome, now I can continue working on the OS ^^
dan200 #7
Posted 11 December 2015 - 03:24 PM
fixed in 1.76pr3