Skip to content

Commit

Permalink
Fix invalid memory access in capture.dll
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadido3 committed Feb 8, 2024
1 parent dddaad9 commit 9cfb011
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bin/capture-b/Capture.pb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
; This software is released under the MIT License.
; https://opensource.org/licenses/MIT

EnableExplicit

UsePNGImageEncoder()

Declare Worker(*Dummy)
Expand All @@ -26,6 +28,8 @@ Structure WorkerInfo
workerNumber.i
EndStructure

#Workers = 8

; Returns the size of the main OpenGL rendering output.
ProcedureDLL GetGLViewportSize(*dims.GLViewportDims)
If Not *dims
Expand Down Expand Up @@ -61,16 +65,16 @@ ProcedureDLL AttachProcess(Instance)

CreateDirectory("mods/noita-mapcap/output/")

Static Workers = 8
Dim WorkerInfos.WorkerInfo(Workers-1)
For i = 0 To Workers-1
Static Dim WorkerInfos.WorkerInfo(#Workers-1)
Protected i
For i = 0 To #Workers-1
WorkerInfos(i)\workerNumber = i
CreateThread(@Worker(), @WorkerInfos(i))
Next
EndProcedure

Procedure Worker(*workerInfo.WorkerInfo)
Protected img, x, y
Protected img, x, y, sx, sy

Repeat
WaitSemaphore(Semaphore)
Expand Down Expand Up @@ -110,6 +114,8 @@ ProcedureDLL Capture(*capRect.RECT, x.l, y.l, sx.l, sy.l)
ProcedureReturn #False
EndIf

Protected imageID, hDC, *pixelBuffer

; Limit the desired capture area to the actual client area of the viewport.
If *capRect\left < 0 : *capRect\left = 0 : EndIf
If *capRect\top < 0 : *capRect\top = 0 : EndIf
Expand Down Expand Up @@ -182,8 +188,8 @@ EndProcedure

; IDE Options = PureBasic 6.04 LTS (Windows - x64)
; ExecutableFormat = Shared dll
; CursorPosition = 94
; FirstLine = 51
; CursorPosition = 116
; FirstLine = 99
; Folding = -
; Optimizer
; EnableThread
Expand Down
Binary file modified bin/capture-b/capture.dll
Binary file not shown.

0 comments on commit 9cfb011

Please sign in to comment.