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

vulkan.CreateInstance throws runtime error #21

Closed
jclc opened this issue Jul 23, 2018 · 6 comments
Closed

vulkan.CreateInstance throws runtime error #21

jclc opened this issue Jul 23, 2018 · 6 comments

Comments

@jclc
Copy link
Member

jclc commented Jul 23, 2018

Calling CreateInstance panics with runtime error: cgo argument has Go pointer to Go pointer.

appInfo := &vk.ApplicationInfo{
	SType:              vk.StructureTypeApplicationInfo,
	PApplicationName:   title,
	ApplicationVersion: vk.MakeVersion(0, 0, 0),
	PEngineName:        "No Engine",
	EngineVersion:      vk.MakeVersion(0, 0, 0),
	ApiVersion:         vk.ApiVersion10,
}
createInfo := &vk.InstanceCreateInfo{
	SType:            vk.StructureTypeInstanceCreateInfo,
	PApplicationInfo: appInfo,
}

if ret := vk.CreateInstance(createInfo, nil, &vkInstance); ret != vk.Success {
	return errors.New("failed to create Vulkan instance")
}
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 1 [running]:
github.com/vulkan-go/vulkan.CreateInstance.func1(0x1b10470, 0x0, 0x785048, 0xc4200b2060)
        /home/vhns/projects/go/src/github.com/vulkan-go/vulkan/vulkan.go:24 +0xa2
github.com/vulkan-go/vulkan.CreateInstance(0xc420069ea8, 0x0, 0x785048, 0xa)
        /home/vhns/projects/go/src/github.com/vulkan-go/vulkan/vulkan.go:24 +0x4d
gitlab.com/jclc/game/graphics.Init(0x4f4e7f, 0xa, 0xc4200b0020, 0x5073a0)
        /home/vhns/projects/go/src/gitlab.com/jclc/game/graphics/vulkan.go:51 +0x19e
main.main()
        /home/vhns/projects/go/src/gitlab.com/jclc/game/main.go:12 +0x3a
exit status 2
@jclc jclc changed the title Cannot pass nil AllocationCallbacks pointer to CreateInstance vulkan.CreateInstance throws runtime error Jul 23, 2018
@xlab
Copy link
Member

xlab commented Jul 24, 2018

Did you use var vkInstance vk.Instance?
Also, what platform do you have?

@jclc
Copy link
Member Author

jclc commented Jul 24, 2018

Yes, var vkInstance vk.Instance defined as a package-wide variable. Using Linux desktop. I'm at work right now so I can't post the full thing but there isn't much code before this.

@jclc
Copy link
Member Author

jclc commented Jul 24, 2018

Declaring vkInstance right before the function call instead of as a top-level variable seems to fix that particular error, but now I'm getting a segfault in the C code

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]

runtime stack:
runtime.throw(0x4fa724, 0x2a)
        /usr/lib/go/src/runtime/panic.go:616 +0x81
runtime.sigpanic()
        /usr/lib/go/src/runtime/signal_unix.go:372 +0x28e

goroutine 1 [syscall]:
runtime.cgocall(0x4b9f50, 0xc420069de8, 0x4a6775)
        /usr/lib/go/src/runtime/cgocall.go:128 +0x64 fp=0xc420069db8 sp=0xc420069d80 pc=0x412b64
github.com/vulkan-go/vulkan._Cfunc_callVkCreateInstance(0x199aa90, 0x0, 0xc4200a4078, 0x0)
        _cgo_gotypes.go:4253 +0x4d fp=0xc420069de8 sp=0xc420069db8 pc=0x4a54ed
github.com/vulkan-go/vulkan.CreateInstance.func1(0x199aa90, 0x0, 0xc4200a4078, 0xc4200a4078)
        /home/vhns/projects/go/src/github.com/vulkan-go/vulkan/vulkan.go:24 +0xc4 fp=0xc420069e20 sp=0xc420069de8 pc=0x4a6bd4
github.com/vulkan-go/vulkan.CreateInstance(0xc420069ea8, 0x0, 0xc4200a4078, 0x4f4289)
        /home/vhns/projects/go/src/github.com/vulkan-go/vulkan/vulkan.go:24 +0x4d fp=0xc420069e50 sp=0xc420069e20 pc=0x4a69cd
gitlab.com/jclc/game/graphics.Init(0x4f4f61, 0xa, 0xc4200b0020, 0x5074a0)
        /home/vhns/projects/go/src/gitlab.com/jclc/game/graphics/vulkan.go:52 +0x254 fp=0xc420069f30 sp=0xc420069e50 pc=0x4a7c94
main.main()
        /home/vhns/projects/go/src/gitlab.com/jclc/game/main.go:12 +0x3a fp=0xc420069f88 sp=0xc420069f30 pc=0x4a7f2a
runtime.main()
        /usr/lib/go/src/runtime/proc.go:198 +0x212 fp=0xc420069fe0 sp=0xc420069f88 pc=0x439ba2
runtime.goexit()
        /usr/lib/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc420069fe8 sp=0xc420069fe0 pc=0x460a21
exit status 2

I can build and run the vulkancube demo just fine.

@jclc
Copy link
Member Author

jclc commented Jul 26, 2018

Here's output from GDB. I'm stumped.

(gdb) run
Starting program: /home/vhns/projects/go/src/gitlab.com/jclc/game/game
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff42ae700 (LWP 24598)]
[New Thread 0x7ffff3aad700 (LWP 24599)]
[New Thread 0x7ffff32ac700 (LWP 24600)]
[New Thread 0x7ffff2aab700 (LWP 24601)]
[New Thread 0x7ffff22aa700 (LWP 24602)]

Thread 1 "game" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) backtrace
#0  0x0000000000000000 in ?? ()
#1  0x00000000004ba04f in _cgo_526486ca5792_Cfunc_callVkCreateInstance (v=0xc420069dd0) at cgo-gcc-prolog:1260
#2  0x000000000045fd20 in runtime.asmcgocall () at /usr/lib/go/src/runtime/asm_amd64.s:688
#3  0x000000c4200a8090 in ?? ()
#4  0x000000c420098450 in ?? ()
#5  0x0000000000000000 in ?? ()

@jclc
Copy link
Member Author

jclc commented Jul 26, 2018

My bad. Didn't realise vulkan-go required a call to Init() from both itself and glfw.

@jclc jclc closed this as completed Jul 26, 2018
@jclc
Copy link
Member Author

jclc commented Jul 27, 2018

In my defense though, the documentation is pretty much non-existent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants