Results 1 to 9 of 9

Thread: Report a hidden bug

  1. #1
    Member
    Join Date
    Jan 2017
    Location
    changsha China
    Age
    32
    Posts
    80
    Rep Power
    16

    Report a hidden bug

    There may be logic errors in parsing when writing code for loops or array operations.

    Although the code is correct, ThinBasic reports errors.

    The magic thing is that as long as you add a piece of code that doesn't work, it will run without problems.

    You can compare the code in these two pictures.

    1.jpg

    2.jpg

    The error is on line 259, so I added some debugging in the front (output the content to dbgview), and then no more error.

    In fact, I have encountered such inexplicable problems in various programming I have done before. Often when I troubleshoot the problem, I add the code output to dbgview and the problem is solved.

    I think this should be a bug on the grammar or lexer, but this problem is difficult to reproduce and it is difficult to find the smallest use case.

    So I do n’t know how to report this problem, I hope ErosOlmi will do some troubleshooting.

  2. #2
    Member
    Join Date
    Jan 2017
    Location
    changsha China
    Age
    32
    Posts
    80
    Rep Power
    16
    3.jpg

    This is another similar problem encountered some time ago.

    The loop can't jump out normally. Adding some useless code in front of the loop can solve it, but the code is always modified, so the problem that can't jump out always appears, so I can only judge inside the loop to solve this problem.



    Say something off topic

    Earlier Petr Schreiber told me that ThinBasic only performs the most basic syntax check on the code at runtime to improve the efficiency of the operation.

    Has ErosOlmi considered developing a bytecode instruction system for ThinBasic?

    This results in more complete syntax checking and better performance.

    Of course, this is a time-consuming work. It is not suitable to add in the current version. It may be carried out when porting to FreeBasic.

  3. #3
    Hi xLeaves,

    in the first post I can't read, it's too small.

    In the second post, what is the problem with loop exit ? Please post the code that fails.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi xLeaves,

    the best would be to isolate the issue to the replicable example.

    On the first RunTimeError, I can see thinBasic complains that you pass index of array as 0, but the array has dimensions 1 to 60.

    So, in this case, I might be zero, or ILevel might be zero. Please try to print these two to console or break the expression to smaller ones.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Ciao xLeaves,

    If I saw well from images
    1. the first is a array "subscription out of range" that is script try to read element index <= 0 or > max number of array elements. In this case zero
      But it seems that changing some code, problem seems solved.
    2. the second seems that EXIT DO doesn't work as expected.


    I would like to analyze and fix such issues but I need to have a piece of code that I can run.
    If you are able to isolate in a script that you can attach here ... it would be of great help.

    In the mean time I will try to see EXIT DO issue that is more easy to verify for me.
    EXIT DO internally scan the code in order to find next LOOP having the same indent level of the current loop.
    It can be "
    bad" influenced by how the code is written, maybe I missed some programming behave.


    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    Member
    Join Date
    Jan 2017
    Location
    changsha China
    Age
    32
    Posts
    80
    Rep Power
    16
    Dear ErosOlmi, and everyone who responded:

    I'm sorry that I haven't responded to this question. After posting, I didn't check whether the image is clear, so that you can't see the error code.
    I have developed some tools using ThinBasic. At present, the above error occurs in a project of about 3000 lines. The reason why the code to reproduce the problem is not provided is simply because when I try to simplify the code , The error disappeared, I will attach the complete project code and point out the specific error location.

    release.zip

    This source code runs on ThinBasic 1.11.2.0 and was developed using LzRPA. Lzbot_test_boot.tbasic and lzbot_test_main.tbasic are the generated source code. Just run lzbot_test_boot.tbasic.

    Its role is to generate a bunch of XML documents used in the game based on an Excel spreadsheet. The spreadsheet file name is:设计表.xlsx (Can be opened with Office 2007 and above)

    After running, he will output documents such as item.xml, suit.xml, monster.xml, drop.xml, etc.



    Next, I will mark the error code:

    The first paragraph, adding irrelevant code does not report an error

    In lines 2888 and 2889 of lzbot_test_main.tbasic, the problem is that when I comment out the 2888 lines of code, an array overflow error is raised (in fact, I tried to output the length and data of the array, and it didn't Overflow), and when this line of code runs, the array will not overflow, and the function of this line of code is just to output a message to my IDE, I do not know why it will affect the results of the next line.

    For i = sDropMid To sDropHigh
    	Dim iLevel As Long = i - sDropMid + 1
    	Dim iPrevDrop As Long = 0
    	If iLevel > 1 Then
    		iPrevDrop = DropRate(iLevel - 1)
    	End If
    	TracePrint "动态爆率:" & iLevel & ",阶数:" & i & ",上一阶分母:" & iPrevDrop       ' Error Point
    	DropRate(iLevel) = (((DropWeight(i) * 8) + 2) * HighDrop(iLevel)) + iPrevDrop          ' Error Point
    Next
    
    The second problem does not jump out of the loop

    It happened on line 1964, you can see that the While part of this line of code is commented out, and on line 1970, I added another judgment to avoid the situation where the loop cannot break out. I guess this problem is caused by the data type, it It's been a long time and I haven't continued to study the cause and try to fix it, maybe I can take a look recently.

    ItemLine = 2
    Do 'While (Sheet_Item.Cells(ItemLine, 3).Value <> "")      ‘ Error Point
    	
    	' 读取记录生成装备数据
    	ItemLevel     = Sheet_Item.Cells(ItemLine,  1).Value
    	sLevel        = Sheet_Item.Cells(ItemLine,  2).Value
    	sKeyName      = Sheet_Item.Cells(ItemLine,  3).Value
    	If sKeyName = "" Then                                 ‘ Error Point
    		Exit Do
    	End If
    	TracePrint("正在处理 " & sKeyName)
    

  7. #7
    Member
    Join Date
    Jan 2017
    Location
    changsha China
    Age
    32
    Posts
    80
    Rep Power
    16
    Sorry to mention these two very strange questions. I understand very well the idea that a programmer wants the simplest use case to troubleshoot. When my tool encounters a bug, I usually want the simplest steps to reproduce it. , But these problems did come after I wrote a certain number of lines of code.

    In addition, a new problem is reported here:

    When a Declare statement defines an external DLL function, if an extra layer of encapsulation is used on the basis of this function, and it happens to have the same parameter name, an error will be reported, for example:

    Declare Sub Sleep Lib "kernel32.dll" Alias "Sleep" (ByVal ms As Long)
    
    Function MySleep(ByVal ms As Long)
    	Sleep(ms)
    End Function
    
    Function Main() As Long
    	MsgBox("Hello World")
        MySleep(1000)
    	MsgBox("Hello World2")
    End Function
    

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Quote Originally Posted by xLeaves View Post
    Sorry to mention these two very strange questions. I understand very well the idea that a programmer wants the simplest use case to troubleshoot. When my tool encounters a bug, I usually want the simplest steps to reproduce it. , But these problems did come after I wrote a certain number of lines of code.

    In addition, a new problem is reported here:

    When a Declare statement defines an external DLL function, if an extra layer of encapsulation is used on the basis of this function, and it happens to have the same parameter name, an error will be reported, for example:

    Declare Sub Sleep Lib "kernel32.dll" Alias "Sleep" (ByVal ms As Long)
    
    Function MySleep(ByVal ms As Long)
        Sleep(ms)
    End Function
    
    Function Main() As Long
        MsgBox("Hello World")
        MySleep(1000)
        MsgBox("Hello World2")
    End Function
    
    Here the problem is that you cannot declare an external function having the same name of thinBasic keyword.
    "Sleep" is a thinBasic keyword so you get an error.

    You can declare it with a different name:
    Declare Sub MyVersionOfSleep Lib "kernel32.dll" Alias "Sleep" (ByVal ms As Long)
    


    Regarding the intermittent error reported above ... I'm testing.
    At first sight the only thing I've seen is that is strange is that you DIM variable inside loops and I didn't consider that fact.

    Usually DIM ... should be placed outside loops.
    When thinBasic see DIM <VariableName> As <VariableType> it checks if <VariableName> is already defined in the current stack level.
    If yes, it check if <VariableType> is the same of the already defined variable.
    If also this is true, DIM is just ignored.
    But having so much DIM <VariableName> As <VariableType> = <expression> can be a problem.
    Anyway ... going on in checking
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9
    Member
    Join Date
    Jan 2017
    Location
    changsha China
    Age
    32
    Posts
    80
    Rep Power
    16
    Quote Originally Posted by ErosOlmi View Post
    Here the problem is that you cannot declare an external function having the same name of thinBasic keyword.
    "Sleep" is a thinBasic keyword so you get an error.

    You can declare it with a different name:
    Declare Sub MyVersionOfSleep Lib "kernel32.dll" Alias "Sleep" (ByVal ms As Long)
    


    Regarding the intermittent error reported above ... I'm testing.
    At first sight the only thing I've seen is that is strange is that you DIM variable inside loops and I didn't consider that fact.

    Usually DIM ... should be placed outside loops.
    When thinBasic see DIM <VariableName> As <VariableType> it checks if <VariableName> is already defined in the current stack level.
    If yes, it check if <VariableType> is the same of the already defined variable.
    If also this is true, DIM is just ignored.
    But having so much DIM <VariableName> As <VariableType> = <expression> can be a problem.
    Anyway ... going on in checking
    Thank you ErosOlmi. The last question is my negligence. I'm very sorry to ask you to verify such a question.

Similar Threads

  1. STL Container Size Limit Report
    By kryton9 in forum Software discussion
    Replies: 2
    Last Post: 24-12-2011, 00:55
  2. The Hidden Beauty of Pollination
    By Charles Pegge in forum Shout Box Area
    Replies: 0
    Last Post: 28-11-2011, 23:16
  3. a skull hidden in painting
    By zak in forum Shout Box Area
    Replies: 1
    Last Post: 05-11-2010, 14:49
  4. TBDI - Progress report
    By Michael Hartlef in forum TBDI module. thinBasic Direct Input integration by MikeHart
    Replies: 30
    Last Post: 14-03-2007, 10:04

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •