Comments (3)
Thanks for the detailed rundown! You are right, it is indeed crashing on delete Explorer::Instance;
. A callback like that is exactly what I was looking for, thank you!
from hello_imgui.
Hello,
Hum, this is not an easy issue.
glDeleteTextures is pointing to invalid memory.
Do you mean that the function pointer is then invalid?
If so, here is a possible analysis (I'm sorry if I drown you under technical details).
Based on what I saw in your code, this is want I understood:
class Explorer
{
public:
static Explorer* Instance; // You have a static pointer that contains an ImageGlPtr
private:
HelloImGui::ImageGlPtr m_imgBackground;
...
int main()
{
make_test_page();
Explorer::Instance = new Explorer();
// I suppose this launches hello_imgui (which in turn inits the glad openGl Loader)
Explorer::Instance->Run();
// Do you encounter the bug here (which would mean that the OpenGL loader
// was "unloaded" ?
delete Explorer::Instance;
Explorer::Instance = nullptr;
return 0;
}
Below, more details about the internals of hello_imgui:
By default, you should be using glad, see external/hello_imgui/CMakeLists.txt:
if (IOS OR EMSCRIPTEN)
set(need_opengl_loader OFF)
else()
set(need_opengl_loader ON)
endif()
option(HELLOIMGUI_USE_GLAD "Use Glad OpenGl loader" ${need_opengl_loader})
In this case, glad is loaded here (and this should make the opengl function pointers ok), in the case of the glfw backend:
void RunnerGlfwOpenGl3::Impl_InitGlLoader()
{
#ifndef __EMSCRIPTEN__
// Initialize OpenGL loader
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
bool err = gl3wInit() != 0;
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
bool err = glewInit() != GLEW_OK;
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
// You code should run this part
// this is were the glad openGl loader is inited
bool err = gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress)) == 0;
#else
bool err = false; // If you use IMGUI_IMPL_OPENGL_LOADER_CUSTOM, your loader is likely to requires
// some form of initialization.
#endif
if (err)
{
HIMG_THROW("RunnerGlfwOpenGl3::Impl_InitGlLoader(): Failed to initialize OpenGL loader!");
}
#endif // #ifndef __EMSCRIPTEN__
}
Below is an analysis of what happens once the glfw backend is stopped.
void RunnerGlfwOpenGl3::Impl_Cleanup()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(mWindow);
glfwTerminate();
// Could you test whether the glDeleteTextures function pointer
// was invalidated by the call to glfwTerminate ?
}
I suspect the glDeleteTextures function pointer might have been invalidated by the call to glfwTerminate() inside RunnerGlfwOpenGl3::Impl_Cleanup().
I'm still pondering what is the best solution for that.
In the meantime, may be you could try to add an exit button? This way you could trap the exit, and handle the destruction before OpenGL is deinited;
For a more complete approach, may be we could add a PreExit
callback that would be called before destroying the openGl context (its rule would be symmetrical to PostInit).
May be something like this:
struct RunnerCallbacks
{
VoidFunction ShowGui = {};
VoidFunction ShowMenus = {};
VoidFunction ShowStatus = {};
VoidFunction PostInit = {};
VoidFunction PreExit = {}; // Add this new callback
...
}
// And this new callback could be called here:
void AbstractRunner::TearDown()
{
params.callbacks.PreExit();
Impl_Cleanup();
}
from hello_imgui.
I added a BeforeExit
callback: see b7d78de
I think it should be enough to delete your ImageGl in this callback.
from hello_imgui.
Related Issues (20)
- Pre-exit behavior HOT 1
- An api which can help us get assets folder path HOT 2
- IDBFS Support HOT 1
- Imgui Ini Settings Parts HOT 2
- requrest:How to know which dockspace is currently active HOT 2
- not working on linux ubuntu HOT 1
- Some question about hello_imgui_ini_settings HOT 1
- How to set the no_docking and no_tab_bar for the MainDockSpace ? HOT 3
- Bisect MoveWindowToMonitor HOT 1
- Custom drawing behind GUI not possible due to Impl_Frame_3D_ClearColor() HOT 2
- macOS bundle support HOT 2
- Can I change a borderless window size? HOT 3
- Metal backend + emscripten favicon and shell template HOT 22
- Ability to put user menu items between the App Menu and the View Menu HOT 1
- Sdl Dpi awareness on Windows / multiple monitors HOT 1
- New back-end default HOT 3
- adding generated files to assets directory? HOT 8
- freetype dependency in Windows HOT 4
- how to add a toolbar (or other fixed windows) that limits the available main docking space? HOT 9
- Is there a way to make input_text to show only the last part of the text while deactivated HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hello_imgui.