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

fix array decoding #510

Merged
merged 3 commits into from
Feb 19, 2024
Merged

fix array decoding #510

merged 3 commits into from
Feb 19, 2024

Conversation

markus-wa
Copy link
Owner

@markus-wa markus-wa commented Feb 15, 2024

see #509

I'm not really sure why the old version was crashing on all versions of Go except 1.21 - but this should fix array decoding to be much more consistent.

Previously PropertyUpdate events contained either a fieldState or an int, now it's always an array.

@markus-wa markus-wa requested a review from akiver February 15, 2024 13:28
Copy link

codecov bot commented Feb 15, 2024

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (24ab81c) 80.49% compared to head (64c9c37) 80.70%.

❗ Current head 64c9c37 differs from pull request most recent head 18bd5cb. Consider uploading reports for the commit 18bd5cb to get more accurate results

Files Patch % Lines
pkg/demoinfocs/sendtables2/entity.go 84.00% 3 Missing and 1 partial ⚠️
pkg/demoinfocs/sendtables2/serializer.go 33.33% 3 Missing and 1 partial ⚠️
pkg/demoinfocs/sendtables2/field_state.go 84.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #510      +/-   ##
==========================================
+ Coverage   80.49%   80.70%   +0.21%     
==========================================
  Files          47       47              
  Lines        6367     6401      +34     
==========================================
+ Hits         5125     5166      +41     
+ Misses       1029     1021       -8     
- Partials      213      214       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@markus-wa markus-wa force-pushed the fix-array-decoding branch 2 times, most recently from 3cb8a8a to d7f89fd Compare February 15, 2024 14:40
@BestAwperEver
Copy link
Contributor

