openframeworks / openframeworks/openFrameworks

multiple cairo renderers threading suffers from global style state leaks

Open
#2,086 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug core section-2D
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

I am using a Cairo renderer with a background threaded drawing, of which I have 8 threads running.

There are several instances where the global style is referenced and therefor causes unpredictable behavior. For example in:

 void ofCairoRenderer::draw(ofPath & shape){
      ....
      c.a = shape.getStrokeColor().a/255. * ofGetStyle().color.a; 
      ....
 }

This causes frames to intermittently show up blank. @arturoc is this outside of the expected use of Cairo?

Here is a snippet on how it's being used

cairoRenderer.setupMemoryOnly(ofCairoRenderer::IMAGE, false, false, ofRectangle(0,0,videoPixels.getWidth(), videoPixels.getHeight()) );
cairoRenderer.setupGraphicDefaults();
cairoRenderer.background(0);

for (int i = 0; i < contours.size(); i++){
        ofPath contourPath;
        for(int p = 0; p < contours.getPolyline(i).getVertices().size(); p++){
            contourPath.lineTo(contours.getPolyline(i).getVertices()[p]);
        }
        contourPath.close();

        cairoRenderer.setColor(ofColor::white);
        contourPath.setFillColor(ofColor::white);
        cairoRenderer.draw(contourPath);            
    }
}



cairoRenderer.flush();

ofPixels resized = cairoRenderer.getImageSurfacePixels();
resized.setImageType(OF_IMAGE_COLOR);
resized.resize(faceTargetRectangle.getWidth(), faceTargetRectangle.getHeight(), OF_INTERPOLATE_BICUBIC);
resized.pasteInto(outputImage, faceTargetRectangle.x, faceTargetRectangle.y);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ofCairoRenderer::draw, especially the ofGetStyle().color access shown in the report, and trace other global-style references used by the Cairo renderer. Reproduce the memory-only renderer with multiple background drawing threads and verify that frames no longer intermittently appear blank.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.