AllenDang/giu

[bug] Window grows until filling screen then app crashes

Closed this issue ยท 16 comments

What happend?

Title?

Code example

main.go
package main

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

func loop() {
	g.Window("main").Layout(
		g.Labelf("hi"),
	)
}

func main() {
	wnd := g.NewMasterWindow("main", 400, 200, 0)
	wnd.Run(loop)
}

To Reproduce

  1. Run my code
  2. see the crash...

Version

(latest)

OS

Windows 10

Hi,
thats really strange... could you try to run example from github.com/AllenDang/cimgui-go and lmk if it also fails? Giu has some extra logic about window handling.

Hi, thats really strange... could you try to run example from github.com/AllenDang/cimgui-go and lmk if it also fails? Giu has some extra logic about window handling.

Hi, I got the same issue as the issue creator, on Win10 as well, and for me the example from github.com/AllenDang/cimgui-go is working fine.

Thank you that's really valuable info. I'll look at our code later and try to find out whar may cause this

Added also a video about reproducing it:

WIN10-reproduced-AllenDanggiu-issues-810.mp4

I tried debugging it, but the UI element size increase happens while the code is running inside asm_amd64.s, so I guess the change is not immediate.

Is it specific for SingleWindow or for Window too?

Is it specific for SingleWindow or for Window too?

It's present for both.

could you try to debug your code in the following way:
clone giu repo and find example for which you rissue happens (I think hello world will be the best).
go to Window.go and find (*WindowWidget).Layout() method.
You'll find this line:

        showed := imgui.BeginV(Context.FontAtlas.RegisterString(w.title), w.open, imgui.WindowFlags(w.flags))

(and another one with imgui.End())

comment out everything else inside this function and check if your issue still exists. lmk about the result

I commented out the part, and ran the code, attached a video about it. (For me it's not playable, but after download it's working fine)
Though it has the same result (crash), and roughly the same effect (the label is expanding until crash), it's not entirely the same behavior. The label extension is a bit quicker, and it's jumping to other location too with this version.

WIN10-reproduced-AllenDanggiu-issues-810-with-changed-src.mp4

ok, thank you.
Could you tell me 2 more things:

  • does it happen only for labels or it does not matter?
  • what is the panic message exactly?

Answers:

  • It does not matter, it's the same behavior if the only content is InputTextMultiline as well.

Message and call stack:

PS C:\Temp\giu> go run "c:\Temp\giu\examples\helloworld\helloworld.go"
panic: Assertion failed!
File: D:/a/cimgui-go/cimgui-go/cimgui/imgui/imgui.cpp, Line 10226

Expression: g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting."


goroutine 1 [running]:
github.com/AllenDang/cimgui-go.init.func1({0xc0001c1500?, 0x0?}, {0xc00000ed20?, 0x7ff7bc6a3ac0?}, 0xc000138000?)
        C:/Users/Alex/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240424153022-294abe7370df/assert.go:28 +0x65
github.com/AllenDang/cimgui-go.goImguiAssertHandler(0xc00007fc50?, 0x7ff7bce316c0, 0xbc6296ef?)
        C:/Users/Alex/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240424153022-294abe7370df/assert.go:45 +0x67
github.com/AllenDang/cimgui-go._Cfunc_igGLFWRunLoop(0x25ece753cf0, 0x7ff7bc6a58e0, 0x7ff7bc6a5920, 0x7ff7bc6a5960, 0x7ff7bc6a59e0)
        _cgo_gotypes.go:24237 +0x4d
github.com/AllenDang/cimgui-go.(*GLFWBackend).Run.func1(0x7ff7bc55da01?)
        C:/Users/Alex/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240424153022-294abe7370df/glfw_backend.go:249 +0x9c    
github.com/AllenDang/cimgui-go.(*GLFWBackend).Run(0xc00006c050?, 0xc00006c050?)
        C:/Users/Alex/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240424153022-294abe7370df/glfw_backend.go:249 +0x32    
main.main.(*MasterWindow).Run.func1()
        C:/Temp/giu/MasterWindow.go:244 +0xcb
github.com/AllenDang/giu.mainthreadCallPlatform(...)
        C:/Temp/giu/mainthread_windows.go:12
github.com/AllenDang/giu.(*MasterWindow).Run(...)
        C:/Temp/giu/MasterWindow.go:236
main.main()
        c:/Temp/giu/examples/helloworld/helloworld.go:18 +0x67
exit status 2

With version github.com/AllenDang/giu@v0.7.0 the issue is not present.

Expression: g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting."
This seems to be important, but I think its not a case...

Do you use some special scaling in windows?
Try commenting out lines 125 and 126 in MasterWindow.go

I already did it for you on debug-810 branch of my fork. For quick setup:

git remote add gucio321 https://github.com/gucio321/giu
git fetch gucio321
git checkout gucio321/debug-810

I'm using a 4K monitor with 150% scaling.

If lines 125 and 126 are commented out, the helloworld example runs well, if they are left in the code, the issue is reproducible.

kรฉp

To me it seems that

imgui.CurrentStyle().ScaleAllSizes(xScale=1.5)

is called during each render frame, and it doesn't set the scale to an absolute 1.5 (150%), but it scales the current scale up by 150%, so it recursively scales up to infinity. Maybe it only needs a single call during initialization?

Edit:
this solved the issue, so perhaps this should be in the initialization section, not in the loop:

func (w *MasterWindow) setTheme() (fin func()) {
	// Scale DPI in windows
	if runtime.GOOS == "windows" && !w.initialized {
		w.initialized = true
		xScale, _ := Context.backend.ContentScale()
		imgui.CurrentStyle().ScaleAllSizes(xScale)
	}

ok, got it, thank you for help. Bugfix on the way ๐Ÿ˜„

As you can see, I'm going to issue a bugfix release v0.8.1 as soon as all remaining issues are fixed.
see here

PR merged. lmk if you still have problems.