It still fails for me, but now at least I can create a replicable example (here's the match):

package main

import (
	dem "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs"
	"github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/events"
	"log"
	"os"
)

func main() {
	f, err := os.Open("1-f06e69ac-25e4-4a11-a7ec-092bdf1c4f69-1-1.dem")

	if err != nil {
		log.Panic("failed to open demo file: ", err)
	}
	defer f.Close()

	p := dem.NewParser(f)
	defer p.Close()

	p.RegisterEventHandler(func(e events.FrameDone) {
		for _, pl := range p.GameState().Participants().All() {
			pl.MVPs()
		}
	})

	err = p.ParseToEnd()
	if err != nil {
		panic(err)
	}
}

panic: interface conversion: interface {} is nil, not int32 at pkg/demoinfocs/sendtables/propdecoder.go:137

@markus-wa
Copy link
Owner Author

can you send the full stacktrace please @BestAwperEver 🙏

@BestAwperEver
Copy link
Contributor

Sure! Is it still non-replicable though?

panic: interface conversion: interface {} is nil, not int32
stacktrace:
goroutine 18 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x64
github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs.NewParserWithConfig.func1({0x1008f10e0, 0x14000a3c690})
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/demoinfocs-golang/v4@v4.0.3-0.20240215151838-f39979ec2282/pkg/demoinfocs/parser.go:403 +0x2c
github.com/markus-wa/godispatch.(*Dispatcher).dispatchWithRecover.func1()
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/godispatch@v1.4.1/dispatch.go:197 +0x48
panic({0x1008f10e0?, 0x14000a3c690?})
        /usr/local/go/src/runtime/panic.go:914 +0x218
github.com/markus-wa/godispatch.callConsumerCode.func1()
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/godispatch@v1.4.1/dispatch.go:122 +0x60
panic({0x1008f10e0?, 0x14000a3c680?})
        /usr/local/go/src/runtime/panic.go:914 +0x218
github.com/markus-wa/godispatch.callConsumerCode.func1()
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/godispatch@v1.4.1/dispatch.go:122 +0x60
panic({0x1008c9ea0?, 0x14001186ff0?})
        /usr/local/go/src/runtime/panic.go:914 +0x218
github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/sendtables.PropertyValue.Int(...)
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/demoinfocs-golang/v4@v4.0.3-0.20240215151838-f39979ec2282/pkg/demoinfocs/sendtables/propdecoder.go:137
github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/common.getInt(...)
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/demoinfocs-golang/v4@v4.0.3-0.20240215151838-f39979ec2282/pkg/demoinfocs/common/entity_util.go:10
github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/common.(*Player).MVPs(0x14000583380)
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/demoinfocs-golang/v4@v4.0.3-0.20240215151838-f39979ec2282/pkg/demoinfocs/common/player.go:746 +0x270
main.main.func1({})
        /Users/mshirobokov/GolandProjects/cs2-test0/main.go:23 +0x60
reflect.Value.call({0x10088a8e0?, 0x1400019c408?, 0x14000a8d528?}, {0x1007eae97, 0x4}, {0x14000a8d630, 0x1, 0x1008e9de0?})
        /usr/local/go/src/reflect/value.go:596 +0x994
reflect.Value.Call({0x10088a8e0?, 0x1400019c408?, 0x14000b95b00?}, {0x14000a8d630?, 0xf700014000a8d618?, 0x0?})
        /usr/local/go/src/reflect/value.go:380 +0x94
github.com/markus-wa/godispatch.callConsumerCode({0x10088a8e0?, 0x1400019c408?, 0x14000a8d5f8?}, {0x14000a8d630?, 0x140002fe700?, 0x0?})
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/godispatch@v1.4.1/dispatch.go:125 +0x44
github.com/markus-wa/godispatch.(*Dispatcher).Dispatch(0x14000184300, {0x1008c09a0, 0x100de32a0})
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/godispatch@v1.4.1/dispatch.go:111 +0x1fc
github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs.(*parser).handleFrameParsed(0x140002fe700, 0x0)
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/demoinfocs-golang/v4@v4.0.3-0.20240215151838-f39979ec2282/pkg/demoinfocs/parsing.go:527 +0x48
reflect.Value.call({0x10088b460?, 0x14000198ab0?, 0x14000a8ddd8?}, {0x1007eae97, 0x4}, {0x14000a8dee0, 0x1, 0x0?})
        /usr/local/go/src/reflect/value.go:596 +0x994
reflect.Value.Call({0x10088b460?, 0x14000198ab0?, 0x0?}, {0x14000a8dee0?, 0xdc00000000000000?, 0x0?})
        /usr/local/go/src/reflect/value.go:380 +0x94
github.com/markus-wa/godispatch.callConsumerCode({0x10088b460?, 0x14000198ab0?, 0x14000a8de98?}, {0x14000a8dee0?, 0x14000100000?, 0x10050c4c4?})
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/godispatch@v1.4.1/dispatch.go:125 +0x44
github.com/markus-wa/godispatch.(*Dispatcher).Dispatch(0x140001842a0, {0x100876e20, 0x100de32a0})
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/godispatch@v1.4.1/dispatch.go:111 +0x1fc
github.com/markus-wa/godispatch.(*Dispatcher).dispatchWithRecover(0x140001842b8?, {0x100876e20?, 0x100de32a0?})
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/godispatch@v1.4.1/dispatch.go:202 +0x50
github.com/markus-wa/godispatch.(*Dispatcher).dispatchQueue(0x140001842a0, 0x0?)
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/godispatch@v1.4.1/dispatch.go:177 +0xcc
created by github.com/markus-wa/godispatch.(*Dispatcher).AddQueues in goroutine 1
        /Users/mshirobokov/go/pkg/mod/github.com/markus-wa/godispatch@v1.4.1/dispatch.go:162 +0x1ac


goroutine 1 [running]:
main.main()
        /Users/mshirobokov/GolandProjects/cs2-test0/main.go:29 +0x1fc

Process finished with the exit code 2

@markus-wa
Copy link
Owner Author

markus-wa commented Feb 15, 2024

@BestAwperEver that's a CS:GO demo, right?

Or is it actually CS2? sorry I'm on my phone - I didn't expect propdecoder.go in a cs2 stack trace

@BestAwperEver
Copy link
Contributor

BestAwperEver commented Feb 16, 2024

The filestamp is "PBDEMS2" and the match was played on February 12, so I'm pretty sure it's CS2. Don't mind the link -- it contains "csgo" instead of "cs2" (and works as well if you replace "csgo" by "cs2") just because I've created it manually from the old link on a CS:GO match by replacing the ID which I got from the demo file name 😃

@markus-wa
Copy link
Owner Author

markus-wa commented Feb 19, 2024

@BestAwperEver can you try again with go get github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs@5d503e7f3df1fb5b207777c6810d72fafc1ed1c7

@markus-wa markus-wa enabled auto-merge February 19, 2024 12:45
@markus-wa markus-wa merged commit 600fc4e into master Feb 19, 2024
6 checks passed
@markus-wa markus-wa deleted the fix-array-decoding branch February 19, 2024 12:50
@BestAwperEver
Copy link
Contributor

I assume you've already tested it, but I ran the demo on the current master and encountered no issues with the code above. Thanks!

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.

2 participants