April 25, 2019, 04:23:23 AM

Author Topic: Problem with VarPtr not working  (Read 144 times)

Offline imaginaryhuman

  • Jr. Member
  • **
  • Posts: 7
Problem with VarPtr not working
« on: April 04, 2019, 10:51:44 PM »
I'm struggling to get 'compress' to work (from zlib).

I am doing: compress2 BankBuf(b),r,Varptr(code[0]),codeoff,9

The variables are set up right. Everything is normal except the VarPtr seems not to be working. Blitz reports that there is no overload for having a variable of the type inside the bracket of VarPtr... e.g. if I put code[0] in there, it says there's no overload with a byte in that position (its a byte array). If I put "code" ie the array itself it says there's no overload with a byte array in that position. It's almost like it isn't actually returning a byteptr at all, it's just returning the contents of the brackets.

I know the syntax is right cus I've been using this for years on the old blitzmax (pre NG). It does the same when I try with lzmacompress2 (imported)... same syntax, same parameters... the varptr isn't returning a byte pointer.

Also it seems BytePtr and IntPtr don't register as valid commands any more, are they not part of NG? Was pointer support removed entirely? I tried also a bankbuf(bank)[0] but it says you can't get an array of bankbufs, rather than using it as a byte pointer. How am I supposed to pass a pointer to the compress function if there are no pointers?

Offline TomToad

  • Sr. Member
  • ****
  • Posts: 371
Re: Problem with VarPtr not working
« Reply #1 on: April 05, 2019, 01:08:28 PM »
Arrays are already pointers.  Instead of passing VarPtr(code[0]), just pass code.
Code: BlitzMax
  1. SuperStrict
  2. Local n:UInt = 100
  3. Local r:UInt = 100
  4. Local a:Byte[n]
  5. Local s:String = ""
  6. 'fill a with numbers 1 through 9
  7. For Local i:Int = 0 Until n
  8.         a[i] = i/10
  9.         s :+ a[i] + " "
  10. Next
  11.  
  12. 'create a bank and compres the data to it
  13. Local bank:TBank = CreateBank(n)
  14. compress2(BankBuf(bank),r,a,n,9)
  15.  
  16. 'print the contents of the buffer
  17. s :+ "~n~n"
  18. For Local i:Int = 0 Until r
  19.         s :+ PeekByte(bank,i) + " "
  20. Next
  21.  
  22. 'clear the contents of the array
  23. For Local i:Int = 0 Until n
  24.         a[i] = 0
  25. Next
  26.  
  27. 'uncompress the buffer to the array
  28. uncompress(a,n,BankBuf(bank),r)
  29. s :+ "~n~n"
  30. For Local i:Int = 0 Until n
  31.         s :+ a[i] + " "
  32. Next
  33. Print s
  34.  
  35.  
------------------------------------------------
8 rabbits equals 1 rabbyte.

Online markcwm

  • Sr. Member
  • ****
  • Posts: 361
Re: Problem with VarPtr not working
« Reply #2 on: April 05, 2019, 05:20:54 PM »
BytePtr and IntPtr have always been separated by a space, Bye Ptr and Int Ptr.

I believe BRL Blitzmax code should run in 32-bit NG without modification.

Offline imaginaryhuman

  • Jr. Member
  • **
  • Posts: 7
Re: Problem with VarPtr not working
« Reply #3 on: April 05, 2019, 05:36:15 PM »
@TomToad ... but VarPtr(code[0]) has always worked in pre-NG versions. Thanks for example though.

@markcwm .... will try that, thanks.

Offline Derron

  • Hero Member
  • *****
  • Posts: 1953
Re: Problem with VarPtr not working
« Reply #4 on: April 05, 2019, 05:53:11 PM »
If nothing speaks "against" it maybe VarPtr should return the pointer itself if you pass it a pointer.


bye
Ron

Offline imaginaryhuman

  • Jr. Member
  • **
  • Posts: 7
Re: Problem with VarPtr not working
« Reply #5 on: April 05, 2019, 06:16:31 PM »
Managed to get it working with

Local r:ULong=codeoff*4
compress2 BankBuf(b),r,VarPtr(code[0]),ULong(codeoff),9

the lengths had to be ULong types, whereas in the past they used to be Int. And using Byte Ptr(code) is the only way I could work with the array. Strangely once this was changed to ULong, the VarPtr started working.

Offline imaginaryhuman

  • Jr. Member
  • **
  • Posts: 7
Re: Problem with VarPtr not working
« Reply #6 on: April 05, 2019, 06:17:00 PM »
Good to know pointers are still in (phew) .... I use them often. Thanks guys.