Closed THE-FYP closed 5 years ago
ImVector_ImWchar_create returns memory from ImGui and is released with ImVector_ImWchar_destroy ImVector_ImWchar_Init initializes memory from LuaJIT and is released with ImVector_ImWchar_UnInit
ImVector_ImWchar_UnInit and after ImVector_ImWchar_destroy will crash
Now I use it as
local p_ranges = ig.lib.ImVector_ImWchar_create()
local GRB = ig.GlyphRangesBuilder()
GRB:AddText("Hello world")
GRB:AddChar(0x7262); -- Add a specific character
--GRB:AddRanges(ig.GetIO().Fonts:GetGlyphRangesJapanese()); -- Add one of the default ranges
GRB:BuildRanges(p_ranges)
print(p_ranges,p_ranges[0],p_ranges[0].Size,p_ranges[0].Capacity)
local Data = p_ranges[0].Data
for i=0,p_ranges[0].Size-1 do
print(Data[i])
end
ig.lib.ImVector_ImWchar_destroy(p_ranges)
or
local p_ranges = ffi.new"ImVector_ImWchar[1]"
ig.lib.ImVector_ImWchar_Init(p_ranges)
...
ig.lib.ImVector_ImWchar_UnInit(p_ranges)
I didnt wrap it in a metatype because there are this two different uses.
Oh, I see... I was sure that create/destroy are allocator/deallocator and Init/UnInit are constructor/destructor. Ok, but is there any to reason to not choice one of these for use in the metatype? As I see all the other types (except ImVec2/ImVec4) are allocated/deallocated by the ImGui side and don't provide alternative way of initialization, so why not to choose the same for ImVector types?
There was an open question about that in cimgui but nobody answered. I think the _create path is better for not using the LuaJIT memory space (low 1Gb in win64)
Also was waiting for more ImVector_XXX use cases in order to wrap them programatically
It is important for use in
ImFontAtlas::AddFontFrom...
functions.