Image number limitation?

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

Image number limitation?

Post by Lebostein »

It seems the number of images is limited, regardless of the memory used

With this code, I get 9994 images before CreateImage() returns ZERO:

Code: Select all

For i = 1 To 14000
  Debug Str(i) + " : " + Str(CreateImage(#PB_Any, 32, 32, 24))
Next i
...
9993 : 10233664
9994 : 10233704
9995 : 0
9996 : 0
...

But if I change the size of the images, I get the same maximum number:

Code: Select all

For i = 1 To 14000
  Debug Str(i) + " : " + Str(CreateImage(#PB_Any, 96, 96, 24))
Next i
...
9993 : 10233664
9994 : 10233704
9995 : 0
9996 : 0
...

And if I create a huge image before, I get one picture less:

Code: Select all

Debug CreateImage(1, 16000, 16000, 24)
For i = 1 To 14000
  Debug Str(i) + " : " + Str(CreateImage(#PB_Any, 96, 96, 24))
Next i
117768924
...
9992 : 10233624
9993 : 10233664
9994 : 0
9995 : 0
...

Why the number of images seems limited? Or is this a problem of the Virtual machine I use (Win XP in Virtualbox on GNOME)?
It does not seem to be a memory problem, because the number of created images is the same with different image sizes.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Image number limitation?

Post by IdeasVacuum »

I tried your code Lebostein - got exactly the same results (PB5.44LTS x86). If you free the image immediately after creation, the image ID is not incremented, so it does look as though the 9994 limit is imposed. Not sure what is "magic" about 9994 though :D

Code: Select all

For i = 1 To 14000
       iImg.i = CreateImage(#PB_Any, 32, 32, 24)
                  Debug Str(i) + ": " + Str(iImg)
                  ;FreeImage(iImg)
Next i
It's not a #PB_Any limitation:

Code: Select all

For i = 1 To 14000
       iImg.i = CreateImage(i, 32, 32, 24)
                  Debug Str(i) + ": " + Str(iImg)
                  ;FreeImage(iImg)
Next i
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Image number limitation?

Post by Keya »

my guess is hard-coded limit of 10000 give or take one, especially as when you simply run the program "! int 3" (nothing else) so a blank program it has 5 existing GDI handles in use. Windows doesn't apply that limitation though (https://msdn.microsoft.com/en-us/librar ... 85%29.aspx) = should be able to get minimum 16k on Windows 2000 and up to 64k on newer, so maybe its a limitation that brings it inline with an OSX or Linux GDI limitation or something, but again im only guessing
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Image number limitation?

Post by Lunasole »

Yes, it looks like be related with GDI: by adding OpenWindow() I've got images stop creating at number 9983, and with two windows opened - 9978, and what can point to GDI here -- PB incorrectly draws opened windows after that.
It's some PB bug as for me, rather than planned limitation.

Code: Select all

EnableExplicit

OpenWindow(0, 50, 50, 300, 700, "")
;OpenWindow(1, 50, 50, 300, 700, "") ; comment/uncomment this to get different number

Define i
For i = 1 To 14000
	;If i > 8000 ; comment/uncomment this to see opened windows glitches
	;	SetWindowTitle(0, "all is fine still")
	;	Break
	;EndIf
	If CreateImage(#PB_Any, 2, 2, 24) = 0 
		SetWindowTitle(0, Str(i))
		Break
	EndIf
Next i

Repeat
	
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
acreis
Enthusiast
Enthusiast
Posts: 204
Joined: Fri Jun 01, 2012 12:20 am

Re: Image number limitation?

Post by acreis »

This question arrises from time to time.

Please search the forum for the answer.

Anyway, what program needs show 10000 images?

What user can see 10000 images at one time?

I said show an see10000 images.

If you need store 10000 images then there are others ways to do it.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Image number limitation?

Post by Lunasole »

[...]

Well after some search I found this link Fred has posted previously: https://support.microsoft.com/en-us/kb/327699

So, that 10k handles limit is not related to PB, it is "fool-proof" feature provided by XP and it can be increased by changing registry settings.
Just for interest changed it to 65536 and rebooted PC, after that 30910 images were created successfully ^^
Last edited by Lunasole on Thu Jan 05, 2017 11:15 pm, edited 2 times in total.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Image number limitation?

Post by Keya »

so we were all testing on XP? :)
here's the only other threads i could find about it
http://www.forums.purebasic.com/english ... 13&t=56982
http://forum.purebasic.com/english/view ... 13&t=22838
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Image number limitation?

Post by Lunasole »

Keya wrote:so we were all testing on XP? :)
No :) That limit is actual for Win7 too, probably for 8 also.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Image number limitation?

Post by Keya »

ah! yes my Win7 also has HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\GDIProcessHandleQuota = 10000
The MSDN page about GDI limitations mentions this registry key but makes no mention of the default value of 10000
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

Re: Image number limitation?

Post by Lebostein »

acreis wrote: Anyway, what program needs show 10000 images?
What user can see 10000 images at one time?
That is NOT the question! And why you think I need the images to display these at one time?!?
Sometimes it is useful to prepare thumbnails or icons for ListIconGadgets or something....

Thanks at all others for useful hints!!!

@Fred: Please add this hint to the manual! Image creation is limited by memory AND handle maximum (Windows only). On Mac OS there is no handle limit.
Post Reply