panic: runtime error: invalid memory address or nil pointer dereference
SSSOCPaulCote opened this issue · comments
I cloned the repo, and ran go test -v ./...
but I keep getting this error:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x1015168]
Manually testing this package by trying to follow the example on the main page with a running OPC server on my PC also yields this result.
I'm running go 1.17.1 on Windows 10. Here's my test code:
package main
import (
"fmt"
"github.com/konimarti/opc"
)
func main() {
c, _ := opc.NewConnection(
"Fluke.DAQ.OPC",
[]string{"DESKTOP-<redacted>"},
[]string{"Instrument 01.Module 3.Channel 304"},
)
defer c.Close()
fmt.Println(c.Read())
}
Investigating and it might have to do with NewAutomationObject
method in connection_windows.go
. At line 223, you declare a pointer of type ole.IUnknown
as such var unknown *ole.IUknown
but maybe anytime you declare a pointer, you should do it this way var unknown *ole.IUnknown = new(ole.IUnknown)
based on this article
goroutine 1 [running]:
github.com/go-ole/go-ole.(*IDispatch).VTable(...)
C:/Users/<redacted>/go/pkg/mod/github.com/go-ole/go-ole@v1.2.4/idispatch.go:18
github.com/go-ole/go-ole.getIDsOfName(0x0, {0xc0000cf7c8, 0x1, 0x12994c40598})
C:/Users/<redacted>/go/pkg/mod/github.com/go-ole/go-ole@v1.2.4/idispatch_windows.go:20 +0xc8
github.com/go-ole/go-ole.(*IDispatch).GetIDsOfName(...)
C:/Users/<redacted>/go/pkg/mod/github.com/go-ole/go-ole@v1.2.4/idispatch.go:22
github.com/go-ole/go-ole.(*IDispatch).GetSingleIDOfName(0xac4ea5, {0xcea9a4, 0x9bd487})
C:/Users/<redacted>/go/pkg/mod/github.com/go-ole/go-ole@v1.2.4/idispatch.go:47 +0x3b
github.com/go-ole/go-ole.(*IDispatch).InvokeWithOptionalArgs(0xc0000cf8b8, {0xcea9a4, 0x0}, 0x8, {0xc0000cf8a8, 0x1, 0x1})
C:/Users/<redacted>/go/pkg/mod/github.com/go-ole/go-ole@v1.2.4/idispatch.go:63 +0x3b
github.com/go-ole/go-ole/oleutil.CallMethod(...)
C:/Users/<redacted>/go/pkg/mod/github.com/go-ole/go-ole@v1.2.4/oleutil/oleutil.go:51
github.com/konimarti/opc.(*AutomationObject).GetOPCServers(0x0, {0xc00001a0d0, 0xc0000cf9b8})
C:/Users/<redacted>/go/src/github.com/konimarti/opc/connection_windows.go:183 +0x88
main.listCommand(0xc0000f4160)
Or maybe it's the go-ole package that needs to fix some pointer dereferencing issue.
Did you go through the Troubleshooting section? Try setting the architecture to $ENV:GOARCH="386" in Powershell and compile everything again. Most of the time, this is the issue or a wrong ProgID. Also, please add opc.Debug() before the opc.NewConnection call to print more debug-related information.
@konimarti setting GOARCH
to 386 worked. Thank you for responding. I'll close this issue!