-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug FontGlyphRangesBuilder #206
Comments
Just to explain: mentioned code comes from utils.go so it isn't auto-generated, ergo #198 didn't apply to them |
well, It looks like something else... |
After looking at dlv output I still suppose that it is caused by lack of |
on go 1.21.1
|
Huh? It's strange... |
@Wolf65 could you post some testing code? I checked on current giu migration pr and it worked |
While I was building the example, another commit was released and the error changed and another one appeared. I hope I explained it clearly in the main comments. |
I was to lazy to construct my own code if I know that you have one for sure 😄 Sorry ;-) In case of your bug... File: /home/runner/work/cimgui-go/cimgui-go/cimgui/imgui/imgui_draw.cpp, Line: 2208 so IM_ASSERT_USER_ERROR(0, "Could not load font file!"); so the following makes it working for me diff --git a/main.go b/main.go
index 91d760b..61f00a5 100644
--- a/main.go
+++ b/main.go
@@ -25,13 +25,13 @@ func main() {
baseBuilder.AddRanges(io.Fonts().GlyphRangesCyrillic())
baseBuilder.BuildRanges(baseRange)
- io.Fonts().AddFontFromFileTTFV("fonts/ttf/JetBrainsMono-Medium.ttf",
+ io.Fonts().AddFontFromFileTTFV("JetBrainsMono-Medium.ttf",
baseFontSize,
&baseConfig,
baseRange.Data())
|
About the path to the font. since it's a piece of code from the main project, I forgot to fix the path to the font. Sorry. About the fall with panic. It may have fixed itself. I couldn't get it to repeat itself. What about the code that's commented out below? |
|
diff --git a/main.go b/main.go
index 91d760b..f44f95c 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,8 @@
package main
import (
+ "fmt"
+
imgui "github.com/AllenDang/cimgui-go"
)
@@ -25,13 +27,13 @@ func main() {
baseBuilder.AddRanges(io.Fonts().GlyphRangesCyrillic())
baseBuilder.BuildRanges(baseRange)
- io.Fonts().AddFontFromFileTTFV("fonts/ttf/JetBrainsMono-Medium.ttf",
+ io.Fonts().AddFontFromFileTTFV("JetBrainsMono-Medium.ttf",
baseFontSize,
&baseConfig,
baseRange.Data())
- //File: D:/a/cimgui-go/cimgui-go/cimgui/imgui/imgui_draw.cpp, Line: 2208
- //exit status 1
+ // File: D:/a/cimgui-go/cimgui-go/cimgui/imgui/imgui_draw.cpp, Line: 2208
+ // exit status 1
// FontAwesome
fontAwesomeConfig := *imgui.NewFontConfig()
@@ -42,12 +44,12 @@ func main() {
fontAwesomeConfig.SetGlyphOffset(imgui.Vec2{X: 0, Y: 2})
////Whoa, I caught a bug while I was doing the test. If you uncomment the code below
- //IconRange := []uint16{uint16(IconsFontAwesome6.Min), uint16(IconsFontAwesome6.Max16), 0}
- //io.Fonts().AddFontFromFileTTFV(fmt.Sprintf("fonts/ttf/%s",
- // IconsFontAwesome6.Filenames[1][1]),
- // fontAwesomeFontSize,
- // &fontAwesomeConfig,
- // imgui.SliceToPtr(IconRange))
+ IconRange := []imgui.Wchar{imgui.Wchar(IconsFontAwesome6.Min), imgui.Wchar(IconsFontAwesome6.Max16), 0}
+ io.Fonts().AddFontFromFileTTFV(fmt.Sprintf("%s",
+ IconsFontAwesome6.Filenames[1][1]),
+ fontAwesomeFontSize,
+ &fontAwesomeConfig,
+ imgui.SliceToPtr(IconRange))
////.\main.go:49:3: cannot use imgui.SliceToPtr(IconRange) (value of type *uint16) as *imgui.Wchar value in argument to io.Fonts().AddFontFromFileTTFV
backend.Run(loop) |
@gucio321 I don't know how to comment on that. bug.mp4 |
@Wolf65 I need to run this code on my machine since it seems that my debugger is broken on windows. |
It's a major project And in go.mod delete replace |
@Wolf65 it works for me??? |
Yes and 2 imgui no merge windows |
But I can't reproduce ur panic 😕 Should I do something special? |
oh no, I've just watched ur vide again... Does this panic appear randomly???? |
Uh, no. Like in the video ~3 starts up ~3 times then ~6 panics. |
could you try |
|
meh, Can't see anyghing useful unfortunately. |
I'm hitting this problem too. Did some |
I did a little more research and found the change that cause the issue: diff --git a/cimgui_structs.go b/cimgui_structs.go
index a53d5778..1b69681a 100644
--- a/cimgui_structs.go
+++ b/cimgui_structs.go
@@ -522,13 +522,24 @@ func newFontGlyphFromC(cvalue *C.ImFontGlyph) *FontGlyph {
// Helper to build glyph ranges from text/string data. Feed your application strings/characters to it then call BuildRanges().
// This is essentially a tightly packed of vector of 64k booleans = 8KB storage.
type FontGlyphRangesBuilder struct {
- // TODO: contains unsupported fields
- data unsafe.Pointer
+ FieldUsedChars Vector[*uint32] // Store 1-bit per Unicode code point (0=unused, 1=used)
}
func (self FontGlyphRangesBuilder) handle() (result *C.ImFontGlyphRangesBuilder, releaseFn func()) {
- result = (*C.ImFontGlyphRangesBuilder)(self.data)
- return result, func() {}
+ result = new(C.ImFontGlyphRangesBuilder)
+ FieldUsedChars := self.FieldUsedChars
+ FieldUsedCharsData := FieldUsedChars.Data
+ FieldUsedCharsDataArg, FieldUsedCharsDataFin := WrapNumberPtr[C.ImU32, uint32](FieldUsedCharsData)
+ FieldUsedCharsVecArg := new(C.ImVector_ImU32)
+ FieldUsedCharsVecArg.Size = C.int(FieldUsedChars.Size)
+ FieldUsedCharsVecArg.Capacity = C.int(FieldUsedChars.Capacity)
+ FieldUsedCharsVecArg.Data = FieldUsedCharsDataArg
+
+ result.UsedChars = *FieldUsedCharsVecArg
+ releaseFn = func() {
+ FieldUsedCharsDataFin()
+ }
+ return result, releaseFn
}
func (self FontGlyphRangesBuilder) c() (result C.ImFontGlyphRangesBuilder, fin func()) {
@@ -538,7 +549,7 @@ func (self FontGlyphRangesBuilder) c() (result C.ImFontGlyphRangesBuilder, fin f
func newFontGlyphRangesBuilderFromC(cvalue *C.ImFontGlyphRangesBuilder) *FontGlyphRangesBuilder {
result := new(FontGlyphRangesBuilder)
- result.data = unsafe.Pointer(cvalue)
+ result.FieldUsedChars = newVectorFromC(cvalue.UsedChars.Size, cvalue.UsedChars.Capacity, (*uint32)(cvalue.UsedChars.Data))
return result
}
|
IDK what happens here. I'll think about it but can't promise any other actionn on my side as I have no fast enough laptop here and this one is a bit too slow to effectively recompile cimgui-go so I can't do any tests now. |
I have a suspicion that the glyph range is not supposed to be deallocated... Here's a sample of how it's used to load a font sith a specific set of glyphs: bld := cimgui.NewFontGlyphRangesBuilder()
bld.AddRanges(atlas.GlyphRangesDefault())
bld.AddChar(cimgui.Wchar('⌘'))
rng := cimgui.NewGlyphRange()
bld.BuildRanges(rng)
atlas.AddFontFromMemoryTTFV(ptr, int32(len(data)), pixelSize, cfg, rng.Data()) I think |
maybe... could you try to |
I diff above was a bit outdated... on the latest main the data is actually pinned diff --git a/cimgui_structs.go b/cimgui_structs.go
index 36b723f1..f59703ad 100644
--- a/cimgui_structs.go
+++ b/cimgui_structs.go
@@ -530,13 +530,26 @@ func newFontGlyphFromC(cvalue *C.ImFontGlyph) *FontGlyph {
// Helper to build glyph ranges from text/string data. Feed your application strings/characters to it then call BuildRanges().
// This is essentially a tightly packed of vector of 64k booleans = 8KB storage.
type FontGlyphRangesBuilder struct {
- // TODO: contains unsupported fields
- data unsafe.Pointer
+ FieldUsedChars Vector[*uint32] // Store 1-bit per Unicode code point (0=unused, 1=used)
}
func (self FontGlyphRangesBuilder) handle() (result *C.ImFontGlyphRangesBuilder, releaseFn func()) {
- result = (*C.ImFontGlyphRangesBuilder)(self.data)
- return result, func() {}
+ result = new(C.ImFontGlyphRangesBuilder)
+ FieldUsedChars := self.FieldUsedChars
+ FieldUsedCharsData := FieldUsedChars.Data
+ FieldUsedCharsDataArg, FieldUsedCharsDataFin := WrapNumberPtr[C.ImU32, uint32](FieldUsedCharsData)
+ FieldUsedCharsVecArg := new(C.ImVector_ImU32)
+ FieldUsedCharsVecArg.Size = C.int(FieldUsedChars.Size)
+ FieldUsedCharsVecArg.Capacity = C.int(FieldUsedChars.Capacity)
+ FieldUsedCharsVecArg.Data = FieldUsedCharsDataArg
+ FieldUsedChars.pinner.Pin(FieldUsedCharsVecArg.Data)
+
+ result.UsedChars = *FieldUsedCharsVecArg
+ releaseFn = func() {
+ FieldUsedCharsDataFin()
+ FieldUsedChars.pinner.Unpin()
+ }
+ return result, releaseFn
}
func (self FontGlyphRangesBuilder) c() (result C.ImFontGlyphRangesBuilder, fin func()) {
@@ -546,7 +559,7 @@ func (self FontGlyphRangesBuilder) c() (result C.ImFontGlyphRangesBuilder, fin f
func newFontGlyphRangesBuilderFromC(cvalue *C.ImFontGlyphRangesBuilder) *FontGlyphRangesBuilder {
result := new(FontGlyphRangesBuilder)
- result.data = unsafe.Pointer(cvalue)
+ result.FieldUsedChars = newVectorFromC(cvalue.UsedChars.Size, cvalue.UsedChars.Capacity, (*uint32)(cvalue.UsedChars.Data))
return result
}
Unfortuantely that's didn't change anything |
meh I see. I suppose this whole |
It's been a while since I've worked with this repo, so I don't have enough insight to comment on that - But I'll be happy to test any changes 😄 |
I'll try to fix this but can't say when could it happen... |
No worries, I've just hacked it my apply the patch above If any one else is having this problem, a temporary solution is to use my branch which patches this: https://github.com/ptxmac/cimgui-go/tree/ptx_fixes Right now it's up to date with |
gengo_structs.go seemd to be extremely useful, however it generated several bugs that cannot be fixed using that engine. Some of the reported issues are: - AllenDang#206
gengo_structs.go seemd to be extremely useful, however it generated several bugs that cannot be fixed using that engine. Some of the reported issues are: - AllenDang#206
gengo_structs.go seemd to be extremely useful, however it generated several bugs that cannot be fixed using that engine. Some of the reported issues are: - AllenDang#206
This works for me now! 🎊 |
last PR
working option
when using NewGlyphRange/NewFontGlyphRangesBuilder
error
The text was updated successfully, but these errors were encountered: