[v2-beta.8] FileSelect - Critical Error: Invalid memory read/write Topic is solved

Report problems with documented functionality
Tomshi
Posts: 6
Joined: 06 Sep 2022, 20:58
Contact:

[v2-beta.8] FileSelect - Critical Error: Invalid memory read/write

Post by Tomshi » 06 Sep 2022, 21:08

Attempting to use FileSelect with various options results in an "Invalid memory read/write" error. Only the first example in the doc is currently working for example (setting option as 3 appears to be why it works..?)
Unsure if a similar error crops up with anything else, this was just the first roadblock I came across

So for example, this works (from the doc):

Code: Select all

SelectedFile := FileSelect(3, , "Open a file", "Text Documents (*.txt; *.doc)")
if SelectedFile = ""
    MsgBox "The dialog was canceled."
else
    MsgBox "The following file was selected:`n" SelectedFile
While this doesn't:

Code: Select all

SelectedFolder := FileSelect("D", , "Select a folder")
if SelectedFolder = ""
    MsgBox "The dialog was canceled."
else
    MsgBox "The following folder was selected:`n" SelectedFolder
The error in question
image.png
image.png (17.43 KiB) Viewed 1422 times

lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2-beta.8] FileSelect - Critical Error: Invalid memory read/write

Post by lexikos » 06 Sep 2022, 22:55

I'm guessing that the issue is the fourth parameter being omitted. For now you can pass "" instead.

lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2-beta.8] FileSelect - Critical Error: Invalid memory read/write

Post by lexikos » 07 Sep 2022, 03:57

This is due to a change in how optional parameters are represented internally for a selection of built-in functions. If you encounter Critical Errors with other functions when omitting a parameter, please try passing an empty string, and report the result in this topic.

Thanks for the detailed bug report.


ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Re: [v2-beta.8] FileSelect - Critical Error: Invalid memory read/write

Post by ludamo » 10 Sep 2022, 01:59

I am getting toast notifications "New notification" when ever I start or reload AHK v2-beta8 and v2-beta9 and whenever a coded TrayTip (Toast) appears. This never happened before beta8. It seems that this is happening because I have a line in my script as follows:

Code: Select all

TrayTip	; with no parameters
I think I have tracked it down to a change in script2.cpp as follows:

Code: Select all

94	if (!aTitle) aTitle = _T("");
95	if (!aText) aText = _T("");
If I add this code it seems to go away:

Code: Select all

       if (!aTitle && !aText)
           return FR_FAIL;
I guess I could also comment out TrayTip (with no parameters)
Last edited by ludamo on 10 Sep 2022, 02:05, edited 1 time in total.

ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Re: [v2-beta.8] FileSelect - Critical Error: Invalid memory read/write

Post by ludamo » 10 Sep 2022, 02:04

I just tried again with beta9 with

Code: Select all

TrayTip ""
but get the same result i.e. frequent "New notification" Toasts. Commenting out TrayTip "" fixes the issue.

lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2-beta.8] FileSelect - Critical Error: Invalid memory read/write

Post by lexikos » 10 Sep 2022, 04:29

That's due to a silly mistake (if (*aTitle && !*aText) was changed to if (aTitle && !*aText)).

Returning FR_FAIL should cause the thread to be aborted. You don't want that. If you want the function to do nothing under those conditions, you can return OK. But why would you call it if you want nothing to happen?

ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Re: [v2-beta.8] FileSelect - Critical Error: Invalid memory read/write

Post by ludamo » 11 Sep 2022, 03:48

Thanks for the feedback & correction. My C++ is very rudimentary (basically just copy what I see and put it somewhere else - trial & error). I was using TrayTip without parameters as part of my code to dismiss all sorts of notifications. I mean it is also used in the v2 help file without parameters to dismiss a TrayTip. In example #2 https://lexikos.github.io/v2/docs/commands/TrayTip.htm#ExDisplayTime

lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2-beta.8] FileSelect - Critical Error: Invalid memory read/write

Post by lexikos » 11 Sep 2022, 21:54

Aside from the bug, using TrayTip without parameters only dismisses a previous TrayTip shown by the script itself, as in the example you linked to. It sounds like you were trying to use it to dismiss other notifications, which is not what it does.

Post Reply

Return to “Bug Reports”