cherry picked a couple of bgfx nanovg fixes and fixed a heap corruption bug in it