Page 1 of 1

about ConnectionID() function bug

Posted: Fri Aug 12, 2011 6:01 am
by shu7734
InitNetwork()
Connection1=0
Debug ConnectionID(Connection1)

F5 run the code

[ERROR] Invalid memory access. (Read error at address 0)

Re: about ConnectionID() function bug

Posted: Fri Aug 12, 2011 6:05 am
by netmaestro
It should give the compiler error "The specified connection is not initialized" to be consistent with other PB objects. The IMA is a bug.

Re: about ConnectionID() function bug

Posted: Fri Aug 12, 2011 6:16 am
by shu7734
My Environment

PureBasic 4.51 (Windows - x86)
Windows Server 2003 R2 MSDN Sp2

Re: about ConnectionID() function bug

Posted: Fri Aug 12, 2011 6:25 am
by shu7734
the Connection1 is a object?

is not a long value?

Re: about ConnectionID() function bug

Posted: Fri Aug 12, 2011 6:27 am
by netmaestro
The ConnectionID command expects a pointer to a valid connection object. Something other than that is received. A descriptive compiler error message is the correct response, an IMA is not. Fred or Freak will fix it.

Re: about ConnectionID() function bug

Posted: Fri Aug 12, 2011 4:38 pm
by freak
The debugger cannot validate if a given value is a valid connection. It doesn't have that information. It could only catch the 0 value but thats not that helpful imho.

Anyway, the memory access error clearly tells you that something is wrong, so the debugger did at least part of its job :D

Re: about ConnectionID() function bug

Posted: Sat Aug 13, 2011 11:31 am
by shu7734
because i used the funtion on DLL
compiler cann't find the error

Procedure Thread(*Parameters.l)
Sleep_(120000)
Connection=0
SendFileMode=*Parameters
If SendFileMode=0
While Connection=0
Sleep_(30000)
Connection=OpenNetworkConnection("127.0.0.1",80,#PB_Network_TCP)
i=i+1
If i>10
SendFileMode=1
Break
EndIf
Wend
EndIf

If SendFileMode=1
If ConnectionID(Connection)
CloseNetworkConnection(Connection)
EndIf
EndIf

EndProcedure

ProcedureDLL DllMain()
InitNetwork()
CreateThread(@Thread(),1)
Sleep_(1000000)
EndProcedure

Re: about ConnectionID() function bug

Posted: Sat Aug 13, 2011 11:35 am
by freak
The ConnectionID() command only works on a valid connection. You cannot use it like this.