Problem with redim in Autosizing

Started by Roland Stowasser, February 03, 2024, 08:50:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Roland Stowasser

Hi Charles,

unfortunately, I haven't been able to work with Oxygenbasic as intensively as I would like. But I noticed that you made some changes to "redim". This causes the programs in \Wingui\Autosizing to crash. The error message is in autosizing.inc in line 73 and line 148:

error:  Array member not found
word:  pinctl_rec.destructor
col:     16
line:    73
file:    autosizing.inc

The whole construct consists of:

sizing_data
PinCtl_Rec
MaxPinnedCtls
MaxPinned

at the moment I don't know where I have to apply the constructor / destructor?

Zlatko Vid

Autosizing Folder contain few demos and SmallApp
and all programs work ...so how you get that error is mistery ?

Roland Stowasser

I use Version:

0.7.0 2024-01-01T14:45:45 32bit
 
and I think this is current. I know autosizing.inc works with previous versions but I missed some of the latest progress and the improvement of redim. I don't know yet how this will affect the file.

Charles Pegge

Yes, I see the problem! It's affecting UDT/Class variables with redim ...

Zlatko Vid

Well
I really never use ReDim command in o2 ..i think in any Basic
I think that this command is problematic.

yes i tried with older 0.6.0 2023 06-03T07

Zlatko Vid

btw..
when we talking about autosize of controls inside
window ...it is prefered way to use
WM_SIZE message and put all sizing inside this message ?

Charles Pegge

I'm making progress with redim on UDTs and will need to do a few more tests. It's highly combinatorial with primitives, UDTs, classes, multi-dimensions, static and dynamic..

Theo Gottwald

#7
Does it mean i can make UDT's with dynamic strings?
It would be a large improvement compared to Powerbasic.
I  think Powerbasic was on the way to auto-redim when Bob passed away.

PS: Thought of making a new Setup,
but saw there has been a bug somewhere and now waiting for a stable version.

Charles Pegge

Yes Theo, there are no restrictions on what members you can use in a UDT, including dynamic strings. But you have to be careful when instantiating such UDT variables locally inside a function and then returning the variables. The local dynamic strings will get garbage-collected at the end of the function. The solution is to use bstrings instead of strings. These are also dynamic but not automatically garbage-collected.

The current problem with redim, is due to the _del macro being invoked inside the redim macro

Roland Stowasser

#9
Hi Charles,

at the moment I run programs every now and then and in demos\!ProjB\WinP the app SpaceInvaders.o2bas does not work. I assume line 194 must read:

      call PlayWav "../GDI/cosmobumm.wav",0,1

but the error occurs in line 73:

error:  unexpected end of prog
word : idx
proc:  setexplos
col:    7
line:  73
file:  'main source'

although no redim, maybe it's a similar problem?

Btw: do you know why Peter left the old forum?

Charles Pegge

#10
Thanks Roland,

It is the Dim inside a type. I have restored tolerance of this word. It is rarely used inside a type but I think the semantics are okay in Basic.

Perhaps Peter Wirbelauer got carried away by his Dancing Gnomes :). He got some fairly hostile treatment from John Spikowski and Mike Lobanovsky, which was not unusual on the Oxygen Forum. His APIs and demo code are specialized for single window 2d games. Compact and elegant.


Frank Brübach

Hey Roland Here is a fixed Version and its running Well :) of Ufo Game

'fixed version, 08-02-2024 by frank bruebach, oxyenbasic
'
include "win.inc"
int i
sys SetTimer = CallDll(user,"SetTimer")
sys KillTimer= CallDll(user,"KillTimer")

Screen 800,600,1
SetCaption "UFFO"
SetColorKey 255,0,255
ShowMouse 0

Type uBomb
  x as long
  y as long
  z as Single
End Type

Type Uffo
  x as long
  y as long
  z as long
  r as long
  i as long
  n as long
End Type

Type Rocket
  x as long
  y as long
  r as long
End Type

Type Explosion
  x as long
  y as long
  i as long
  z as single
End Type

Dim Meg(40) as uBomb
Dim Ufo(40) as Uffo
Dim Bum(40) as Explosion
Dim Rok(40) as Rocket
sys xRak,yRak,rRak,zRak,iBx,iDx,iCx,iAx,zFrame,z1,z2,z3,px,sc,uz,jx,drop,Ok
sys ufos,miss,ship,bomb expl,bknd

'bknd= LoadBmp "media/bground.bmp",1
ufos= LoadBmp "media/ufos.bmp",8
miss= LoadBmp "media/missile.bmp",8
ship= LoadBmp "media/ships.bmp",8
bomb= LoadBmp "media/bomb1.bmp",8
expl= LoadBmp "media/explode.bmp",8

Function Timer1() as long callback
zFrame +=1
iF zFrame =8 Then zFrame =0
End Function

Function Timer2() as long callback
jx +=1
iF jx =21 Then jx=0
End Function

