Comments (5)
Hello,
hello_imgui does not use exceptions and does not make any assumptions about them being present or not. So I guess you can do whatever you like.
I consider it as a kind of window management system for Imgui that hides some its mechanics
Yes.
P.S. It would be worth to mention about thread safety/awareness too.
hello_imgui does not launch any thread at all.
from hello_imgui.
Thanks. To be able to use exceptions (and C++ does use them by default itself) or threads I must be sure the environment allows it. Imgui is almost a plane C library that does nothing about such support but it allows access to all the internals and do not have (or do not have many) callbacks that may throw. But as far as hello_imgui hides some internals and is built around the users’ callbacks (as I see from hello_world example) it shall provide exception safe guarantees or be aware about exceptions (allow a user somehow handle them and make hello_imgui intact). The same is valid about thread safeness – you are either thread safe or aware about threads (i.e. you provide some synchronization primitives that your clients may use).
I do have to wrap some Imgui code with my own thread/exception safe wrappers and this is OK though it means Imgui may not be used in real-life applications as is. But hello_imgui is a kind of wrapper itself and to have a wrapper around a wrapper…
hello_imgui does not launch any thread at all.
I do understand it. But the real applications inevitably do and your clients must know what to expect and how use hello_imgui in multi-threaded environment with exceptions.
In other words, your clients have to decide whether to use hello_imgui or write their own window management system (as I believe all them do for pure Imgui). I am not an expert in GUI applications and it is hard for me to estimate such cases myself so I rely on documentation heavily.
from hello_imgui.
If you look at the API overview, you will see these callbacks:
What HelloImGui::Run()
will do is simply:
- Init the backend and imgui
- launch a render loop (at approx 60 FPS) that will run on the application's main thread (more precisely the thread where HelloImGui::Run was called).
- This render loop will handle frames creation and call a combination of the callbacks (depending on the UI state) synchronously at each loop
- HelloImGui::Run() will finish execution only after the application window was closed.
The wording "callback" is thus perhaps not quite appropriate, but be assured that these callbacks are synchronous.
So in summary,
- hello-imgui does not make any exception safety guarantee, not anymore than imgui. However it does not launch any exception.
- If the code of the user provided callbacks may throw, then either (1) the user should add a catch clause in the callback that will catch them, or (2) HelloImGui::Run will throw them synchronously in the application main thread. Option (1) is of course the better choice.
- hello-imgui guarantees that at any given time, only one thread will be active inside hello-imgui (and in fact it does not create any thread).
- if callbacks need to access data that could be updated by a separate thread (for example a camera thread that would update a video image), the user is responsible to protect the access to this data (via mutex, atomics, ...)
from hello_imgui.
Ok, thank you. I see that in case of an error I have to invent some program behavior that would not crash the program. I cannot just throw an exception and stop thinking about the broken frame anymore. I can wrap the Imgui’s begin/end C-style paradigm with my own exception safe helpers but hello_imgui looks different and I am not sure I could use it the same way.
I wonder if there is a window manager for Imgui for C++ (the full-featured C++ with exceptions, threads, co-routines in the future, etc.)
from hello_imgui.
I cannot just throw an exception and stop thinking about the broken frame
Well, the callbacks that you provide are supposed to be consisting of mainly only GUI code (I.e ImGui calls). The business code should belong elsewhere, as for any program where the GUI is separated from the rest. You could plug signals and slots between callbacks and your business code for example (using Qt or boost::signal)
from hello_imgui.
Related Issues (20)
- Custom patched ImGui version HOT 3
- Google Closure compiler support is almost perfect except for this one line. HOT 22
- Offline usage: avoid re-downloading glfw and freetype HOT 2
- Unable to add left edge toolbar
- 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
- offline build HOT 13
- FontAwesome solid vs. regular HOT 4
- Problems with implot from vcpkg HOT 1
- RunnerParams backendType compatibility is broken HOT 1
- text blurry when connected to a non-retina external monitor HOT 4
- Improve HELLOIMGUI_WIN32_NO_CONSOLE implementation HOT 6
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.