Pointers

BlitzMax Forums/BlitzMax Beginners Area/Pointers

Rambo_Bill(Posted 2005) [#1]
How do I convert a pointer back?
I have:
DrawImage(ImagePTR,X,Y,FrameNum)

Where ImagePTR is a pointer to a tImage type, but I get an error that it can't convert to tImage.

I've Tried:
DrawImage(ImagePTR[0],X,Y,FrameNum)
and I didn't get an error but my computer locked.

I figured it out, I had loaded the image into a local Object which must have been automatically destroyed, so when I referenced it via a pointer the program crashed.


skidracer(Posted 2005) [#2]
Image.TImage is not a pointer in the BlitzMax sense, a pointer would be defined as

local myimageptr:TImage ptr

and to pass the actual object reference to DrawImage would require

DrawImage myimageptr[0],x,y


Rambo_Bill(Posted 2005) [#3]
DrawImage myimageptr[0],x,y locks my pc, must be something wrong with above code.


Rambo_Bill(Posted 2005) [#4]
I figured it out, I had loaded the image into a local Object which must have been automatically destroyed, so when I referenced it via a pointer the program crashed.


skidracer(Posted 2005) [#5]
hmmm, For iFrame=0 To FramesTotal should be FramesTotal-1, but my guess is FramesTotal=0

also, in BlitzMax all object references are pointers so there is no point in your use of pointers, from what I can see they are only going to introduce severe reference counting problems without introducing any benefits


Rambo_Bill(Posted 2005) [#6]
I wanted to be sure by keeping a reference to a TImage type in my type that I wasn't holding an extra memory since that same TImage type may be used in multiple copies of my type.. If that makes any sense to ya. But if its just storing a pointer and not like copying the objects contents into my type, then I guess there is no reason for it. Keeping it a non-pointer would probably help with the garbage collection as well.. Seems like the Garbage Collection doesn't take into account pointers and can delete stuff on ya.