Hello,
The following lines is returning a *Buffer while it should return 0 (the URL exists but the map BUTTONS does not)
The buffer in memory contains
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
first : You see that there is no file with that name on this url. so it cannot be downloaded.
second: why you are using EncodeImage ? (if the download was correct) You have a png file, so CatchImage() to get the image and SaveImage() to save it...
so UsePNGImageEncoder and Decoder is needed...
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom
English is not my native language... (I often use DeepL.)
If the image is found then a it is in memory
If not found on the server the image is loaded locally from disk and the put in memory.
in both cases I return a pointer to the catchimage routine.
But that is not the problem, the If *Buffer always fires even if the file is not found.... normally the ]Buffer should be 0
williamvanhoecke wrote: Tue Mar 04, 2025 11:29 pmIf *Buffer always fires even if the file is not found.... normally the ]Buffer should be 0
It is "guilty" because there is something in this *Buffer... Image or not. Now it is on the developer to do something with it.
Thats why I try to use "Catchimage". This is the test, if it is a 404 HTTP Error (or something else) or an Image.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom
English is not my native language... (I often use DeepL.)
williamvanhoecke wrote: Tue Mar 04, 2025 11:29 pm
But that is not the problem, the If *Buffer always fires even if the file is not found.... normally the ]Buffer should be 0
It is correct that it is not 0. The server is sending back a HTML file to display the error message on a browser. That is typical behavior of web servers as they expect a browser to fetch the file and need a way to show the user what wend wrong.
You need to parse the HTML to determine if the file exists.
First check the size of the returned buffer. Then you can check the title tag. If the first characters are "<title>" you can assume it's not a png file but a html response from the server.
williamvanhoecke wrote: Tue Mar 04, 2025 11:29 pmIf *Buffer always fires even if the file is not found.... normally the ]Buffer should be 0
It is "guilty" because there is something in this *Buffer... Image or not. Now it is on the developer to do something with it.
Thats why I try to use "Catchimage". This is the test, if it is a 404 HTTP Error (or something else) or an Image.
Yes, I know now, I found out by testing and checking, but documentation says otherwise, is says to check if the returned memorypointer = 0 or not -> "Returns the new memory buffer address if the download was successful, zero otherwise."
Are you aware that this is a memory leak?
`CatchImage(#PB_Any, ...)` returns a freshly created object that is never stored in a variable. So you will never be able to use `FreeImage()` with it. So if that line is executed more than once your memory consumption will increase which each iteration.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
Are you aware that this is a memory leak?
`CatchImage(#PB_Any, ...)` returns a freshly created object that is never stored in a variable. So you will never be able to use `FreeImage()` with it. So if that line is executed more than once your memory consumption will increase which each iteration.
Thanks for your concern, and yes I am aware of the memory consumption, but it is about images that are there as long as the program lives.
Ok... nice code
I would expect to do al this checking stuff with HTTPRequestMemory()
The ReceiveHTTPMemory() however is explicitly to receive a pointer to a file, not some other stuff the server decides to send, so i would expect the function itself to do the checking and return an valid pointer or 0.
I was just mislead by the documentation: Returns nonzero if the download was successful, zero otherwise