fyne-io / terminal

A graphical terminal emulator for Linux using Fyne
Other
252 stars 38 forks source link

Fix buffer corruption that is still happening on run() #64

Closed figuerom16 closed 9 months ago

figuerom16 commented 9 months ago

Buffer corruption was still happening due to the use of Append instead of Copy. Copy is more precise.

I've tried to make an if statement to skip the Copying on when leftover is length zero, but for some reason it always adds back in corruption. I'm really not sure why other than deeper memory handling that I'm not seeing.

figuerom16 commented 9 months ago

The append implementation strangely works just not the original version.

figuerom16 commented 9 months ago

Ok, I think I understand what's going on now! So no matter what the buffer needs to copied every time which is what append is doing essentially. If something modifies the buffer in t.handleOutput then it will be corrupted upon return.

Unless we hunt down what's changing the buffer in t.handleOutput it will need to be copied every time. EDIT: If I had to guess it might be utf8.DecodeRune(buf) doing something to the buffer memory. I don't see an easy way around that though.

figuerom16 commented 9 months ago

This is the best/simplest implementation I can find. Luckily it's simpler than the previous implementation. Someone who is more knowledgeable about buffer handling can probably optimize this. Sorry, I couldn't remove the buffer copy.

figuerom16 commented 9 months ago

Increased buffer size to 32KB to fit in most L1 cache the 4KB buffer is an old I/O standard for files on old hardware. This will reduce refreshes and buffer copies.