Announcement

Collapse
No announcement yet.

This code crashes when called a few times in a row...

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • This code crashes when called a few times in a row...

    Hi
    This code works fine if called from the main form button press once. You can press the button 4 or 5 times in a row fast and it still works.
    HOWEVER, if you press the button very fast a bunch of times in row this will crash the program.
    I cant figure out why i can't trap the error?

    Code:
    '------------------------------------------------------------------------------
     FUNCTION POKE_4050() AS LONG
    
       LOCAL THREAD_HANDLE         AS LONG
       LOCAL THREAD_RESULT         AS LONG
    
    
        THREAD CREATE THREADED_POKE_4050(0) TO THREAD_HANDLE
    
        TEXT_TO_SCREEN_ONE "THREAD CREATED - " + STR$(THREAD_HANDLE)  '<-- for debug
        THREAD CLOSE  THREAD_HANDLE TO THREAD_RESULT
        TEXT_TO_SCREEN_ONE "THREAD CLOSED - " + STR$(THREAD_RESULT)    '<-- for debug
    
     END FUNCTION
    '------------------------------------------------------------------------------
     THREAD FUNCTION THREADED_POKE_4050(BYVAL NO_VALUE AS LONG ) AS LONG
    
      ON ERROR GOTO ERROR_CONTROL
    
      LOCAL CONTROLLER_UNIQUE_ID  AS LONG
      LOCAL FILE_NUMBER AS LONG
    
      FOR CONTROLLER_UNIQUE_ID = 1 TO 96
        IF GL_CONTROLLER_IP_ADDRESS(CONTROLLER_UNIQUE_ID) <> "" AND GL_CONTROLLER_NAME(CONTROLLER_UNIQUE_ID) <> "" THEN
    
        FILE_NUMBER = FREEFILE
        TEXT_TO_SCREEN_ONE "FILE NUMBER = " + STR$(FILE_NUMBER)   '<-- for debug
    
        TRY
         TCP OPEN PORT 4050 AT GL_CONTROLLER_IP_ADDRESS(CONTROLLER_UNIQUE_ID) AS FILE_NUMBER
         TEXT_TO_SCREEN_ONE "[S] VERTX_CONTACT_CONTROLLER " + GL_CONTROLLER_IP_ADDRESS(CONTROLLER_UNIQUE_ID)
        CATCH
         TEXT_TO_SCREEN_ONE "TCP OPEN ERROR " + GL_CONTROLLER_IP_ADDRESS(CONTROLLER_UNIQUE_ID)
        END TRY
    
        TRY
         TCP NOTIFY FILE_NUMBER, RECV CLOSE TO GL_hDlg AS %POKE_TCP_MASTER_EVENT
         TEXT_TO_SCREEN_ONE "P2"
        CATCH
         TEXT_TO_SCREEN_ONE "TCP NOTIFY ERROR " + GL_CONTROLLER_IP_ADDRESS(CONTROLLER_UNIQUE_ID)
        END TRY
    
        SLEEP 100
    
        TRY
         TCP SEND FILE_NUMBER, "0045;0010; " + GL_CONTROLLER_IP_ADDRESS(CONTROLLER_UNIQUE_ID)
         TEXT_TO_SCREEN_ONE "P3"
         CATCH
        TEXT_TO_SCREEN_ONE "TCP SEND ERROR"
        END TRY
    
       END IF
      NEXT
    
      EXIT FUNCTION
    
      ERROR_CONTROL:
      MSGBOX ERROR$
    
     END FUNCTION
    '------------------------------------------------------------------------------

  • #2
    Actually I can get the debugger to break on error and it is saying Subscript/Pointer out of range in the main form callback...
    So it looks like the problem is not in this function...

    Comment


    • #3
      I am going to move this to a new thread as the problem has nothing to do with the above listed code.

      Comment


      • #4

        RE:
        I cant figure out why i can't trap the error?
        ....

        Code:
        FUNCTION POKE_4050() AS LONG
        
          THREAD CREATE THREADED_POKE_4050(0) TO THREAD_HANDLE
        ...
        
        
        
        THREAD FUNCTION THREADED_POKE_4050(BYVAL NO_VALUE AS LONG ) AS LONG
        Re " When you ress the button very fast a bunch of times in row this will crash the program."

        You are (assumption, insufficient code shown) calling the procedure "POKE_4050" on the WM_COMMAND/BN_CLICKED which is starting a new thread of execution with the thread function THREADED_POKE_4050.

        But you have zero sunchronization. Depending on exactly how you control things - and you control nothing using the code shown - your code might be trying to execute multiple TOEs which are all fighting for the use of port 4050.

        I don't think you so much want to trap errors as to detect these conflicts... the easiest way of doing same is to not allow the button to be clicked until the code executed from the last click has reached a state where it is safe to start another TOE.




        e.g.
        Code:
          CASE WM_COMMAND/BN_CLICKED or the approproriate bnutton
             Disable the button
             CALL POKE_4050    ' which will not return until some event has ccurred    
             Enable the button
        That is, instead of looking for a way to trap errors, code so they cannot occur.


        Re:
        break on error and it is saying Subscript/Pointer out of range in the main form callback...
        Not that I am a fan of the stepping debugger, but it would seem you, too, recognize there is "insufficient code shown" to diagnose your issue with confidence.

        MCM
        Michael Mattias
        Tal Systems Inc.
        Racine WI USA
        mmattias@talsystems.com
        http://www.talsystems.com

        Comment

        Working...
        X