Skip to content
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

Data race in rasterizer #21

Open
amlinux opened this issue Apr 10, 2022 · 0 comments
Open

Data race in rasterizer #21

amlinux opened this issue Apr 10, 2022 · 0 comments

Comments

@amlinux
Copy link

amlinux commented Apr 10, 2022

Rasterizer is doing an unsafe data access operation that results in a race:

==================
WARNING: DATA RACE
Write at 0x00c0003012f0 by goroutine 8:
  github.com/fogleman/fauxgl.(*Context).rasterize()
      external/com_github_fogleman_fauxgl/context.go:252 +0x109c
  github.com/fogleman/fauxgl.(*Context).drawClippedTriangle()
      external/com_github_fogleman_fauxgl/context.go:347 +0xa49
  github.com/fogleman/fauxgl.(*Context).DrawTriangle()
      external/com_github_fogleman_fauxgl/context.go:387 +0x924
  github.com/fogleman/fauxgl.(*Context).DrawTriangles.func1()
      external/com_github_fogleman_fauxgl/context.go:421 +0xda
  github.com/fogleman/fauxgl.(*Context).DrawTriangles·dwrap·3()
      external/com_github_fogleman_fauxgl/context.go:426 +0x47

Previous read at 0x00c0003012f0 by goroutine 15:
  github.com/fogleman/fauxgl.(*Context).rasterize()
      external/com_github_fogleman_fauxgl/context.go:232 +0x99c
  github.com/fogleman/fauxgl.(*Context).drawClippedTriangle()
      external/com_github_fogleman_fauxgl/context.go:347 +0xa49
  github.com/fogleman/fauxgl.(*Context).DrawTriangle()
      external/com_github_fogleman_fauxgl/context.go:387 +0x924
  github.com/fogleman/fauxgl.(*Context).DrawTriangles.func1()
      external/com_github_fogleman_fauxgl/context.go:421 +0xda
  github.com/fogleman/fauxgl.(*Context).DrawTriangles·dwrap·3()
      external/com_github_fogleman_fauxgl/context.go:426 +0x47

Goroutine 8 (running) created at:
  github.com/fogleman/fauxgl.(*Context).DrawTriangles()
      external/com_github_fogleman_fauxgl/context.go:417 +0x7b
  github.com/fogleman/fauxgl.(*Context).DrawMesh()
      external/com_github_fogleman_fauxgl/context.go:436 +0x54
<skipped>

The code in question even has a comment:

            if dc.ReadDepth && bz > dc.DepthBuffer[i] { // safe w/out lock?
                continue
            }

I think, a sync.RWMutex around accesses to DepthBuffer would fix it.

amlinux added a commit to JoyTeam/fauxgl that referenced this issue Apr 10, 2022
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

No branches or pull requests

1 participant