Global List - Invalid Memory Access

TailBite specific forum

Moderators: gnozal, ABBKlaus, lexvictory

akee
Enthusiast
Enthusiast
Posts: 475
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Global List - Invalid Memory Access

Post 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
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: Global List - Invalid Memory Access

Post 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' ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
akee
Enthusiast
Enthusiast
Posts: 475
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Global List - Invalid Memory Access

Post by akee »

Hmm... compiling it again... now it works... Thanks for testing gnozal. :)
Post Reply