[Done] IMA error on redim array

Post bugreports for the Windows version here
Allen
User
User
Posts: 92
Joined: Wed Nov 10, 2021 2:05 am

[Done] IMA error on redim array

Post by Allen »

Hi,

I got an IMA error at the last line. Any suggestion? (6.01 x64 CBE and ASM BE in win 10.)

Code: Select all

Structure Test
  Length.i
  Array Qty.i(1)
EndStructure
Dim A.Test(2,1)

A(2,1)\Qty(1)=3
ReDim A(2,2)
A(2,2)\Qty(1)=3
Thanks

Allen


// Moved from "Coding Questions" to "Bugs - Windows" (Kiffi)
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: IMA error on redim array

Post by StarBootics »

Fred should have a look at this code because it appear to be a bug, the ReDim should initialize the Qty array inside the test structure but it's not the case.

Code: Select all

Structure Test
  Length.i
  Array Qty.i(1)
EndStructure
Dim A.Test(2,1)

A(2,1)\Qty(1)=3
ReDim A(2,2)

For ID0 = 0 To 2
  For ID1 = 0 To 2
    Debug A(ID0, ID1)
  Next
Next

Debug A(2,2)\Length

A(2,2)\Qty(1)
Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: IMA error on redim array

Post by STARGÅTE »

Hm, seems like a bug in ReDim for multidimensional arrays in combination with a complex structure.
The issue is: Array Qty() is not initialized for the additional fields created by ReDim.

Code: Select all

Structure Test
  Length.i
  Array Qty.i(1)
EndStructure
Dim A.Test(2,1)

A(2,1)\Qty(1)=3
Debug ArraySize(A(2,1)\Qty())
ReDim A(2,2)
Debug ArraySize(A(2,2)\Qty())
A(2,2)\Qty(1)=3
Similar problem with lists or maps:

Code: Select all

Structure Test
  Length.i
  List Qty.i()
EndStructure
Dim A.Test(2,1)

Debug ListSize(A(2,1)\Qty())
ReDim A(2,2)
Debug ListSize(A(2,2)\Qty())
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Allen
User
User
Posts: 92
Joined: Wed Nov 10, 2021 2:05 am

Re: IMA error on redim array

Post by Allen »

Hi,

It works for single dimenion array.

Code: Select all

Structure Test
  Length.i
  Array Qty.i(1)
EndStructure
Dim A.Test(2)

A(2)\Qty(1)=3
ReDim A(3)
A(3)\Qty(1)=3
Above code is OK.

Allen
juergenkulow
Enthusiast
Enthusiast
Posts: 544
Joined: Wed Sep 25, 2019 10:18 am

Re: IMA error on redim array

Post by juergenkulow »

Code: Select all

; Redim, SYS_ReAllocateMultiArray does not create arrays, lists, maps in Structure. Also Linux 
Structure Test
  Array Qty.i(1)
  List  L.i()
  Map   M.i()
EndStructure
Dim A.Test(2,1)

A(2,1)\Qty(1)=3
ReDim A(2,2)
Dim A(2,2)\Qty(1)
A(2,2)\Qty(1)=3
NewList A(2,2)\L()
AddElement(A(2,2)\L())
A(2,2)\L()=4711
NewMap A(2,2)\M()
A(2,2)\M("TEST")=4711
Debug A(2,2)\Qty(1)
Debug A(2,2)\L()
Debug A(2,2)\M("TEST")
; 3
; 4711
; 4711
juergenkulow
Enthusiast
Enthusiast
Posts: 544
Joined: Wed Sep 25, 2019 10:18 am

Re: IMA error on redim array

Post by juergenkulow »

Code: Select all

Structure Test
  Length.i
  Array Qty.i(1)
EndStructure
Dim A.Test(2,1)
! p_p=(((s_test*)a_a.a)[2LL*a_a.b[0]+1LL].f_qty.a);
Debug Hex(*p)
A(2,1)\Qty(1)=3

ReDim A(2,2)
! p_p=(((s_test*)a_a.a)[2LL*a_a.b[0]+2LL].f_qty.a);
Debug Hex(*p)
A(2,2)\Qty(1)=3 ;((integer*)((s_test*)a_a.a)[2LL*a_a.b[0]+2LL].f_qty.a)[(integer)1LL]=3;

CompilerIf #PB_Compiler_Backend<>#PB_Backend_C
  CompilerError "Please use C Backend for this Test."
CompilerEndIf 
; 21343D8
; 0
; [10:26:21] Executable type: Linux - x64  (64bit, Unicode)
; [10:26:21] Executable started.
; [10:26:21] [ERROR] ReDim2.pb (Line: 13)
; [10:26:21] [ERROR] Invalid memory access.
; [10:26:42] The Program was killed.
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Done] IMA error on redim array

Post by Fred »

Fixed.
Post Reply