[Help] Converting code from PureBasic!

Just starting out? Need help? Post your questions and find answers here.
Mijikai
Posts: 12
Joined: Sun Sep 17, 2017 9:59 am

[Help] Converting code from PureBasic!

Post by Mijikai »

I always wanted to test SpiderBasic so i tried to convert one of my PureBasic codes. 8-)

Sadly nothing seems to work... :cry:

What im doing wrong ? :?

Code (SpiderBasic Demo 2.10):

Code: Select all

DeclareModule CHESS
  Declare.i Init(Title.s)
EndDeclareModule

Module CHESS
  
  Structure GUI_STRUCT
    Window.i
    WindowHandle.i
  EndStructure
  
  Structure CHESS_STRUCT
    GUI.GUI_STRUCT  
  EndStructure
  
  Procedure.i CallbackWindowClose()
    Debug 123
    CloseWindow(EventWindow())
  EndProcedure
  
  Procedure.i Init(Title.s)
    Protected *Chess.CHESS_STRUCT
    *Chess = AllocateMemory(SizeOf(CHESS_STRUCT))
    If *Chess
      *Chess\GUI\Window = OpenWindow(#PB_Any,#Null,#Null,600,460,Title,#PB_Window_SizeGadget|#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
      If IsWindow(*Chess\GUI\Window)
        *Chess\GUI\WindowHandle = WindowID(*Chess\GUI\Window)
        WindowBounds(*Chess\GUI\Window,600,460,#PB_Ignore,#PB_Ignore);Does not work!
        BindEvent(#PB_Event_CloseWindow,@CallbackWindowClose(),*Chess\GUI\Window);Callback does not get called!
        ;BindEvent(#PB_Event_CloseWindow,@CallbackWindowClose());Callback does not get called!
        ProcedureReturn *Chess
      EndIf 
      FreeMemory(*Chess)
    EndIf
  EndProcedure
  
EndModule


Debug CHESS::Init("Test Window 1")
Debug CHESS::Init("Test Window 2");2nd Window wont open!
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: [Help] Converting code from PureBasic!

Post by falsam »

JavaScript Error
Uncaught TypeError: Cannot set property '_Window' of undefined
at chess$f_init (spiderbasic.js:286)
at SpiderLaunch (spiderbasic.js:302)
at SpiderMain (main.js:24)
at main.js:41
at fa (dojo.js:19)
at dojo.js:20
at ga (dojo.js:20)
at da (dojo.js:20)
at s (dojo.js:22)
at HTMLScriptElement.<anonymous> (dojo.js:27)
But why ?.....

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: [Help] Converting code from PureBasic!

Post by falsam »

:!: I think there is a bug with the pointers of structures.

■ Modify your procedure Init(Title.s) with this code and test the structure *Chess

Code: Select all

 Procedure.i Init(Title.s)
    Protected *Chess.CHESS_STRUCT
    *Chess = AllocateMemory(SizeOf(CHESS_STRUCT))
    If *Chess
      Debug *Chess\GUI
      
      ;*Chess\GUI\Window = OpenWindow(#PB_Any,#Null,#Null,600,460,Title,#PB_Window_SizeGadget|#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
      ;If IsWindow(*Chess\GUI\Window)
      ;  *Chess\GUI\WindowHandle = WindowID(*Chess\GUI\Window)
        ;WindowBounds(*Chess\GUI\Window,600,460,#PB_Ignore,#PB_Ignore);Does not work!
        ;BindEvent(#PB_Event_CloseWindow,@CallbackWindowClose(),*Chess\GUI\Window);Callback does not get called!
                                                                                 ;BindEvent(#PB_Event_CloseWindow,@CallbackWindowClose());Callback does not get called!
      ;  ProcedureReturn *Chess
      ;EndIf 
     FreeMemory(*Chess)
    EndIf
  EndProcedure  
*Chess\GUI is undefined

■ Now WorkAround with this code.

Code: Select all

Procedure.i Init(Title.s)
    Protected Chess.CHESS_STRUCT
    ;*Chess = AllocateMemory(SizeOf(CHESS_STRUCT))
    If CHESS      
      Chess\GUI\Window = OpenWindow(#PB_Any,#Null,#Null,600,460,Title,#PB_Window_SizeGadget|#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
      If IsWindow(Chess\GUI\Window)
        Chess\GUI\WindowHandle = WindowID(Chess\GUI\Window)
        WindowBounds(Chess\GUI\Window,600,460,#PB_Ignore,#PB_Ignore);Does not work!
        BindEvent(#PB_Event_CloseWindow,@CallbackWindowClose(),Chess\GUI\Window);Callback does not get called!
                                                                                 ;BindEvent(#PB_Event_CloseWindow,@CallbackWindowClose());Callback does not get called!
        ProcedureReturn Chess
      EndIf 
     ;FreeMemory(*Chess)
    EndIf
  EndProcedure  
EndModule
You have your two windows.

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
Mijikai
Posts: 12
Joined: Sun Sep 17, 2017 9:59 am

Re: [Help] Converting code from PureBasic!

Post by Mijikai »

Seems like everything breaks as soon as i pass something to the allocated structure:

Code: Select all

*Chess\GUI\Window = XYZ
Is this a bug ? :(
Mijikai
Posts: 12
Joined: Sun Sep 17, 2017 9:59 am

Re: [Help] Converting code from PureBasic!

Post by Mijikai »

falsam wrote:I think there is a bug with the pointers of structures.

....
Thanks for your reply.
I just saw it when i had posted my suspicion about a possible bug,
If that is the case SpiderBasic is not safe to use - ill only continue my endeavour once this issue is resolved.
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Re: [Help] Converting code from PureBasic!

Post by MrTAToad »

Try using AllocateStructure instead of AllocateMemory - by the looks of it, the latter is only to be used with Poke and Peek, whilst the former is for structures.

Thus :

Code: Select all

DeclareModule CHESS
  Declare.i Init(Title.s)
EndDeclareModule

Module CHESS
  
  Structure GUI_STRUCT
    Window.i
    WindowHandle.i
  EndStructure
  
  Structure CHESS_STRUCT
    GUI.GUI_STRUCT  
  EndStructure
  
  Procedure.i CallbackWindowClose()
    Debug 123
    CloseWindow(EventWindow())
  EndProcedure
  
  Procedure.i Init(Title.s)
    Protected *Chess.CHESS_STRUCT
    Debug "HERE"
    *Chess = AllocateStructure(CHESS_STRUCT)
    Debug "Size : "+Str(SizeOf(CHESS_STRUCT))
    If *Chess=#Null
      Debug "IS NULL"
    Else
      Debug "Is not NULL"
    EndIf
    
    If *Chess
      *Chess\GUI\Window = OpenWindow(#PB_Any,#Null,#Null,600,460,Title,#PB_Window_SizeGadget|#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
      If IsWindow(*Chess\GUI\Window)
        *Chess\GUI\WindowHandle = WindowID(*Chess\GUI\Window)
        WindowBounds(*Chess\GUI\Window,600,460,#PB_Ignore,#PB_Ignore);Does not work!
        BindEvent(#PB_Event_CloseWindow,@CallbackWindowClose(),*Chess\GUI\Window);Callback does not get called!
        ;BindEvent(#PB_Event_CloseWindow,@CallbackWindowClose());Callback does not get called!
        ProcedureReturn *Chess
      EndIf 
      FreeMemory(*Chess)
    EndIf
  EndProcedure
  
EndModule


Debug CHESS::Init("Test Window 1")
Debug CHESS::Init("Test Window 2");2nd Window wont open!
Also dont forget that structures in SpiderBasic are actually functions, with added code in. I suspect what is happening, is although 8 bytes are being allocated for the "structure", its proper size is larger and thus causing a memory overflow problem.
Mijikai
Posts: 12
Joined: Sun Sep 17, 2017 9:59 am

Re: [Help] Converting code from PureBasic!

Post by Mijikai »

MrTAToad wrote:Try using AllocateStructure instead of AllocateMemory - by the looks of it, the latter is only to be used with Poke and Peek, whilst the former is for structures.

...

Also dont forget that structures in SpiderBasic are actually functions, with added code in. I suspect what is happening, is although 8 bytes are being allocated for the "structure", its proper size is larger and thus causing a memory overflow problem.
Thanks for the reply.
If that is the case (as it seems now) it should be stated/explained in the helpfile. :shock:
This should not be a guessing game... i rly hope this issue gets resolved. :|
User avatar
MrTAToad
Posts: 291
Joined: Sun Apr 20, 2014 11:43 am
Location: Chichester, England
Contact:

Re: [Help] Converting code from PureBasic!

Post by MrTAToad »

Yes, hopefully appropriate amendments will be made to the help file :)
Post Reply