Include Binary Crashing Program

Just starting out? Need help? Post your questions and find answers here.
User avatar
FourthStone
User
User
Posts: 26
Joined: Mon Dec 11, 2017 8:44 am
Location: Australia

Include Binary Crashing Program

Post by FourthStone »

Hello, I have a crash issue with a couple of resource files I am trying to include with a project, I'm using PureBasic 5.73 LTS (Windows - x86).

When the files are included my program crashes after 5-10 seconds, I suspect it's the files themselves but I wanted to ask the question anyway in case I was overlooking something or potentially discovered a bug. The strange thing is when running with the debugger or from the compiled EXE the issue is not present, only when launching the program from the IDE (with debugger disabled).

This took me a while to track down as I thought I'd added some other logic to the program causing the crashes but when I reverted changes I'd recently made and commented out the include binary statements the problem was fixed.

I recreated the two problem BMP files as PNG and this seems to resolve the crashing so I'm guessing there was something problematic with the original two BMP files.

EDIT: The program is still crashing with the PNGs, but only the two below... very strange.

Code: Select all

; inline toolstrip bmps
ToolStripMain:       : IncludeBinary #PB_Compiler_FilePath + "/ART_TOOL_Buttons_02.BMP"
ToolStripMain2:      : IncludeBinary #PB_Compiler_FilePath + "/ART_TOOL_Palette_01.BMP"
  
ToolStripSubDraw:    : IncludeBinary #PB_Compiler_FilePath + "/ART_TOOL_Sub_Draw_01.BMP"
  
; these two files cause the program to crash
;ToolStripSubLine:    : IncludeBinary #PB_Compiler_FilePath + "/ART_TOOL_Sub_Line_01.BMP"
;ToolStripSubBox:     : IncludeBinary #PB_Compiler_FilePath + "/ART_TOOL_Sub_Box_01.BMP"
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: Include Binary Crashing Program

Post by eck49 »

You could try introducing Delay statements between or before the Loads to see if it makes a difference.

I've had issues in the IDE with things happening too quickly in succession. The IDE crashes leaving the program running - without access to any IDE resources but struggling even to shut down. Adding a short delay (say 50ms) enables the IDE to catch up with events. The unchanged code - without the Delay - compiled into an executable which runs with no problem. When debugging, the IDE clearly has a lot more work to do that the compiled program does not need to do. Maybe even with the Debugger disabled.

This is with PB 5.70 in Linux.
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
User avatar
mk-soft
Always Here
Always Here
Posts: 5398
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Include Binary Crashing Program

Post by mk-soft »

I have tested it once ...

I assume that the path information is not correct. That is one slash too many. The compiler constant already has the slash at the end.

Code: Select all


CompilerIf #PB_Compiler_FilePath = "/tmp/"
  CompilerError "Set compiler option - Create temporary executable in the source directory!"
CompilerEndIf

UsePNGImageDecoder()
UsePNGImageEncoder()

;#CreateDummyImage = #True
#CreateDummyImage = #False

