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

Error when ImGui sets glfw window position #5783

Closed
androbytes opened this issue Oct 16, 2022 · 12 comments
Closed

Error when ImGui sets glfw window position #5783

androbytes opened this issue Oct 16, 2022 · 12 comments

Comments

@androbytes
Copy link

I get an error on this line:
image

Here is my code:

IMGUI_CHECKVERSION();
		ImGui::CreateContext();
		ImGuiIO& io = ImGui::GetIO(); (void)io;
		io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
		io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
		io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
		
		ImGui::StyleColorsDark();

		ImGui_ImplGlfw_InitForOpenGL((GLFWwindow*)window.get(), true);
		ImGui_ImplOpenGL3_Init("#version 410");

		window->Vsync(true);

		float lastTime = glfwGetTime();

		while (window->ShouldClose()) {
			Andromeda::Renderer::ClearCol(1, 0, 0, 1);

			ImGui_ImplOpenGL3_NewFrame();
			ImGui_ImplGlfw_NewFrame();
			ImGui::NewFrame();

			float delta = glfwGetTime() - lastTime;
			lastTime = glfwGetTime();

			{
				ImGui::Begin("Hello World!");
				ImGui::Text("beans");
				ImGui::End();
			}

			ImGui::Render();
			int display_w, display_h;
			glfwGetFramebufferSize((GLFWwindow*)window.get(), &display_w, &display_h);
			glViewport(0, 0, display_w, display_h);
			ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

			if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
				GLFWwindow* backupWindow = glfwGetCurrentContext();
				ImGui::UpdatePlatformWindows();
				ImGui::RenderPlatformWindowsDefault();
				glfwMakeContextCurrent(backupWindow);
			}

			sandbox->Update(delta);

			window->Poll();
		}

		ImGui_ImplOpenGL3_Shutdown();
		ImGui_ImplGlfw_Shutdown();
		ImGui::DestroyContext();

I built it into a lib if that could do anything to make it break.

@ocornut
Copy link
Owner

ocornut commented Oct 16, 2022

You need to specify which error and fill the exact issue template so we know eg which OS you are using.

@androbytes
Copy link
Author

androbytes commented Oct 16, 2022

I am running on windows, I am on the docking branch and I just get an error that says "exception thrown at ...". I am using v1.88 (latest as of now)

@PathogenDavid
Copy link
Contributor

@AnnoyingB A stack trace and the the full exception message would be helpful here. We can't just divine what's wrong with your program, especially when the code snippet provided is not self-contained.

@androbytes
Copy link
Author

image

@PathogenDavid
Copy link
Contributor

Looking at your screenshot it appears the call to glfwCreateWindow failed since vd->Window is null.

I'm not seeing an obvious reason it would be failing here.

If your engine is multi-threaded, make sure you aren't accessing the main window's OpenGL context from a different thread from the one where you call ImGui::UpdatePlatformWindows.

You should configure a GLFW error callback to get the error message. (See example_glfw_opengl3's usage for an example.)

@androbytes
Copy link
Author

image

@PathogenDavid
Copy link
Contributor

This appears to be the same as #5687, which unfortunately didn't really have a resolution.

Does this issue happen with the official example_glfw_opengl3 example?

Looking around the internet, it sounds like you probably just need to update your GPU drivers.


Also screenshots of consoles make it harder for people to search. Copy+pasting the error for the sake of searchability:

WGL: Failed to create OpenGL context

@androbytes
Copy link
Author

image
it is up-to-date :\

@androbytes
Copy link
Author

it works in the example

@androbytes
Copy link
Author

this is my glfw init code:

		const GLFWvidmode* mode = nullptr;
		GLFWmonitor* monitor = nullptr;

		if (!glfwInit()) {
			const char* description; 
			glfwGetError(&description);
			printf(description);
			return false;
		}

		if (props->fullscreen) {
			mode = glfwGetVideoMode(monitor);
			monitor = glfwGetPrimaryMonitor();

			glfwWindowHint(GLFW_RED_BITS, mode->redBits);
			glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
			glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
		}

		if (props->api == 0) {
			glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
			glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
			glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

			Andromeda::Logger::Print("OpenGL 4.1", LogType::Info);
		}

		if (props->api == 1) {
			glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
			glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
			glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

			Andromeda::Logger::Print("OpenGL 3.3", LogType::Info);
		}

		glfwWindowHint(GLFW_DECORATED, props->decorated);

		window = glfwCreateWindow(mode ? mode->width : props->sizeX, mode ? mode->height : props->sizeY, props->title.data(), monitor ? monitor : nullptr, nullptr);
		if (!window) {
			const char* description;
			glfwGetError(&description);
			Andromeda::Logger::Print(description, LogType::Critical);
			return false;
		}

		// For ImGui
		glfwMakeContextCurrent(window);

		Andromeda::Logger::Print("Window made", LogType::Info);

		return true;

@androbytes
Copy link
Author

I copied some code of the examples and it still doesn't work :\

@androbytes
Copy link
Author

I fixed it. I had the class "Window" stored as a unique ptr witch glfw didn't like. I just had to make it a normal variable.

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

3 participants