Skip to content

Commit

Permalink
fix data race appearing when trying to add mpqs to the project
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Nov 28, 2024
1 parent 3b6b5c4 commit 16031d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/gucio321/HellSpawner
go 1.23.3

require (
github.com/AllenDang/giu v0.11.1-0.20241126223035-127b1890fcfb
github.com/AllenDang/giu v0.11.1-0.20241127193319-4536adce5d46
github.com/OpenDiablo2/OpenDiablo2 v0.0.0-20210514222603-a688d660a0f7
github.com/OpenDiablo2/dialog v0.0.0-20201230220514-26162241209f
github.com/enriquebris/goconcurrentqueue v0.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/AllenDang/giu v0.11.1-0.20241126215915-4bc05bbbfea7 h1:JXQDuG3pYnrBfN
github.com/AllenDang/giu v0.11.1-0.20241126215915-4bc05bbbfea7/go.mod h1:sxKZ1fD18qc57i2xLMVCfgvljeDntFPDpuheF29orNw=
github.com/AllenDang/giu v0.11.1-0.20241126223035-127b1890fcfb h1:xKJeQlfbd95nbYd+yLIhEXWtISInQwvpkvvZDI9I/Tc=
github.com/AllenDang/giu v0.11.1-0.20241126223035-127b1890fcfb/go.mod h1:sxKZ1fD18qc57i2xLMVCfgvljeDntFPDpuheF29orNw=
github.com/AllenDang/giu v0.11.1-0.20241127193319-4536adce5d46 h1:+sGvyKihHGE0odVsLH8j6V2CfDysXQNdB/OdMewY60w=
github.com/AllenDang/giu v0.11.1-0.20241127193319-4536adce5d46/go.mod h1:sxKZ1fD18qc57i2xLMVCfgvljeDntFPDpuheF29orNw=
github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 h1:dKZMqib/yUDoCFigmz2agG8geZ/e3iRq304/KJXqKyw=
github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8/go.mod h1:b4uuDd0s6KRIPa84cEEchdQ9ICh7K0OryZHbSzMca9k=
github.com/AllenDang/imgui-go v1.12.1-0.20221124025851-59b862ca5a0c h1:kiXjH0n0KzOpvhgy3nDFkPmKfg4A+QWsEOwxwWy6yuI=
Expand Down
7 changes: 6 additions & 1 deletion pkg/common/hsproject/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,18 @@ func (p *Project) ReloadAuxiliaryMPQs(cfg *config.Config) (err error) {
p.mpqs = make([]d2interface.Archive, len(p.AuxiliaryMPQs))

wg := sync.WaitGroup{}
m := &sync.Mutex{}
wg.Add(len(p.AuxiliaryMPQs))

for mpqIdx := range p.AuxiliaryMPQs {
go func(idx int) {
fileName := filepath.Join(cfg.AuxiliaryMpqPath, p.AuxiliaryMPQs[idx])

if data, mpqErr := d2mpq.FromFile(fileName); mpqErr != nil {
m.Lock()
data, mpqErr := d2mpq.FromFile(fileName)
m.Unlock()

if mpqErr != nil {
err = mpqErr
} else {
p.mpqs[idx] = data
Expand Down

0 comments on commit 16031d8

Please sign in to comment.