www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - The program exits unexpectedly

reply unDEFER <undefer gmail.com> writes:
Hello!
I'm starting port my program to Windows _without_ Cygwin and 
found big trouble.
My main thread exits unexpectedly without any diagnostic 
messages. The second thread still lives when it happens.
The visual studio debugger say that thread exits with code 2.
What it maybe?
Dec 09 2016
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 09/12/2016 10:26 PM, unDEFER wrote:
 Hello!
 I'm starting port my program to Windows _without_ Cygwin and found big
 trouble.
 My main thread exits unexpectedly without any diagnostic messages. The
 second thread still lives when it happens.
 The visual studio debugger say that thread exits with code 2.
 What it maybe?
An exception/error might be thrown, try catching Error's in the threads function. Also try adding an infinite loop to it.
Dec 09 2016
parent reply unDEFER <undefer gmail.com> writes:
On Friday, 9 December 2016 at 09:29:36 UTC, rikki cattermole 
wrote:
 On 09/12/2016 10:26 PM, unDEFER wrote:
 An exception/error might be thrown, try catching Error's in the 
 threads function.
 Also try adding an infinite loop to it.
Exceptions works good, and prints debug message always. It is not exception.. I have tried to add try/catch around full loop of the program. It doesn't work. And program has infinite loop. But maybe it is unhandled signal?
Dec 09 2016
parent reply unDEFER <undefer gmail.com> writes:
On Friday, 9 December 2016 at 09:42:52 UTC, unDEFER wrote:
 Exceptions works good, and prints debug message always. It is 
 not exception..
 I have tried to add try/catch around full loop of the program. 
 It doesn't work. And program has infinite loop.
 But maybe it is unhandled signal?
I have found. It exits on "stdout.flush()"
Dec 09 2016
parent unDEFER <undefer gmail.com> writes:
On Friday, 9 December 2016 at 10:08:24 UTC, unDEFER wrote:
 On Friday, 9 December 2016 at 09:42:52 UTC, unDEFER wrote:
 Exceptions works good, and prints debug message always. It is 
 not exception..
 I have tried to add try/catch around full loop of the program. 
 It doesn't work. And program has infinite loop.
 But maybe it is unhandled signal?
I have found. It exits on "stdout.flush()"
Without flush falls in different places.. And in the console leaves not fully printed lines.
Dec 09 2016
prev sibling parent reply unDEFER <undefer gmail.com> writes:
I'm afraid that the problem that my program wants to say 
something, but there is no "flush" so message leaves in the 
buffer.
Dec 09 2016
parent reply unDEFER <undefer gmail.com> writes:
On Friday, 9 December 2016 at 14:29:38 UTC, unDEFER wrote:
 I'm afraid that the problem that my program wants to say 
 something, but there is no "flush" so message leaves in the 
 buffer.
I have found, it was code like: string path = "C:"; string parent = path[0..path.lastIndexOf("\\")]; And in mini program it works and shows diagnostic message. Where my diagnostic message in more complicate program???
Dec 09 2016
next sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 12/09/2016 08:50 AM, unDEFER wrote:
 On Friday, 9 December 2016 at 14:29:38 UTC, unDEFER wrote:
 I'm afraid that the problem that my program wants to say something,
 but there is no "flush" so message leaves in the buffer.
I have found, it was code like: string path = "C:"; string parent = path[0..path.lastIndexOf("\\")];
That's a bug because you're not checking the return value of lastIndexOf. According to its documentation, lastIndexOf returns -1 if it fails to find the needle: ptrdiff_t found = path.lastIndexOf("\\"); if (found == -1) { // Not found } else { // Now we can use it: string parent = path[0..path.lastIndexOf("\\")]; // ... } The added complication is the fact that ptrdiff_t can be converted to size_t and you get a huge string when doing path[0..path.lastIndexOf("\\")] Do you have boundschecking turned off? It should catch such an error.
 And in mini program it works and shows diagnostic message.
 Where my diagnostic message in more complicate program???
Assuming boundschecking is turned off, I think you get unlucky in the mini program and happen to hit a '\0' byte. Ali
Dec 09 2016
parent unDEFER <undefer gmail.com> writes:
On Friday, 9 December 2016 at 20:35:07 UTC, Ali Çehreli wrote:

 Assuming boundschecking is turned off, I think you get unlucky 
 in the mini program and happen to hit a '\0' byte.
No, no.. the program built in debug mode with dub.
Dec 09 2016
prev sibling parent reply Martin Krejcirik <mk-junk i-line.cz> writes:
On Friday, 9 December 2016 at 16:50:05 UTC, unDEFER wrote:
 And in mini program it works and shows diagnostic message.
 Where my diagnostic message in more complicate program???
Try redirecting stdout and stderr to a file(s). There are cases when the console itself can crash.
Dec 09 2016
parent unDEFER <undefer gmail.com> writes:
On Friday, 9 December 2016 at 21:20:12 UTC, Martin Krejcirik 
wrote:
 On Friday, 9 December 2016 at 16:50:05 UTC, unDEFER wrote:
 And in mini program it works and shows diagnostic message.
 Where my diagnostic message in more complicate program???
Try redirecting stdout and stderr to a file(s). There are cases when the console itself can crash.
OK, thank you. Next time with other crashes I will try.
Dec 09 2016