Comments (7)
Hi, glfw::init
returns an object of type GlfwLibrary
. That object terminate
s GLFW on destruction, so you have to store it somewhere. You cannot really store it in a smart pointer because I didn't think of moving it anywhere. You'll probably have to store it inside a struct
or a tuple
and store that in a smart pointer. I haven't tested it, but I think that this should work:
// Aggregate type
struct holder {
glfw::GlfwLibrary lib;
};
auto GLFW = std::make_unique<holder>(glfw::init());
You'll have to make sure that this object outlives all glfw objects and commands.
I admit that this wasn't the best design choice on my part, and I am planning to revise this and other parts of the library's interface.
from glfwpp.
It's just as I thought, but I tried putting init into a main() function before, hoping it stay in scope until the end of program. However it didn't have any effect.
Maybe storing it was removed by compiler since I didn't use it anywhere later.
And yes, I noted the storing of object in example and nodiscard inside.
What is different about not using vulkan thou? Why does it work?
from glfwpp.
Using Vulkan shouldn’t have any effect. Could you send your main
function, or at least it’s relevant parts?
from glfwpp.
glfw::init();
glfw::WindowHints{
.clientApi = glfw::ClientApi::None,
}.apply();
window = glfw::Window(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
...
// load of vulkan stuff here
...
while (!window->shouldClose()) {
glfw::pollEvents();
}
from glfwpp.
The problem with this code is that the GlfwLibrary
isn’t stored anywhere. It gets destructed immediately after the call to glfw::init
. You have to assign the result of init
to a variable.
int main() {
auto GLFW = glfw::init();
glfw::WindowHints{
.clientApi = glfw::ClientApi::None,
}.apply();
window = glfw::Window(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
...
// load of vulkan stuff here
...
while (!window->shouldClose()) {
glfw::pollEvents();
}
}
from glfwpp.
Oh, sorry. I actually stored the thing like you shown after previous comments.
Now it opens the window, but assertion error pops up anyway after it's closed.
P.S. I've just discovered that this problem lies in try catch block. I took it out of it and now it works properly.
Okay, i think my issue is fixed. Many thanks. Would love to find a way to actually put it inside the exception catcher thou.
from glfwpp.
It just came to my mind that there is an obscure trick you could use to declare in the exception block. You could allocate the library object using a shared pointer. Then, you would throw a custom exception that would internally store that same shared pointer. This would ensure that the library doesn’t get terminated until the catch block completes.
This is convoluted, and personally I’d just wrap the try catch block with a second try catch block. The key thing is to make the scope of the library object extend past the window.
from glfwpp.
Related Issues (14)
- Add move semantics to objects and consider their nullability HOT 6
- Add window parameter to window callbacks
- Separate GLFW examples from the main GLFW repository
- Add example testing inclusion by multiple translation units HOT 1
- Solve compilation issue with multiple translations units HOT 1
- Better C++ style error support.
- Use a different OpenGL loader
- Force LF line endings on all text files HOT 1
- Add `.editorconfig`
- Replace `CMakeSettings.json` with `CMakePresets.json`
- multiple windows HOT 13
- Add Conan support HOT 1
- Build failure on GCC 12.2.0: Missing include for `std::exchange` 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 glfwpp.