[1.1.76] Memory leak when iterating UTF-8 character set
Posted: Wed Feb 15, 2023 8:30 am
				
				When iterating over the UTF-8 character set and sending those characters to be displayed in a label, the game will slow down and eventually crash. I am specifically NOT creating new frames or labels while doing this, I'm just changing `label.caption` repeatedly. I would expect the video memory to be freed up as this runs.
Run the following from the console and wait a few moments:
The game will progressively slow down until eventually logging the following error:
At this point, the game will continue to run, including sound effects and logging and such, but video will be frozen and the game will not accept any inputs. After a bit more time, the game will crash while logging the same error again.
			Run the following from the console and wait a few moments:
Code: Select all
game.speed = 10000
local labels = {}
for i=0, 63 do
  labels[i] = game.player.gui.screen.add{type="frame", visible=false}.add{type="label", style="label"}
end
local bytes = {}
local size = 1
local prefix
local function on_tick()
  if size == 1 then
    if not prefix then
      prefix = 0x00
    else
      prefix = prefix + 0x40
    end
    if prefix == 0x80 then
      size = 2
      bytes[1] = 0xC0
    end
  else
    bytes[size-1] = bytes[size-1] + 1
    if size == 2 and bytes[1] == 0xE0 then
      size = 3
      bytes[2] = 0x80
    end
  end
  for i = size-1, 2, -1 do
    if bytes[i] == 0xC0 then
      bytes[i] = 0x80
      bytes[i-1] = bytes[i-1] + 1
      if i == 2 then
        if bytes[1] == 0xF0 then
          size = size + 1
          for j = 2, size-1 do
            bytes[j] = 0x80
          end
        elseif bytes[1] == 0xF8 then
          script.on_event(defines.events.on_tick)
          game.speed = 1
        end
      end
    end
  end
  for i = 0, 63 do
    bytes[size] = i+prefix
    labels[i].caption = string.char(table.unpack(bytes))
  end
end
script.on_event(defines.events.on_tick, on_tick)
Code: Select all
 792.989 D3D11_ERROR: ID3D11Device::CreateTexture2D failed in VideoBitmapDX11::createInternalTexture on line 243. Error [0x80070057] - E_INVALIDARG
 792.989 > TextureDesc: Width=9600, Height=19200, MipLevels=1, ArraySize=1, Format=61, Usage=0, BindFlags=8, CPUAccessFlags=0, MiscFlags=0