[Solved]Subexpression for 'Ptr' must be a variable

BlitzMax Forums/Brucey's Modules/[Solved]Subexpression for 'Ptr' must be a variable

RustyKristi(Posted 2016) [#1]
Getting a similar error like on this thread: http://www.blitzmax.com/Community/posts.php?topic=105796


compress(cmp, cmpLen, Varptr _bank.buf()[1], _bank.Size() - 1)

This statement works with Vanilla BMX.


Derron(Posted 2016) [#2]
So the bug seeks to be in
Varptr methodcall()

Bye
Ron


Brucey(Posted 2016) [#3]
so what is "Varptr _bank.buf()[1]" trying to do exactly?


Derron(Posted 2016) [#4]
Seems the code is available there ("TNetPacket.bmx"):
http://www.blitzforum.de/forum/viewtopic.php?p=396979

If compressed Then
			'Compression
			Local cmp:Byte Ptr = MemAlloc(_bank.Size() - 1)
			Local cmpLen:Int = 0
			compress(cmp, cmpLen, Varptr _bank.buf()[1], _bank.Size() - 1)
			
			Local buf:Byte Ptr = MemAlloc(cmpLen + 1)
			MemCopy(Varptr buf[1], cmp, cmpLen)
			buf[0] = 1

			Local p:Byte Ptr = enet_packet_create(buf, cmpLen + 1, enet_flags)
			
			MemFree(cmp)
			MemFree(buf)
			
			Return p
		Else
			'No compression
			Return enet_packet_create(_bank.buf(), _bank.Size(), enet_flags)
		End If



bye
Ron


LT(Posted 2016) [#5]
Didn't think you're supposed to use Varptr on a return value. Seems strange that would work in vanilla...


Brucey(Posted 2016) [#6]
Oh, I see... so you mean this?
compress(cmp, cmpLen, _bank.buf() + 1, _bank.Size() - 1)

and this...
MemCopy(buf + 1, cmp, cmpLen)


I'd say that the author of that code doesn't really understand pointers... or just likes to jump through lots of hoops.


Brucey(Posted 2016) [#7]
Didn't think you're supposed to use Varptr on a return value

It's not...

more like :
get bank byte pointer
    _bank.buf()

get second byte
  [1]

get location of second byte
  VarPtr

in essence :
 VarPtr ( _bank.buf()[1] )

or...

 _bank.buf() + 1



RustyKristi(Posted 2016) [#8]
Thanks guys. Yes, that is a networking library that uses Pub.Enet. I could not find any enet examples so I just found that by searching and it works ok in Vanilla.

So what do I use in replacement for that line? I know there's two instances on that file.


Derron(Posted 2016) [#9]
Brucey already told you this:
VarPtr ( _bank.buf()[1] )
is the same as
_bank.buf() + 1

@ Enet examples
There is one in the "samples" directory of vanilla BlitzMax.

Not a solo-runnable-example but this is how I use enet (and bnetex for broadcasting on LAN):
basefunctions_network.bmx
gamefunctions_network.bmx


bye
Ron


Brucey(Posted 2016) [#10]
Also note that bnetex (at least the version I found on github) is LGPL.


RustyKristi(Posted 2016) [#11]
Thanks guys. That solved the problem! :)

@Brucey, got it thanks for the heads up. I'm having problems working with Bnetex anyway but might check it out some other time.

Derron, are you using NG with Bnetex for your game?