BGFX: 'Failed to create swap chain'

Started by mangledpixel, December 15, 2019, 16:58:47

Previous topic - Next topic


I'm trying to create a BGFX frame buffer from a window created using GLFW, using bgfx_create_frame_buffer_from_nwh, but this always results in the error Fatal error 2: Failed to create swap chain. C:\projects\bgfx\src\renderer_d3d11.cpp line 4632 being thrown from the external BGFX thread (I set up a custom callback to catch it). The ultimate aim here is to create buffers for multiple windows, but this also fails in the case of a single window.

The relevant code:
long nwh;
		switch (Platform.get()) {
		case LINUX:		nwh = GLFWNativeX11.glfwGetX11Window(window); break;
		case MACOSX:	nwh = GLFWNativeCocoa.glfwGetCocoaWindow(window); break;
		case WINDOWS:	nwh = GLFWNativeWin32.glfwGetWin32Window(window); break;
		default:		nwh = NULL; break;
		log("Creating framebuffer for view "+view+" with window handle "+nwh);
		short frameBuffer = bgfx_create_frame_buffer_from_nwh(nwh, width, height, BGFX_TEXTURE_FORMAT_BGRA8, BGFX_TEXTURE_FORMAT_D24S8);

This is after calling bgfx_set_platform_data and bgfx_init, and after the GLFW window has been created.

Getting capabilities from BGFX shows true for BGFX_CAPS_SWAP_CHAIN and for BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER on the relevant format(s). Not sure what I'm doing wrong here, or if this is even the correct approach for rendering to multiple GLFW windows with BGFX.


Never mind, I figured it out. For future reference: you need to set the platformdata's nwh field to the native window handle of a valid window (doesn't matter which one) before trying to create framebuffers.