Skip to content
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] Markdown crashes on window resize #928

Open
ioxenus opened this issue Dec 17, 2024 · 2 comments
Open

[bug] Markdown crashes on window resize #928

ioxenus opened this issue Dec 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@ioxenus
Copy link

ioxenus commented Dec 17, 2024

What happend?

The app crashes when there's a Markdown element (containing whatever, even just a line of plain text) and I resize the app's window. It doesn't crash if you resize quickly (or a little); so I guess it takes a bunch of update/refresh events to make the app crash.

Stacktrace:
goroutine 1 [running, locked to thread]:
github.com/AllenDang/cimgui-go/internal.(*Pool[...]).Allocate(0x104cda9a0, 0x1400025ad20)
	go/pkg/mod/github.com/!allen!dang/[email protected]/internal/pool.go:37 +0x164
github.com/AllenDang/cimgui-go/immarkdown.MarkdownLinkCallback.Handle(0x1400022f6f8?)
	go/pkg/mod/github.com/!allen!dang/[email protected]/immarkdown/cimmarkdown_typedefs.go:784 +0x34
github.com/AllenDang/cimgui-go/immarkdown.MarkdownConfig.SetLinkCallback({0x140001802a0}, 0x104c83e40?)
	go/pkg/mod/github.com/!allen!dang/[email protected]/immarkdown/cimmarkdown_funcs.go:459 +0x2c
github.com/AllenDang/giu.(*MarkdownWidget).OnLink(0x140000a3880, 0x104cd34b0)
	go/pkg/mod/github.com/!allen!dang/[email protected]/Markdown.go:95 +0x74
github.com/AllenDang/giu.Markdown({0x104b2f838, 0x3})
	go/pkg/mod/github.com/!allen!dang/[email protected]/Markdown.go:82 +0x118
main.loop()
	Projects/giu11md/main.go:12 +0x30
github.com/AllenDang/giu.(*MasterWindow).render(0x1400003c660)
	go/pkg/mod/github.com/!allen!dang/[email protected]/MasterWindow.go:253 +0x200
github.com/AllenDang/cimgui-go/backend.loopCallback()
	go/pkg/mod/github.com/!allen!dang/[email protected]/backend/backend.go:36 +0x44
github.com/AllenDang/cimgui-go/backend/glfwbackend._Cfunc_igGLFWRunLoop(0x134633410, 0x104845c48, 0x104845c94, 0x104845ce0, 0x104845d78)
	_cgo_gotypes.go:409 +0x30
github.com/AllenDang/cimgui-go/backend/glfwbackend.(*GLFWBackend).Run.func1(0x6f00000000001?)
	go/pkg/mod/github.com/!allen!dang/[email protected]/backend/glfwbackend/glfw_backend.go:264 +0xa8
github.com/AllenDang/cimgui-go/backend/glfwbackend.(*GLFWBackend).Run(0x10486dbe8?, 0x1400006eed8?)
	go/pkg/mod/github.com/!allen!dang/[email protected]/backend/glfwbackend/glfw_backend.go:264 +0x40
main.main.(*MasterWindow).Run.func1()
	go/pkg/mod/github.com/!allen!dang/[email protected]/MasterWindow.go:270 +0xe4
golang.design/x/hotkey/mainthread.Call(0x1400011c018)
	go/pkg/mod/golang.design/x/[email protected]/mainthread/os_darwin.go:36 +0x80
github.com/AllenDang/giu.mainthreadCallPlatform(...)
	go/pkg/mod/github.com/!allen!dang/[email protected]/mainthread_mac.go:9
github.com/AllenDang/giu.(*MasterWindow).Run(...)
	go/pkg/mod/github.com/!allen!dang/[email protected]/MasterWindow.go:262
main.main()
	Projects/giu11md/main.go:19 +0x88
exit status 2

Code example

main.go
package main

import (
	g "github.com/AllenDang/giu"
)

func loop() {
	var md_content = "[https://example.org](https://example.org)"

	g.SingleWindow().Layout(
		g.Row(
			g.Markdown(md_content),
		),
	)
}

func main() {
	w := g.NewMasterWindow("Markdown", 500, 300, 0)
	w.Run(loop)
}

To Reproduce

  1. Run my demo
  2. try resizing the window for a bit (it doesn't happen instantly)

Version

v0.11.0

OS

darwin / arm64 (macOS 14.6.1)

@ioxenus ioxenus added the bug Something isn't working label Dec 17, 2024
@gucio321
Copy link
Collaborator

panic: cimgui-go/internal.Pool: Allocate: Out of space!
	
	This means that you attempt to allocate too many callbacks for immarkdown.MarkdownLinkCallback.
	There are several possible solutions:
	- You forgot to call Clear() for the pool (e.g. on the end/beginning of the frame)
	- You've too many items calling Allocate without cleaning (more than 32).
	  I this is the case, plelase report an issue ane we'll increase pool limit for the type.
	
	Refer: https://github.com/AllenDang/cimgui-go/issues/224
	

You should also see this.

Generally giu should handle this. Why it doesn't?...

@gucio321
Copy link
Collaborator

I did an experiment:

diff --git a/Markdown.go b/Markdown.go
index 0f55f16..ee59b66 100644
--- a/Markdown.go
+++ b/Markdown.go
@@ -1,6 +1,7 @@
 package giu
 
 import (
+	"fmt"
 	"image"
 	"image/color"
 	"net/http"
@@ -82,6 +83,8 @@ func Markdown(md string) *MarkdownWidget {
 	}).OnLink(OpenURL)
 }
 
+var u = 0
+
 // OnLink sets another than default link callback.
 // NOTE: due to cimgui-go's limitation https://github.com/AllenDang/cimgui-go?tab=readme-ov-file#callbacks
 // we clear MarkdownLinkCallback pool every frame. No further action from you should be required (just feel informed).
@@ -92,6 +95,8 @@ func (m *MarkdownWidget) OnLink(cb func(url string)) *MarkdownWidget {
 		cb(link)
 	})
 
+	fmt.Println("call", u)
+	u++
 	m.getState().cfg.SetLinkCallback(&igCb)
 
 	return m
diff --git a/MasterWindow.go b/MasterWindow.go
index bd43c13..6749587 100644
--- a/MasterWindow.go
+++ b/MasterWindow.go
@@ -205,6 +205,7 @@ func (w *MasterWindow) beforeRender() {
 	// Clean callbacks
 	// see https://github.com/AllenDang/cimgui-go?tab=readme-ov-file#callbacks
 	immarkdown.ClearMarkdownLinkCallbackPool()
+	u = 0
 
 	Context.FontAtlas.rebuildFontAtlas()
 

and, u is not 0 all the time. SO this turns out to be related AllenDang/cimgui-go#345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants