Skip to content

Fix: Ensure OpenGL context is initialized for GrayscaleFilter #197

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vlivashkin
Copy link

Problem:
GrayscaleFilter was crashing with Segmentation fault during initialization because it was creating OpenGL shaders outside of the OpenGL context. This affected all filters that depend on GrayscaleFilter (like CannyEdgeDetectionFilter).

Fix:
Added SyncRunWithContext in GrayscaleFilter::Create() to ensure shader creation happens in the correct OpenGL context:

std::shared_ptr<GrayscaleFilter> GrayscaleFilter::Create() {
  auto ret = std::shared_ptr<GrayscaleFilter>(new GrayscaleFilter());
  gpupixel::GPUPixelContext::GetInstance()->SyncRunWithContext([&] {
    if (!ret->Init()) {
      ret.reset();
    }
  });
  return ret;
}

Testing:
Both GrayscaleFilter and CannyEdgeDetectionFilter now work correctly.

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

Successfully merging this pull request may close these issues.

1 participant