Page 1 of 1
[Help] Converting code from PureBasic!
Posted: Sun Sep 17, 2017 10:12 am
by Mijikai
I always wanted to test SpiderBasic so i tried to convert one of my PureBasic codes.
Sadly nothing seems to work...
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!
Re: [Help] Converting code from PureBasic!
Posted: Sun Sep 17, 2017 10:24 am
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 ?.....
Re: [Help] Converting code from PureBasic!
Posted: Sun Sep 17, 2017 10:54 am
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.
Re: [Help] Converting code from PureBasic!
Posted: Sun Sep 17, 2017 11:02 am
by Mijikai
Seems like everything breaks as soon as i pass something to the allocated structure:
Is this a bug ?

Re: [Help] Converting code from PureBasic!
Posted: Sun Sep 17, 2017 11:13 am
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.
Re: [Help] Converting code from PureBasic!
Posted: Sun Sep 17, 2017 9:30 pm
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.
Re: [Help] Converting code from PureBasic!
Posted: Mon Sep 18, 2017 5:05 pm
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.
This should not be a guessing game... i rly hope this issue gets resolved.

Re: [Help] Converting code from PureBasic!
Posted: Mon Sep 18, 2017 6:25 pm
by MrTAToad
Yes, hopefully appropriate amendments will be made to the help file
