D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3442 - scope(exit) Problem
Summary: scope(exit) Problem
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-26 04:00 UTC by Vermi
Modified: 2015-06-09 01:26 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vermi 2009-10-26 04:00:32 UTC
I don't know if it's really a dmd bug or it's a windows bug, because I made several tests and I don't really understand where is the error. Here is the code : (Working with earlier version of dmd (2.022 if I remember well) :

protected bool _onPaint(PAINTSTRUCT paintStr)
{
  int oldMode = SetBkMode(paintStr.hdc, TRANSPARENT);
  scope(exit)
  {
    SetBkMode(paintStr.hdc, oldMode);
    MessageBoxA(null, "tic", "tic", MB_OK);
  }

  // Some code

  return true;
}


If the function return without exception, the code in the scope statement is properly executed and functionnal, the Background Mode for the DC is restored to OPAQUE (it's original value).

If an exception is thrown ( with the code : (cast(Object)null).toString() for example ), The MessageBox show, but the background mode the DC is not restored, and the background simply disapear in the window.

I made some tests on the return value of SetBkMode :

If an exception is thrown, SetBkMode return OPAQUE (wich is strange, it should return TRANSPARENT according to msdn).

If no exception is thrown, SetBkMode return 0, wich is strange too, because 0 means error. I don't know what to think.
Comment 1 Don 2009-10-30 05:37:35 UTC
Please attach a complete test case. It sounds like bug 1894 to me (see also bug 1087).
Comment 2 Don 2009-12-29 22:12:51 UTC
I'm closing this as invalid since it has no test case. But it is probably a duplicate of one of the bugs I mentioned. Reopen if you have a complete test case.