freebasic / fbc

FreeBASIC is a completely free, open-source, multi-platform BASIC compiler, with syntax similar to MS-QuickBASIC, that adds new features such as pointers, object orientation, unsigned data types, inline assembly, and many others.
https://www.freebasic.net
905 stars 139 forks source link

SIGSEGV when using sleep in DOSBox #198

Open wesleywerner opened 4 years ago

wesleywerner commented 4 years ago

VERSION: 1.07.1 DOS (32-bit) ENVIRONMENT: DOSBox 0.74 (default DOS configuration)

Test program:

print "before sleep"
sleep 250
print "after sleep"

This issue is dependant on the CPU speed configured in DOSBox. When running at the default 3000 cycles the exception is thrown. When dropping the cycles to 300 the problem disappears. I cannot speculate why this happens, reporting it regardless for visibility's sake.

running at 3000 cycles screenshot 003521

running at 300 cycles screenshot 003522

MyTDT-Mysoft commented 4 years ago

it happens while checking for keypress part of sleep... if you use sleep 250,1 it will work, but yes nasty bug that been there for a while now

jayrm commented 1 year ago

Something different to try in fbc 1.10.0. It is kind of like using sleep 250,1, but key presses are still checked.

extern "c"
        extern as unsigned long __fb_dos_no_dpmi_yield
end extern

'' tell SLEEP to call usleep_private() which does not yeild to dpmi
'' this prevents djgpp c runtime from calling __dmpi_yeild() during a
'' call in SLEEP.  Disabling this yeild behaviour appears to prevent
'' the program from crashing in some DOS extenders.

__fb_dos_no_dpmi_yield = 1

print "before sleep"
sleep 250
print "after sleep"

No doubt there are still bugs, but this allowed me to debug some fb DOS programs that would otherwise just crash.