[SOLVED] Program aborted. (by external library)

Mac OSX specific forum
User avatar
parsec
New User
New User
Posts: 8
Joined: Sat Dec 14, 2024 9:33 am

[SOLVED] Program aborted. (by external library)

Post by parsec »

I'm getting a crash on my Mac M2 Sequoia 15.2/PB 6.20 which I'm not sure how to debug further as the error message is not very informative. Program will run under the debugger for hours then aborts with this message:

Code: Select all

[10:27:04] Executable type: MacOSX - arm64  (64bit, Unicode, Thread)
[10:27:04] Executable started.
[16:24:08] [ERROR] LSV6-Config.pb (Line: 851)
[16:24:08] [ERROR] Program aborted. (by external library)
My code has a threaded network procedure (not shown here) where binary data is sent and received over TCP. A structure guarded by a mutex is used to move information between thread and main UI loop, and in the network thread PostEvents are used for signalling when the UI needs updating. So every time the network thread sends data, which is every 5 seconds, it will emit a PostEvent(#EventUpdateTXLed)

This is then handled in the main loop:

Code: Select all

...
Case #EventUpdateTXLed   ; TX Led is in the status bar and updated less frequently than top window
  TXLEDState = #LED_On   ; Only set state and leave UI updating to periodic call below
  TXLEDTmr = ElapsedMilliseconds()
...
;Update status bar LEDs and indicators every 96 ms.
If elapsedMS - led_tmstamp > 96 
  LockMutex(TransferDataMtx)
  LEDCtrl(@DeviceMsg)
  UnlockMutex(TransferDataMtx)
  led_tmstamp = elapsedMS
EndIf
The LEDCtrl() proc will in turn call StatusBar() listed below, which is where the crash supposedly happens on the last line (StatusBarImage()):

Code: Select all

Procedure StatusBar(fieldIdx.i, icon.i, str.s, pad_top.i=0, pad_right=0)
   
  If CreateImage(#MemCanvas, 150, 20)
    If StartDrawing(ImageOutput(#MemCanvas))
      Box(0, 0, 200, 20, SbarBGColor)
      
      If fieldIdx <> #SBField_Padding
        DrawingFont(FontID(sbFontID))
        DrawingMode(#PB_2DDrawing_Transparent)

        DrawAlphaImage(ImageID(icon), 0, 3+pad_top) 
      
        FrontColor(SbarFGColor)
        DrawText(14+pad_right,1,str)
      EndIf

      StopDrawing()
    EndIf
  EndIf
  
  StatusBarImage(0, fieldIdx, ImageID(#MemCanvas)) ; <*** Program aborted. (by external library)
EndProcedure
I'm fairly certain that I don't have a thread race condition anywhere and have no idea what this "external library" that is causing the crash is?

I've encountered the problem a few times now and while it may be coincidental, the crash appears to happen either while the screen is sleeping (WiFi is always powered on so network is always available) or shortly after the screen wakes up. Enabling Purifier will cause a hang without any error messages shown. Any suggestions on how to deal with my problem would be appreciated.
Last edited by parsec on Thu Feb 27, 2025 8:40 am, edited 1 time in total.
User avatar
Piero
Addict
Addict
Posts: 918
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Program aborted. (by external library)

Post by Piero »

parsec wrote: Thu Feb 20, 2025 2:46 pmProgram aborted. (by external library)
I bet it's fieldIdx; the first field index starts from zero.
User avatar
parsec
New User
New User
Posts: 8
Joined: Sat Dec 14, 2024 9:33 am

Re: Program aborted. (by external library)

Post by parsec »

Piero wrote: Tue Feb 25, 2025 12:55 pm
parsec wrote: Thu Feb 20, 2025 2:46 pmProgram aborted. (by external library)
I bet it's fieldIdx; the first field index starts from zero.
Nope, all calls to this proc are done by using constants (#SBField_xxxx) and the status bar is updated every 96 ms. An index overflow would crash it immediately or much much sooner. Note in the log that the program was running for nearly 6 hours before crashing. I suspect the actual point of failure is somewhere else but due to threading it just happened to stop here because that's where the instruction pointer was at.
User avatar
Piero
Addict
Addict
Posts: 918
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Program aborted. (by external library)

Post by Piero »

parsec wrote: Tue Feb 25, 2025 5:55 pmNope
Darn, I got the 1st "by external library" today, and it pointed to an "EnableDebugger" line… but it was just an Array.s(index) "overflow"; maybe it's some array index?
User avatar
parsec
New User
New User
Posts: 8
Joined: Sat Dec 14, 2024 9:33 am

Re: Program aborted. (by external library)

Post by parsec »

Piero wrote: Tue Feb 25, 2025 6:38 pm
parsec wrote: Tue Feb 25, 2025 5:55 pmNope
Darn, I got the 1st "by external library" today, and it pointed to an "EnableDebugger" line… but it was just an Array.s(index) "overflow"; maybe it's some array index?
Could be some memory corruption but it's just guessing at this point since it doesn't seem possible to get a disassembly on Mac. I got the same error again today, aborted in an entirely different location in the code but again related to the UI updating. So I'm fairly certain the code line indicated by the error message is a red herring and has little to do with the actual problem.
User avatar
mk-soft
Always Here
Always Here
Posts: 6244
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Program aborted. (by external library)

Post by mk-soft »

If you work with threads, you can't update the UI from the thread. You have to solve this with PostEvent.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
parsec
New User
New User
Posts: 8
Joined: Sat Dec 14, 2024 9:33 am

Re: Program aborted. (by external library)

Post by parsec »

mk-soft wrote: Wed Feb 26, 2025 11:50 pm If you work with threads, you can't update the UI from the thread. You have to solve this with PostEvent.
Thanks but, to quote myself in the first post : "..and in the network thread PostEvents are used for signalling when the UI needs updating."

I solved the problem, self-inflicted of course. In the network thread I was providing an incorrect length when invoking ReceiveNetworkData(Connection, *DataBuffer, DataBufferLength). DataBufferLength was 4x (4096 b) the allocated receive buffer size (1024 b) so in some rare cases where the number of received bytes exceeded 1024 it would cause a buffer overflow and abort. Duh!
Post Reply