Page 1 of 1

Image number limitation?

Posted: Thu Jan 05, 2017 2:50 pm
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.

Re: Image number limitation?

Posted: Thu Jan 05, 2017 3:46 pm
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

Re: Image number limitation?

Posted: Thu Jan 05, 2017 4:30 pm
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

Re: Image number limitation?

Posted: Thu Jan 05, 2017 8:40 pm
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

Re: Image number limitation?

Posted: Thu Jan 05, 2017 10:03 pm
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.

Re: Image number limitation?

Posted: Thu Jan 05, 2017 10:35 pm
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 ^^

Re: Image number limitation?

Posted: Thu Jan 05, 2017 11:13 pm
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

Re: Image number limitation?

Posted: Thu Jan 05, 2017 11:17 pm
by Lunasole
Keya wrote:so we were all testing on XP? :)
No :) That limit is actual for Win7 too, probably for 8 also.

Re: Image number limitation?

Posted: Thu Jan 05, 2017 11:39 pm
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

Re: Image number limitation?

Posted: Fri Jan 06, 2017 12:50 pm
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.