Page 1 of 1

Global List - Invalid Memory Access

Posted: Fri Apr 15, 2011 9:40 am
by akee
Hi! I received this error while creating my library. Traced it to the AddElement() function.

PB Version 4.51
TB Version 1.4.7

From TB documentation.
You can use arrays, linked lists, global/shared/protected variables, structures, interfaces, etc., and every function or feature PureBasic provides, as long as you use them inside your Procedure's and ProcedureDLL's. But you can, of course, make enumerations and interface, structure, global and procedure declarations outside. Any other code outside procedures will be ignored, except for DataSection's and the Data's, IncludeBinary's and labels inside them. IncludeFile is also allowable outside the procedure, of course, because the compiler processes it before creating the 'PureBasic.asm' file.
TestTailbite.pb

Code: Select all

Structure XYZ
  X.l
  Y.l
  Z.l
EndStructure

Global NewList tbl.XYZ()    ; declared here creates an error. Invalid memory access.

ProcedureDLL TestTailbite_Init()
; Some examples use this method.
;  Global NewList tbl.XYZ()    ; declared here no errors but returns 0.
EndProcedure

ProcedureDLL TestTailbite_End()

EndProcedure


Procedure testlink()
  AddElement(tbl())     ;  <----- ERROR HERE!
  tbl()\X = Random(100)
  tbl()\Y = Random(100)
  tbl()\Z = tbl()\X + tbl()\Y
  ProcedureReturn tbl()\Z
EndProcedure

ProcedureDLL hitlink()
  ProcedureReturn testlink()
EndProcedure 


Procedure showlink()
  Protected value
  ResetList(tbl())
  ForEach tbl()
    value + 1
    MessageRequester(Str(value), Str(tbl()\Z))
  Next
  ProcedureReturn value
EndProcedure

ProcedureDLL hotlink()
  ProcedureReturn showlink()
EndProcedure


; Local Test passed.
;Debug hitlink()
;Debug hotlink()
External Test...
Example1.pb

Code: Select all

a = hitlink()
Debug a

Re: Global List - Invalid Memory Access

Posted: Fri Apr 15, 2011 11:14 am
by gnozal
Hi akee,

'Global NewList tbl.XYZ()' should be in TestTailbite_Init().

So your example works, at least here ; what do you mean with 'declared here no errors but returns 0' ?

Re: Global List - Invalid Memory Access

Posted: Fri Apr 15, 2011 1:22 pm
by akee
Hmm... compiling it again... now it works... Thanks for testing gnozal. :)