cginternals / cginternals/globjects

State has wrong behavior

Open
#329 2 comments 0 reactions 0 assignees View on GitHub
bug design decision
Dominant language
C++
Stars
563
Forks
59
PR merge metrics
No merged PRs in 30d

Description

This code:
```
auto currentState = globjects::State::currentState();
[...] // No state related code here

// Then change some state
globjects::ref_ptr state = new globjects::State(globjects::State::ImmediateMode); // Apply immediately all changes
state->pixelStore(gl::GL_UNPACK_ALIGNMENT, 1); // In components size
state->pixelStore(gl::GL_UNPACK_ROW_LENGTH, width/3); // In components size

[...]
currentState->apply();
```
Trigger this GL error:
```
error: 0x500, high severity (API)
GL_INVALID_ENUM error generated. Polygon modes for are disabled in the current profile.
```
The backtrace for this error is:
```
#0 Stitcher::Application::__lambda0::operator() (__closure=0x10ed440, message=...) at ../src/Application.cpp:478
#1 0x00000000005b3f6d in std::_Function_handler::_M_invoke(const std::_Any_data &, const globjects::DebugMessage &) (__functor=..., __args#0=...)
at /usr/include/c++/4.8.2/functional:2071
#2 0x0000000000623649 in globjects::DebugImplementation_DebugKHR::debugMessageCallback(gl::GLenum, gl::GLenum, unsigned int, gl::GLenum, int, char const*, void const*) ()
#3 0x00007fffece62b18 in ?? () from /lib64/libnvidia-glcore.so.367.57
#4 0x00007fffece62c60 in ?? () from /lib64/libnvidia-glcore.so.367.57
#5 0x00007fffece62f22 in ?? () from /lib64/libnvidia-glcore.so.367.57
#6 0x000000000068e1c2 in glbinding::Function::call(gl::GLenum&, gl::GLenum&) const ()
#7 0x00000000007383e2 in gl::glPolygonMode(gl::GLenum, gl::GLenum) ()
#8 0x000000000062c851 in globjects::State::apply() ()
```

Clearly, it's dealing with polygon mode which I've not touched in my code.
I wonder if the "currentState" is a good idea at all. It's slow (because it loops other all states to restore them). I wonder if a per-thread storage list of modified state wouldn't be better. That is, any state changed with a State instance would append the previous state to a TLS's list (if it's not found in the list beforehand, obviously), and a static restoreState() would pop all item from the TLS's list to restore all the current modified state and not *all* the states like it's done currently, thus avoiding the error written above.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.