Function Timer3() as long callback
Drop = Rand(0,40)
End Function

z1= call SetTimer hwnd,1,140,&Timer1
z2= call SetTimer hwnd,2,200,&Timer2
z3= call SetTimer hwnd,3,150,&Timer3

Sub SetExplos(sys x, y, i)
For iDx=0 To 39
iF Bum(iDx).y =0
  Bum(iDx).x = x
  Bum(iDx).y = y
  Bum(iDx).i = i
  Exit Sub
End iF
Next
End Sub

Sub ShowExplos()
For iDx=0 To 39
iF Bum(iDx).i =1
  SetBmp expl,Bum(iDx).x,Bum(iDx).y,96,96,Bum(iDx).z
  Bum(iDx).z +=.1
  iF Bum(iDx).z >=8.0
      Bum(iDx).z =0
      Bum(iDx).y =0
      Bum(iDx).i =0
  End iF
End iF
Next
End Sub

Sub SetRocket(sys x, y)
For iAx=0 To 39
iF Rok(iAx).y =0
  Rok(iAx).x = x
  Rok(iAx).y = y
  Rok(iAx).r = 1
  Exit Sub
End iF
Next
End Sub

Sub ScanRocket()
For iAx=0 To 39
iF Rok(iAx).r =1 and Rok(iAx).y <=-32
  Rok(iAx).r =0: Rok(iAx).y =0
End iF
Next
End Sub

Sub ShowRocket()
For iAx=0 To 39
iF Rok(iAx).r =1
  SetBmp miss,Rok(iAx).x,Rok(iAx).y,64,64,zFrame
  Rok(iAx).y -=1
  iF Rok(iAx).y =400 Then zRak=0
End iF
Next
End Sub

Sub ScanRakete()
iF rRak=5 Then Exit Sub
iF Key(32)<>0 and Key(39)<>0 and zRak =0
  SetRocket xRak,yRak
  rRak =1
  zRak =1
  call PlayWav "media/shoot.wav",0,1
ElseiF Key(32)<>0 and Key(37)<>0 and zRak=0
  SetRocket xRak,yRak
  rRak =2
  zRak =1
  call PlayWav "media/shoot.wav",0,1
ElseiF Key(32)<>0 and zRak=0
  SetRocket xRak,yRak
  zRak =1
  call PlayWav "media/shoot.wav",0,1
ElseiF Key(39)<>0 and xRak<736
  rRak =1
ElseiF Key(37)<>0 and xRak>0
  rRak =2
Else
  rRak =0
End iF
End Sub

Sub ShowRakete()
iF rRak =0
  SetBmp ship,xRak,yRak,64,64,zFrame
ElseiF rRak =1
  SetBmp ship,xRak,yRak,64,64,zFrame
  xRak +=1
ElseiF rRak =2
  SetBmp ship,xRak,yRak,64,64,zFrame
  xRak -=1
End If
End Sub

Function Collision(sys x1, y1, r1, x2, y2, r2) as sys
iF (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)<(r1+r2)*(r1+r2)
  Return 1
End iF
End Function

Sub RocketCollision()
For iBx=0 To uz
For iCx=0 To 39
iF Rok(iCx).r >0 And Ufo(iBx).r >0 
  iF Collision Rok(iCx).x+32,Rok(iCx).y+32,16,Ufo(iBx).x+32,Ufo(iBx).y+32,16
      SetExplos Rok(iCx).x,Rok(iCx).y,1
      SetExplos Ufo(iBx).x,Ufo(iBx).y,1
      Rok(iCx).r =0: Rok(iCx).y =0
      Ufo(iBx).r =0: Ufo(iBx).y =0
      call PlayWav "media/plode.wav",0,1
      sc +=25
      Exit For
  End iF
End iF
Next
Next
End Sub

Sub RaketeCollision()
iF Ok=1 Then Exit Sub
For iAx=0 To 40
iF Meg(iAx).y >0
  iF Collision xRak,yRak,16,Meg(iAx).x,Meg(iAx).y,16
      SetExplos xRak,yRak,1
      rRak=5: Ok=1
      'call PlayWav "media/xship.wav",0,1
      call PlayWav "../GDIWindow/cosmobumm.wav",0,1
      Exit Sub
  End iF
End iF
Next
End Sub
 
Sub SetUfos()
For iAx=0 To uz
Ufo(iAx).x = Rand(16,736)
Ufo(iAx).y = Rand(16,300)
Ufo(iAx).r = Rand(1,4)
Ufo(iAx).z = 0
Ufo(iAX).n = 0
Next
End Sub

Sub ScanUfos()
For iBx=0 To uz
iF Ufo(iBx).r =1 and Ufo(iBx).x >=736
  Ufo(iBx).r =2
ElseiF Ufo(iBx).r =2 and Ufo(iBx).x <=0
  Ufo(iBx).r =1
