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

it is crash with imgui-SDL renderer #921

Open
mumin16 opened this issue Oct 22, 2023 · 3 comments
Open

it is crash with imgui-SDL renderer #921

mumin16 opened this issue Oct 22, 2023 · 3 comments

Comments

@mumin16
Copy link

mumin16 commented Oct 22, 2023

/*
// Start the Dear ImGui frame
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();

// 1. Show the big demo window (Most of the sample code is in
// ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear
// ImGui!).
if (show_demo_window)
  ImGui::ShowDemoWindow(&show_demo_window);


ImGui::Render();

*/

// Rendering triangle

    sg_begin_default_pass(&pass_action, view_width, view_height);
    sg_apply_pipeline(pip);
    sg_apply_bindings(&bind);
    sg_draw(0, 3, 1);
    sg_end_pass();
    sg_commit();


//ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
SDL_RenderPresent(renderer);
@floooh
Copy link
Owner

floooh commented Oct 23, 2023

I will need some more information I'm afraid.

How does the error manifest, any error messages, ideally something to build and run myself.

@mumin16
Copy link
Author

mumin16 commented Oct 23, 2023

#include <GLES3/gl3.h>

#include <SDL2/SDL.h>
#include <imgui/backends/imgui_impl_sdl2.h>
#include <imgui/backends/imgui_impl_sdlrenderer2.h>
#include <imgui/imgui.h>

#define SOKOL_IMPL
#define SOKOL_GLES3

#include "sokol_gfx.h"
#include "sokol_log.h"

int view_width = 1280, view_height = 720;

int main(int, char **) {

// Setup SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
printf("Error: %s\n", SDL_GetError());
return -1;
}

// Create window with SDL_Renderer graphics context
SDL_WindowFlags window_flags =
(SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
SDL_Window *window = SDL_CreateWindow(
"Dear ImGui SDL2+SDL_Renderer example", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, view_width, view_height, window_flags);
SDL_Renderer *renderer = SDL_CreateRenderer(
window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
if (renderer == nullptr) {
SDL_Log("Error creating SDL_Renderer!");
return 0;
}
// SDL_RendererInfo info;
// SDL_GetRendererInfo(renderer, &info);
// SDL_Log("Current SDL_Renderer: %s", info.name);

// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
(void)io;
io.ConfigFlags |=
ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |=
ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls

// Setup Dear ImGui style
ImGui::StyleColorsDark();
// ImGui::StyleColorsLight();

// Setup Platform/Renderer backends
ImGui_ImplSDL2_InitForSDLRenderer(window, renderer);
ImGui_ImplSDLRenderer2_Init(renderer);

// Load Fonts
// - If no fonts are loaded, dear imgui will use the default font. You can
// also load multiple fonts and use ImGui::PushFont()/PopFont() to select
// them.
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you
// need to select the font among multiple.
// - If the file cannot be loaded, the function will return a nullptr. Please
// handle those errors in your application (e.g. use an assertion, or display
// an error and quit).
// - The fonts will be rasterized at a given size (w/ oversampling) and stored
// into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which
// ImGui_ImplXXXX_NewFrame below will call.
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype
// for higher quality font rendering.
// - Read 'docs/FONTS.md' for more instructions and details.
// - Remember that in C/C++ if you want to include a backslash \ in a string
// literal you need to write a double backslash \ !
// io.Fonts->AddFontDefault();
// io.Fonts->AddFontFromFileTTF("c:\Windows\Fonts\segoeui.ttf", 18.0f);
// io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
// io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
// io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
// ImFont* font =
// io.Fonts->AddFontFromFileTTF("c:\Windows\Fonts\ArialUni.ttf", 18.0f,
// nullptr, io.Fonts->GetGlyphRangesJapanese()); IM_ASSERT(font != nullptr);

// Our state
bool show_demo_window = true;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);

/* setup sokol_gfx */
sg_setup({
.logger.func = slog_func,
});

/* a vertex buffer */
const float vertices[] = {// positions // colors
0.0f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f,
0.5f, -0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f};
sg_buffer vbuf = sg_make_buffer({.data = SG_RANGE(vertices)});

/* a shader */
sg_shader shd = sg_make_shader({.vs.source = "#version 300 es\n"
"in vec4 position;\n"
"in vec4 color0;\n"
"out vec4 color;\n"
"void main() {\n"
" gl_Position = position;\n"
" color = color0;\n"
"}\n",
.fs.source = "#version 300 es\n"
"precision mediump float;\n"
"in vec4 color;\n"
"out vec4 frag_color;\n"
"void main() {\n"
" frag_color = color;\n"
"}\n"});

/* a pipeline state object (default render states are fine for triangle) */
sg_pipeline pip = sg_make_pipeline(
{.shader = shd,
.layout = {.attrs = {[0].format = SG_VERTEXFORMAT_FLOAT3,
[1].format = SG_VERTEXFORMAT_FLOAT4}}});

/* resource bindings */
sg_bindings bind = {.vertex_buffers[0] = vbuf};

/* default pass action (clear to grey) */
sg_pass_action pass_action = {0};

// Main loop
bool done = false;
while (!done) {
// Poll and handle events (inputs, window resize, etc.)
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to
// tell if dear imgui wants to use your inputs.
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to
// your main application, or clear/overwrite your copy of the mouse data.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input
// data to your main application, or clear/overwrite your copy of the
// keyboard data. Generally you may always pass all inputs to dear imgui,
// and hide them from your application based on those two flags.
SDL_Event event;
while (SDL_PollEvent(&event)) {
ImGui_ImplSDL2_ProcessEvent(&event);
if (event.type == SDL_QUIT)
done = true;
if (event.type == SDL_WINDOWEVENT &&
event.window.event == SDL_WINDOWEVENT_CLOSE &&
event.window.windowID == SDL_GetWindowID(window))
done = true;
}

// Start the Dear ImGui frame
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();

// 1. Show the big demo window (Most of the sample code is in
// ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear
// ImGui!).
if (show_demo_window)
  ImGui::ShowDemoWindow(&show_demo_window);

ImGui::Render();

// Rendering triangle

sg_begin_default_pass(&pass_action, view_width, view_height);
sg_apply_pipeline(pip);
sg_apply_bindings(&bind);
sg_draw(0, 3, 1);
sg_end_pass();
sg_commit();

ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
SDL_RenderPresent(renderer);

}

/* cleanup */
sg_shutdown();

// Cleanup
ImGui_ImplSDLRenderer2_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();

SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();

return 0;
}

@mumin16
Copy link
Author

mumin16 commented Oct 23, 2023

sokol_gfx.h:8204: void _sg_gl_begin_pass(_sg_pass_t *, const sg_pass_action *, int, int): Assertion `glGetError() == 0' failed.

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