Jump to content
Sign in to follow this  
Flaky

$aArray[0] = _ArrayDelete($aArray, $iIndex) crashes autoit

Recommended Posts

Flaky

So I was building some functions to assemble and manipulate a queue, when I ran into this interesting bit.

#include "Array.au3"

local $aArray [10] = [9, "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9"]

$aArray[0] = _ArrayDelete($aArray, 5)

_ArrayDisplay($aArray) ;this was not in the original post

;I removed it because I did not realize that this was part of what caused the crash.

Ideally, the return from _ArrayDelete was supposed to update the 0th index of the array, which contained the number of elements in that array. But instead, I get:

!>21:55:52 AutoIT3.exe ended.rc:-1073741819

Is there any way to get this to work without using a placeholder variable? I suppose it isn't terribly important since I have determined the root of the problem and I can work around it, but I am a little OCD about how my code looks.

Edit: If anyone is curious, the behavior is due to setting a variable using the return from a function call that uses that variable as a byref parameter. I am not sure if this is intended, or not, because in many languages the RHS of the = is evaluated completely prior to setting the LHS.

Edited by Flaky

Share this post


Link to post
Share on other sites
BrewManNH

What version of AutoIt are you using, because I tested this script on 3.3.8.1 and 3.3.9.4 beta and it didn't crash the script for me. Although $aArray[0] doesn't get updated with the return value of _ArrayDelete, probably because the array is being passed as byref. Looks like you're going to have to code it differently, or recreate the function in your script and don't use the UDF version.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Flaky

I am using 3.3.8.1.

Interesting tidbit - I tested this with an _ArrayDisplay($aArray) immediately after the _ArrayDelete call. Without it, there is no crash.

Share this post


Link to post
Share on other sites
kylomas

Flaky,

Is there any way to get this to work without using a placeholder variable?

Yes, like this:

#include "Array.au3"

local $aArray [10] = [9, "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9"]

_ArrayDelete($aArray, 5)

$aArray[0] = ubound($aArray) - 1

_arraydisplay($aArray)

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
trancexx

This was internal AutoIt bug that was fixed after 3.3.8.1 was released. That means you might want to download and run beta AutoIt if you want correct execution.

Sorry for the inconvenience.

edit:

#include <Array.au3>

Local $aArray [10] = [9, "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8", "s9"]

$aArray[0] = _ArrayDelete($aArray, 5) - 1 ; you probably want to substract 1

_ArrayDisplay($aArray)
Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×