GUI displays a png but refuses to display a jpg ? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
boiler
Posts: 16771
Joined: 21 Dec 2014, 02:44

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 10:59

As mikeyww suggested before, display the value of every variable that appears in the Gui command in your MsgBox immediately preceding it. So not just ImgLoc, but also imgguiName and WantedHeight. Copy/paste them to the MsgBox to ensure there is no chance of a typo. Use an editor that will highlight all instances of highlighted text so you can see they match in both places.

Now I tried many of those kinds of things, including disabling parts of your script because it directs itself to different places based on the file extension, so that's another thing the MsgBox does is that it makes sure you know that the script is about to execute the next line.

So if you've done all that and it's still not working, then make an equivalent script of the three-line script that worked with all the same elements including the height option, GUI name, and verify that works. If it does, then add things from your main script until it doesn't work, which will then identify the problem. I know it sounds like a huge effort for that size of a script, but that's how I would go about it.

Actually, I probably would go the other way like I mentioned before, which is to take out things until it works because it resembles the three-line script. If you comment out almost everything else in your script, it should work like the three-line script. You can comment out huge chunks, and when one chunk made a difference, then put it back in and start commenting out smaller parts of that huge chunk to narrow it down.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 11:26

Thanks. I forgot to say this : if I replace the GUI commands by a simple SplashImage, %ImgLoc% , it works. Isn't that crazy ?
But I need the GUI command because I need to display some dynamic text on top of the displayed image. Hence my problem.

I've also tried a MsgBox, %ImgLoc% | %imgguiName% | %WantedHeight% right before displaying the GUI. All three variables have the right values. I don't know what more I can try.
User avatar
boiler
Posts: 16771
Joined: 21 Dec 2014, 02:44

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 11:35

What if you replace that Gui command in that exact same place in the script with hard-coded values for all of the variables? Like just type it out as it would be with no variables including the full path to the file. Does that display it?
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 11:40

Good ideas.

Could consider whether Gui, New helps in any way.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: GUI displays a png but refuses to display a jpg ?  Topic is solved

11 May 2021, 12:00

Jose Hidalgo wrote:
11 May 2021, 10:44
Are there other debugging tools that I wouldn't know about ?
yes, download the ahk source and run ur script as a test script under Visual Studio in debug mode. then step through ahk's actual source code to see what breaks ...which is what i did, only to find out Gui Add, Picture was failing on CreateFile() with:

Code: Select all

ERROR_SHARING_VIOLATION
32 (0x20)
The process cannot access the file because it is being used by another process.
so somethere in ur script ure doing something to the effect of:

Code: Select all

f := FileOpen(myJpgPath, "??")
Gui Add, Picture, , % myJpgPath
u couldnt have known since ahk doesnt report this error(and neither does v2 apparently, which is the real shame)
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 12:25

Oh wow, I guess we're all learning stuff here. Thank you so much for your help ! :bravo: :bravo: :bravo:

swagfag, thanks to you I understood what was going on :
  • Towards the end of the script ("Step 3 : display the corresponding image"), I am checking if the jpg file exists via a JpgFile := FileOpen(JpgLoc, "r") and a If IsObject(JpgFile) command.
  • Then if such file exists, I call the DynamicImage function.
  • But before calling such function, I forgot to add a simple JpgFile.Close() command. Adding it immediately solved the issue !
This was a simple bug, and I would have found it easily if AHK could have said anything about it. Had I gotten some kind of "file already opened" error, I would have quickly understood what was going on.
Maybe this could be reported and included in a future version ?

Problem solved ! I guess... :?
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 13:12

Very good find! I agree that AHK should provide some type of warning, error, or other indication of a problem, since the effect is unexpected.
Jose Hidalgo
Posts: 222
Joined: 07 Mar 2021, 07:44

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 15:49

I am happy that despite my inexperience I may have encountered a real issue that will allow, thanks to swagfag's precious help, to improve this wonderful AHK tool. :oops:
Let me know if there's a way to report it for future releases, or if you guys can take care of it directly.
Until next time !
User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: GUI displays a png but refuses to display a jpg ?

11 May 2021, 18:06

There is a documentation forum, a suggestions (wish list) forum, and one for bugs. I actually consider this issue to be a bug, though some may disagree with me.
lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: GUI displays a png but refuses to display a jpg ?

12 May 2021, 03:35

The lack of error reporting in v1 is not a bug; I have posted a more detailed reply in the bug report topic.

I am checking if the jpg file exists via a JpgFile := FileOpen(JpgLoc, "r") and a If IsObject(JpgFile) command.
To check if a file exists, use the appropriate function: FileExist.

If you must know whether you can read the file, and not just whether it exists, use FileOpen; but note that IsObject is redundant. The return value of FileOpen is either 0 or an object. If JpgFile and If IsObject(JpgFile) therefore give the same result. If you don't need to do anything else with the object, If FileOpen(JpgLoc, "r") would be sufficient. The file is closed automatically when the reference returned by FileOpen is released, immediately after it is evaluated as boolean for the If statement.

However, FileOpen throws an OSError on failure in v2.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: todd and 148 guests