Code: Select all
test := IWICImagingFactory.New()
; msgbox "Works, but ends with error on [ test.obj := '' ] "
ObjRelease(test.obj.ptr)
; msgbox "this causes an error"
test.obj := ""
; Msgbox "this doesn't cause an error"
class IWICImagingFactory {
ptr := 0
obj := 0
CLSID := [0xcacaf262, 0x9370, 0x4615, 0xa1, 0x3b, 0x9f, 0x55, 0x39, 0xda, 0x4c, 0xa]
IID := "{ec5ec8a9-c395-4314-9c77-54d7a935ff70}"
__New(inPtr:=0) {
this.obj := ComObjCreate(this.CLSID_str(this.CLSID), this.IID)
}
__Delete() {
}
CLSID_str(inCLSID, out_str:="") { ; create CLSID str from [array,of,values].
For i, item in inCLSID
out_str .= ((i=2 Or i=3 Or i=4 Or i=6)?"-":"") Format("{:0" ((i=1)?8:(i<=3)?4:2) "X}",item)
return "{" out_str "}"
}
}
Error Message:
Code: Select all
---------------------------
__test_v2.ahk
---------------------------
Critical Error: Invalid memory read/write.
Line#
017: test := IWICImagingFactory.New()
018: msgbox("Works, but ends with error on [ test.obj := '' ] ")
019: ObjRelease(test.obj.ptr)
020: msgbox("this causes an error")
---> 021: test.obj := ""
025: {
000: }
026: {
000: Super.__Init()
026: this.ptr := 0
027: this.obj := 0
028: this.CLSID := [0xcacaf262, 0x9370, 0x4615, 0xa1, 0x3b, 0x9f, 0x55, 0x39, 0xda, 0x4c, 0xa]
The program is now unstable and will exit.
---------------------------
OK
---------------------------
Here's a slightly different approach with a slightly different result in the error (though the same error message):
Code: Select all
test := IWICImagingFactory.New()
msgbox "Works, but ends with error on [ test.obj := '' ] "
ObjRelease(test.obj.ptr)
; msgbox "this causes an error"
; test.obj := ""
; Msgbox "this doesn't cause an error"
class IWICImagingFactory {
ptr := 0
obj := 0
CLSID := [0xcacaf262, 0x9370, 0x4615, 0xa1, 0x3b, 0x9f, 0x55, 0x39, 0xda, 0x4c, 0xa]
IID := "{ec5ec8a9-c395-4314-9c77-54d7a935ff70}"
__New(inPtr:=0) {
this.obj := ComObjCreate(this.CLSID_str(this.CLSID), this.IID)
}
__Delete() {
}
CLSID_str(inCLSID, out_str:="") { ; create CLSID str from [array,of,values].
For i, item in inCLSID
out_str .= ((i=2 Or i=3 Or i=4 Or i=6)?"-":"") Format("{:0" ((i=1)?8:(i<=3)?4:2) "X}",item)
return "{" out_str "}"
}
}
If you comment out the msgbox then no error is thrown.
=================================================================================
Is this considered normal in general? Very occasionally I can run this code with one of the first 2 msgbox's and it will complete without error. But it seems a few sequential runs ensures errors eventually.
There seems to be a period of time I can wait to then run this code without error (with msgbox's), but again, after a few runs it will start to error again.