Using #PB_any give compiler error

Advanced game related topics
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Using #PB_any give compiler error

Post by bfernhout »

I had this problem a couple of times. I load a image and then i grab a array image from that image but the compiler stops,and asking me if this is what i want. To have a high number for that image.

E.g
  • Global Dim JewColors(6)

    Global Jewels = LoadImage(#PB_Any,"graphics\Jewels.bmp")

    For x = 0 To 6
    Jewcolors(x) =CreateImage(#PB_Any,32,32)
    GrabImage(JewColors(x),Jewels,(x*32)+1,y,(x*32)+32,y+31)
    Next


In this example code grabed from source. #PB_any give in the first line a number of 28732912 This is higher then the 100000 is given by the compiler. But the compiler is not complaining about it. Then in the for next loop. The first Array element Jewcolors(0) got a number 28706608. Still no warning from the compiler. Then the next line GrabImage is comming and the compiler start Asking if this is the right number cause its higher then 100 000 and halted the compiling. In the documentation state that i can use the #PB_Any. And when i check the variables all of them are higher then the limit of 100000. There is absolute no problem, only when using a Array this problem is occuring.
Is there a work around for or is this solved in the next release.
From my first self made computer till now I stil like computers.
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Using #PB_any give compiler error

Post by Fred »

I don't think there is a bug here, could you post a small snippet showing the bug ?
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: Using #PB_any give compiler error

Post by bfernhout »

Thats the problem the code is the snipe

Code: Select all

Global Dim JewColors(6)

;The #PB_Any give out the number 28732912 
Global Jewels = LoadImage(#PB_Any,"graphics\Jewels.bmp")

For x = 0 To 6
;The #PB_Any give out the number 28706608 For element 0 Element 1 is not comming up the debugger stop the program
Jewcolors(x) =CreateImage(#PB_Any,32,32)
;The message under the IDE window says error number to high over 100000
GrabImage(JewColors(x),Jewels,(x*32)+1,y,(x*32)+32,y+31)
Next
The following image showed what kind of error i got. It made no sence to me.
[img]http://bartfernhout.magix.net/public/images/PBError.jpg
[/img]
From my first self made computer till now I stil like computers.
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Using #PB_any give compiler error

Post by Fred »

You don't use GrabImage correctly. See the doc:

Code: Select all

A number to identify the new image. #PB_Any can be specified to auto-generate this number.

Note: The number of an existing image created using #PB_Any can not be used as the target image. Instead, the existing image must be freed and a new number generated by passing #PB_Any here. 
http://www.purebasic.com/documentation/ ... image.html
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Using #PB_any give compiler error

Post by TI-994A »

bfernhout wrote:In the documentation state that i can use the #PB_Any...
The PureBasic Manual wrote:GrabImage()

Parameters
#Image2: A number to identify the new image. #PB_Any can be specified to auto-generate this number.
Note: The number of an existing image created using #PB_Any cannot be used as the target image...
The GrabImage() function will create the new image automatically:

Code: Select all

Global Dim JewColors(6)

Global Jewels = LoadImage(#PB_Any,"graphics\Jewels.bmp")

For x = 0 To 6
  ;Jewcolors(x) = CreateImage(#PB_Any,32,32)  ;not required
  Jewcolors(x) = GrabImage(Jewels, #PB_Any ,(x*32)+1,y,(x*32)+32,y+31)
Next
Edit: Error in code.
Last edited by TI-994A on Tue Apr 17, 2018 12:37 pm, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Demivec
Addict
Addict
Posts: 4085
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Using #PB_any give compiler error

Post by Demivec »

TI-994A wrote:
bfernhout wrote:In the documentation state that i can use the #PB_Any...
The PureBasic Manual wrote:GrabImage()

Parameters
#Image2: A number to identify the new image. #PB_Any can be specified to auto-generate this number.
Note: The number of an existing image created using #PB_Any cannot be used as the target image...
The GrabImage() function will create the new image automatically:

Code: Select all

Global Dim JewColors(6)

Global Jewels = LoadImage(#PB_Any,"graphics\Jewels.bmp")

For x = 0 To 6
  ;Jewcolors(x) = CreateImage(#PB_Any,32,32)  ;not required
  Jewcolors(x) = GrabImage(Jewels, #PB_Any ,(x*32)+1,y,(x*32)+32,y+31)
Next
Nice, simple and to the point. :)


If the images that are created using #PB_Any need to be updated by replacing them with a newly created image, it is good to remember that the previous images need to be freed with FreeImage().


@Edit: Removed a bad and incorrect code sample. Thanks TI-994A.
Last edited by Demivec on Tue Apr 17, 2018 4:26 pm, edited 2 times in total.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Using #PB_any give compiler error

Post by TI-994A »

:wink:
Last edited by TI-994A on Tue Apr 17, 2018 1:45 am, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Demivec
Addict
Addict
Posts: 4085
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Using #PB_any give compiler error

Post by Demivec »

@TI-994A: Please excuse my sloppiness, you're absolutely correct. Darn these eyes of mine. :wink:
Last edited by Demivec on Tue Apr 17, 2018 2:06 am, edited 1 time in total.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Using #PB_any give compiler error

Post by TI-994A »

Demivec wrote:Darn these eyes of mine. :wink:
...of ours!

EDIT: Now, it lives on only in yours. :lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: Using #PB_any give compiler error

Post by bfernhout »

All thanks for the intell. The helpfile is here a bit in the dark. So i did it trough the helpfile making this. i already changed it.

Code: Select all

Global Dim JewColors(6)

Global Jewels = LoadImage(#PB_Any,"graphics\Jewels.bmp")

For x = 0 To 6
  ;Jewcolors(x) = CreateImage(#PB_Any,32,32)  ;not required
  Jewcolors(x) = GrabImage(JewColors(x), #PB_Any ,(x*32)+1,y,(x*32)+32,y+31)
Next
The other problem is myself. I am used to work with Blitz3D and there is the declaration of the image a must. As soon as you free up the image Blitz3D lose its pointer to the memory location where the image is stored. Blitz3D need a live action memory allocation. Therefore the pointing to a image is 2 sided. Firts the Variable who got the image assigned to it. Get the pointer to the memory where the real pointer of the image is. And that part is changing every time.
This was also one of the reasons why a game made in Blitz3D, who is running longer than say one hour. Jammed the computer by never freeed up any Image heap space. The cleaning is only done when te game is terminated.

The basic of cleaning up the images that is not needed is just a good thing. And a good practice to do.

You know the way the help file discribe this is a bit puzzeling:

Code: Select all

Result = GrabImage(#Image1, #Image2, x, y, Width, Height)
A beter way to discribe it is:

Code: Select all

NewImage = GrabImage(#ImageSource,#PB_Any,x,y,Width,Height)

;Or if user make the number by himself
;Where noted the #NewImage is assign by user as assigned ImageNumber
Result = GrabImage(#ImageSource,#NewImage,x,y,Width,Height)
Then it make a lot more sence.

Thanks a lot guys.
From my first self made computer till now I stil like computers.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Using #PB_any give compiler error

Post by TI-994A »

@bfernhout: There was an error in my earlier post.

The GrabImage() function should read as follows:

Code: Select all

Jewcolors(x) = GrabImage(Jewels,#PB_Any,(x*32)+1,y,(x*32)+32,y+31)
With the variable Jewels holding the source image.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: Using #PB_any give compiler error

Post by bfernhout »

Thanks very much.

I do understand it now. I have to learn a lot before i could understand PB a little. The same time i think needed to start writing error free code. (Witch is never. Even if i think its ok. Always some thing is popping up. And I was always the one who make the thinking error. Or just forgot something to put in.

Stil its a good piece of program to work in. And a lot of things working perfect. The only drawback is the IDE. You can do al lot in it but smal things are left out.

E.g.
When i am busy in a project i only see the procdures in the file i am busy in, and not all the procedures in the project.
Stil i like the PB. Its much better the Blitz3D and DarkBasic Pro. (Who are both died)

Thanks for all the help.
From my first self made computer till now I stil like computers.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Using #PB_any give compiler error

Post by TI-994A »

bfernhout wrote:...i think needed to start writing error free code...
You'd be the first! :lol:

Moreover, programming might lose its magic if there were no errors to hunt down and debug. That's half the fun.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: Using #PB_any give compiler error

Post by bfernhout »

I think you are right. :lol:
From my first self made computer till now I stil like computers.
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Using #PB_any give compiler error

Post by Michael Vogel »

Just had a look into the help files (in german language), the text for the return value of CreateImage seems to be wrong, as it says "#PB_Any [...] wird die generierte Nummer zurückgegeben." where "Nummer" is identified as the image number.

Anyhow it would be fine to have access to the created image via it's number to be able to use all image functions easily.

Code: Select all

procedure ImageProcessing(image)
	protected temp	

	temp=CreateImage(#PB_Any,2000,2000) 	allocates memory

	process image using a temporary image...

	FreeImage("temp")					how to free the memory again?
endprocedure
Post Reply