CompilerIf #CreateDummyImage
  
  Procedure CreateDummyPNG()
    Protected filename.s
    CreateImage(0, 120, 25, 32, #Red)
    filename = #PB_Compiler_FilePath + "BoxRed.png"
    SaveImage(0, filename, #PB_ImagePlugin_PNG)
    CreateImage(0, 120, 25, 32, #Green)
    filename = #PB_Compiler_FilePath + "BoxGreen.png"
    SaveImage(0, filename, #PB_ImagePlugin_PNG)
    CreateImage(0, 120, 25, 32, #Blue)
    filename = #PB_Compiler_FilePath + "BoxBlue.png"
    SaveImage(0, filename, #PB_ImagePlugin_PNG)
  EndProcedure
  CreateDummyPNG()
  
CompilerElse
  
  image1 = CatchImage(1, ?BoxRed)
  image2 = CatchImage(2, ?BoxGreen)
  image3 = CatchImage(3, ?BoxBlue)
  
  ShowLibraryViewer("Image")
  CallDebugger
  
  DataSection
    BoxRed:
    IncludeBinary #PB_Compiler_FilePath + "BoxRed.png"
    BoxGreen:
    IncludeBinary #PB_Compiler_FilePath + "BoxGreen.png"
    BoxBlue:
    IncludeBinary #PB_Compiler_FilePath + "BoxRed.png"
  EndDataSection

CompilerEndIf
Edit:
If possible, you should update to v5.73 (extra directory).
This fixes an important bug. Especially with the stability of the IDE. You can also add more compilers here. Or just replace the IDE from v5.70 with v5.73.
If you are still using Ubuntu 16.04, you can install the required "zlib 1.2.9".
Link:https://www.purebasic.fr/english/viewto ... 15&t=77227
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
FourthStone
User
User
Posts: 26
Joined: Mon Dec 11, 2017 8:44 am
Location: Australia

Re: Include Binary Crashing Program

Post by FourthStone »

I've updated the path although it still works with the extra slash so I don't think this is the issue.

I've recreated all the BMP's as PNG's - this worked for 2 days but now the problem is back.

The version I am using is 5.73 LTS and there are no updates available, is there some other version available (extra directory)?

With the delayed loads I'm not sure how to accomplish this, the error is present in the DataSection, when I remove/comment the referenced files from the data section then my program does not crash. It's so strange only 2 files cause this issue among many other files that get loaded and only while using the IDE with no debugger :?

I'll try the compiler workaround so that the images load differently if using the IDE, I still don't understand why it is working for some days and then starts misbehaving again even with completely new files :shock:

Code: Select all

DataSection
; inline toolstrippngs
ToolStripMain:       : IncludeBinary #PB_Compiler_FilePath + "resources/ART_TOOL_Buttons_02.png"
ToolStripMain2:      : IncludeBinary #PB_Compiler_FilePath + "resources/ART_TOOL_Palette_01.png"
  
ToolStripSubDraw:    : IncludeBinary #PB_Compiler_FilePath + "resources/ART_TOOL_Sub_Draw_01.png"
  
; these two files cause the program to crash
;ToolStripSubLine:    : IncludeBinary #PB_Compiler_FilePath + "resources/ART_TOOL_Sub_Line_01.png"
;ToolStripSubBox:     : IncludeBinary #PB_Compiler_FilePath + "resources/ART_TOOL_Sub_Box_01.png"
EndDataSection
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Include Binary Crashing Program

Post by Keya »

FourthStone wrote: Sun May 23, 2021 11:23 pmWhen the files are included my program crashes after 5-10 seconds
By any chance is your app multithreaded, or using a timer?
User avatar
FourthStone
User
User
Posts: 26
Joined: Mon Dec 11, 2017 8:44 am
Location: Australia

Re: Include Binary Crashing Program

Post by FourthStone »

Keya wrote: Wed May 26, 2021 2:30 am
FourthStone wrote: Sun May 23, 2021 11:23 pmWhen the files are included my program crashes after 5-10 seconds
By any chance is your app multithreaded, or using a timer?
Multithreaded no, but timer yes, I thought I disabled the timer at one stage during testing but maybe not... have you had something similar using timers?
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Include Binary Crashing Program

Post by Keya »

no, but to me if your program is crashing after ~5 seconds, I'd be surprised if it's related to IncludeBinary's

Create a basic Hello World program that uses the same IncludeBinary's and see if that still crashes. If it doesn't, that would rule out the images being the problem.

And try disabling your timer(s) in your app and see if it still crashes. If it no longer crashes, that may indicate something related to the timer(s).
User avatar
FourthStone
User
User
Posts: 26
Joined: Mon Dec 11, 2017 8:44 am
Location: Australia

Re: Include Binary Crashing Program

Post by FourthStone »

Good point, I'll create a hello world and go from there.

Couple of side notes / observations:

* This version of my program is updated from an earlier version that has no crashes, I can introduce the crashing issue into the earlier version just by adding the 2 suspect datasection lines as per my code example.

* If I comment out the 2 suspect lines (leaving many other pngs included) then I no longer get the crashing.

This is not conclusive obviously, there could have been a dormant problem present in the earlier version that never presented until my code reached some threshold level for it to trigger the crashes.
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: Include Binary Crashing Program

Post by eck49 »

Probably won't make the problem go away, but to gather evidence, what about
** changing the order of the Include statements. Maybe this would change what "needs" to be commented out.
** likewise moving them somewhere else in the code
** commenting out not the Include lines themselves but the code which refers to the images they contain.


And does introducing a do-nothing delay of > 10 seconds at program start delay the crash or does it happen in the first few seconds regardless?
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
User avatar
FourthStone
User
User
Posts: 26
Joined: Mon Dec 11, 2017 8:44 am
Location: Australia

Re: Include Binary Crashing Program

Post by FourthStone »

Thanks Eck49,

I have changed the order of the includes and commented out the catchimage lines to no avail.

Interestingly I added a 500ms delay before the main loop and the issue goes away.

I've been stripping everything back to basics and now don't think it is the includes, but I still don't know what the actual issue is, it seems if I comment out certain font and text commands the issue disappears... the strangest one is shown below, if I put a comment block after loading fonts then the issue goes away :? if I put a 1 second delay here instead the issue returns... it's really doing my head in.

I don't understand why if I comment out certain text and font commands in blocks of code that aren't even getting called why the problem would go away, it just seems arbitrary that uncalled code could effect execution.

Code: Select all

; load fonts
tFont1=LoadFont(#PB_Any,"Arial",8)
tFont2=LoadFont(#PB_Any,"Comic Sans MS",14,#PB_Font_Italic |#PB_Font_Bold)

; I have no idea why this comment block stops the application from crashing
; If tFont1 And tFont2
;   
; Else
;   MessageRequester(" Error!","Font Load Issue")  
; EndIf
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Include Binary Crashing Program

Post by Saki »

Something is overwritten.
See if you do something with strings that writes over the end of the string.
Switch on the purifier.
Do you do something with pointers or poke?
It always depends on the current memory usage, so this can also work sometimes.
地球上の平和
eck49
Enthusiast
Enthusiast
Posts: 153
Joined: Sat Nov 14, 2020 10:08 pm
Location: England

Re: Include Binary Crashing Program

Post by eck49 »

I think Saki is right, and it doesn't look like an easy one to solve.

The faulty action may cause an immediate crash, or it could be corrupting something which is needed later, when the crash happens.

Q: what happens in the first 5-10 sec?
Q: does the time vary, and if so, why? What is making it different?

You may get somewhere with Debug statements or they may have the same effect as the comment statements you report.
Ditto with temporarily making some arrays far bigger than needed and seeing if the empty space gets written to (desperate!).

Uncalled code still occupies memory, and its presence will affect where in memory the code and data you do call/use sit.
An executable compiled from the still-faulty code may well behave differently from what happens in IDE/Debugger because an executable does not need to know all that the IDE needs to keep a handle on.

As an aside, I remember a program I wrote in a high-level commercial language many years ago which had about 50k lines of code which would only compile if a comment line was present at a certain point in the code; the comment did not have to include any text. There must have been a glitch in the compiler!
Ubuntu 22.04 64-bit
Purebasic 6.00 (as of 5 Sep 2022)
(native tongue: English)
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: Include Binary Crashing Program

Post by Saki »

Hi, I do quite a lot with strings.
To speed up also with CopyMemory(), Poke() and pointers.
But then you make errors very fast.
Even small overwrites of the string end can trigger these effects.
When a string end is overwritten it usually takes about 5 seconds before it pops, but before that it already freeze.
The purifier does not always show this reliably, but it can be very helpful.
The other way round I had the case that the code with switched on
Purifier runs, but no longer when it is switched off.
I keep it now in such a way that I have the Purifier always off and only cyclically test whether he finds something.
Similar it behaves then also with the debugger.
It is bad, if it runs with debugger but without no more.

It is also not excluded that it is a procedure parameter,
a float as the last parameter can trigger the current, 573, it overwrites other parameters, but on windows this should work.
地球上の平和
BarryG
Addict
Addict
Posts: 3322
Joined: Thu Apr 18, 2019 8:17 am

Re: Include Binary Crashing Program

Post by BarryG »

FourthStone wrote: Wed May 26, 2021 11:14 pmInterestingly I added a 500ms delay before the main loop and the issue goes away.
I had a similar issue once. Turns out some of my gadget events in the main loop were trying to access images before they were assigned to the gadget. I fixed it by creating a global variable called "appstarted" and only set it 1 once all gadgets were created and ready. So my code looked like this:

Code: Select all

Global appstarted

; Create gadgets from images here

appstarted=1

; Main loop

Repeat
  If appstarted
    Event = WaitWindowEvent()
    If Event = [...]
  EndIf
Until quit
User avatar
FourthStone
User
User
Posts: 26
Joined: Mon Dec 11, 2017 8:44 am
Location: Australia

Re: Include Binary Crashing Program

Post by FourthStone »

I keep running in to issues with respect to this project, I'm starting to think it is PC related.

The latest issue is I'm getting Polink errors, fatal error access denied... Comment out 2 specific resource files, no issue... copy the entire project to another PC unchanged, no issues... anyone seen this? Could it be permission related, drive failing issues, file specific issues? I just don't know... strange thing is previous versions of the project work fine (sans the new resource PNGs).
Post Reply