ElseiF Ufo(iBx).r =3 and Ufo(iBx).y <=0
  Ufo(iBx).r =4
ElseiF Ufo(iBx).r =4 and Ufo(iBx).y >=350
  Ufo(iBx).r =3
ElseiF jx =5 and Ufo(iBx).r =4
  Ufo(iBx).r = Rand(1,4)
ElseiF jx =10 and Ufo(iBx).r =3
  Ufo(iBx).r = Rand(1,4)
ElseiF jx =15 and Ufo(iBx).r =2
  Ufo(iBx).r = Rand(1,4)
ElseiF jx =20 and Ufo(iBx).r =1
  Ufo(iBx).r = Rand(1,4)
End iF
Next
End Sub

Sub ShowUfos()
For iBx=0 To uz
iF Ufo(iBx).r =1
  SetBmp ufos,Ufo(iBx).x,Ufo(iBx).y,64,64,zFrame
  Ufo(iBx).x +=1
ElseiF Ufo(iBx).r =2
  SetBmp ufos,Ufo(iBx).x,Ufo(iBx).y,64,64,zFrame
  Ufo(iBx).x -=1
ElseiF Ufo(iBx).r =3
  SetBmp ufos,Ufo(iBx).x,Ufo(iBx).y,64,64,zFrame
  Ufo(iBx).y -=1
ElseiF Ufo(iBx).r =4
  SetBmp ufos,Ufo(iBx).x,Ufo(iBx).y,64,64,zFrame
  Ufo(iBx).y +=1
End iF
Next
End Sub

Sub SetData
xRak=384:yRak=536:rRak=0
uz=40:sc=0:Ok=0
SetUfos
For iBx=0 To 40
Meg(iBx).y =0
Meg(iBx).x =0
Next
End Sub

Sub TestUfos()
For iAx=0 To 40
iF Ufo(iAx).y >0 or Ok=1 Then Exit Sub
Next
Ok=1
End Sub

Sub ScanUfoBombs()
For iAx=0 To drop Step 2 
iF Ufo(iAx).r >0
  iF Meg(iAx).y=0
      Meg(iAx).x = Ufo(iAx).x
      Meg(iAx).y = Ufo(iAx).y+32
  End iF
End iF
Next
End Sub

Sub UfoBombs()
For iDx=0 To 40
iF Meg(iDx).y >0
  iF iDx <20
      SetBmp bomb,Meg(iDx).x,Meg(iDx).y,64,64,zFrame
  ElseiF iDx >=20
      SetBmp bomb,Meg(iDx).x,Meg(iDx).y,64,64,zFrame
  End iF
  Meg(iDx).y +=1
  iF Meg(iDx).y >=600 Then Meg(iDx).y =0
End iF
Next
End Sub

'Main
'====
SetData()
While Key(27)=0
'SetBmp bknd,0,0,800,600,0
'ClsColor 10,0,90
for i=0 to 599
  line 0,i,799,i,1,0,0,i >>2 'shaded sky
next
SetText 600,0,"SCORE:" + sc,255,255,255
ScanUfos
ShowUfos
ScanRocket
ShowRocket
ScanRakete
ShowRakete
ScanUfoBombs
UfoBombs
ShowExplos
RocketCollision
RaketeCollision
TestUfos
iF Ok=1
  SetText 328,300,"Once again?  ",255,250,245
  SetText 328,320,"Hit [c] Key",200,245,255
  iF Key(0x43) <>0 Then SetData
End iF
Flip
SetFps 80 'select your speed :)
Wend
call KillTimer hwnd,z1
call KillTimer hwnd,z2
call KillTimer hwnd,z3
'Ends
End

Zlatko Vid

QuotePerhaps Peter Wirbelauer got carried away by his Dancing Gnomes

Yeah..i am wondering where is that guy
I like him.  ;)

Roland Stowasser

#13
Hi Frank,

your modifications in type uBomb, Uffo, Rocket and Explosion will work, although you have also to change in line 196: GDIWindow to GDI, otherwise you will miss the final big "Bumms". I never used dim in defining members  a type, but in previous versions this was supported.

Theo Gottwald

Quote from: Charles Pegge on February 07, 2024, 10:11:17 AMYes Theo, there are no restrictions on what members you can use in a UDT, including dynamic strings. But you have to be careful when instantiating such UDT variables locally inside a function and then returning the variables. The local dynamic strings will get garbage-collected at the end of the function. The solution is to use bstrings instead of strings. These are also dynamic but not automatically garbage-collected.

The current problem with redim, is due to the _del macro being invoked inside the redim macro

@Charles Pegge I would expect that local variables are of course deleted after leaving a SUB/Function.
But I expect Global Variables to stay persistant even if been changed inside a SUB Function.
In  PB i  currently have STRINGS and WStrings.
BStrings i only know from being type of System-Strings. What string types are available in there?
And why do i need several of these?