Page 1 of 2
Using #PB_any give compiler error
Posted: Mon Apr 16, 2018 7:42 pm
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.
Re: Using #PB_any give compiler error
Posted: Mon Apr 16, 2018 7:44 pm
by Fred
I don't think there is a bug here, could you post a small snippet showing the bug ?
Re: Using #PB_any give compiler error
Posted: Mon Apr 16, 2018 9:24 pm
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]
Re: Using #PB_any give compiler error
Posted: Mon Apr 16, 2018 10:16 pm
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
Re: Using #PB_any give compiler error
Posted: Tue Apr 17, 2018 12:35 am
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.
Re: Using #PB_any give compiler error
Posted: Tue Apr 17, 2018 12:48 am
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.
Re: Using #PB_any give compiler error
Posted: Tue Apr 17, 2018 1:00 am
by TI-994A
Re: Using #PB_any give compiler error
Posted: Tue Apr 17, 2018 1:32 am
by Demivec
@TI-994A: Please excuse my sloppiness, you're absolutely correct. Darn these eyes of mine.

Re: Using #PB_any give compiler error
Posted: Tue Apr 17, 2018 1:42 am
by TI-994A
Demivec wrote:Darn these eyes of mine.

...of ours!
EDIT: Now, it lives on only in yours.

Re: Using #PB_any give compiler error
Posted: Tue Apr 17, 2018 12:23 pm
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.
Re: Using #PB_any give compiler error
Posted: Tue Apr 17, 2018 12:50 pm
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.
Re: Using #PB_any give compiler error
Posted: Tue Apr 17, 2018 10:11 pm
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.
Re: Using #PB_any give compiler error
Posted: Wed Apr 18, 2018 11:02 am
by TI-994A
bfernhout wrote:...i think needed to start writing error free code...
You'd be the first!
Moreover, programming might lose its magic if there were no errors to hunt down and debug.
That's half the fun.
Re: Using #PB_any give compiler error
Posted: Sat Apr 21, 2018 3:28 pm
by bfernhout
I think you are right.

Re: Using #PB_any give compiler error
Posted: Sun Jun 03, 2018 9:14 am
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