Segmentation faults when using GLFW3 #3209
-
Hello there. I'm trying to get a basic example working with BGFX and GLFW. However, every BGFX call I make after initializing it seems to cause a segfault. What am I doing wrong exactly? Thanks. edit: I'm following this guide #include "bgfx/defines.h"
#include <iostream>
#include <bgfx/bgfx.h>
#include <bgfx/platform.h>
#include <imgui/imgui.h>
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_X11
#include <GLFW/glfw3native.h>
#include "logo.h"
const int width = 1000;
const int height = 600;
int main() {
if (!glfwInit()) {
std::cout << "Error: failed initializing glfw" << std::endl;
return -1;
}
GLFWwindow *window = glfwCreateWindow(width, height, "demo", NULL, NULL);
if (!window) {
std::cout << "Error: failed creating window" << std::endl;
return -1;
}
bgfx::PlatformData pd;
pd.ndt = (void *) glfwGetX11Display();
pd.nwh = (void *)(uintptr_t) glfwGetX11Window(window);
pd.context = NULL;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx::setPlatformData(pd);
bgfx::Init bgfxInit;
bgfxInit.type = bgfx::RendererType::Count;
bgfxInit.resolution.width = width;
bgfxInit.resolution.height = height;
bgfxInit.resolution.reset = BGFX_RESET_VSYNC;
bgfx::init(bgfxInit);
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x303030ff, 1.0f, 0);
unsigned int counter = 0;
for (;;) {
bgfx::frame();
counter++;
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
} |
Beta Was this translation helpful? Give feedback.
Answered by
0xdeadbeer
Nov 30, 2023
Replies: 2 comments
-
I linked the project with the Debug libs, reran the program and got the following output:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I solved the problem by following the advice on the issue #1560 Now the code looks like this ...
bgfx::PlatformData pd;
pd.ndt = glfwGetX11Display();
pd.nwh = (void *)(uintptr_t) glfwGetX11Window(window);
// bgfx::setPlatformData(pd);
bgfx::Init bgfxInit;
bgfxInit.type = bgfx::RendererType::OpenGL;
bgfxInit.resolution.width = screen_width;
bgfxInit.resolution.height = screen_height;
bgfxInit.resolution.reset = BGFX_RESET_VSYNC;
bgfxInit.platformData = pd;
bgfx::init(bgfxInit);
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF, 1.0f, 0);
bgfx::setViewRect(0, 0, 0, screen_width, screen_height);
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
bgfx::touch(0);
bgfx::frame();
}
bgfx::shutdown();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
0xdeadbeer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I solved the problem by following the advice on the issue #1560
Now the code looks like this