الشبكة العربية لمطوري الألعاب

  Jawad Abu Zakhem مشاركة 1

Hello,

I always hoped that the crashes that happen in my program, are because of bugs in the compiler, or in the libraries I use, and not because of my code...

Yesterday my wish came true:
1- Start a windows application project, using any .NET laguage.

2- call the function:
   Application.EnableVisualStyles(); 

in the beginning of the main function, this function will allow the windows in your projects to have windows XP style.

3- Add a ComboBox to the main form...(combobox1)

4- Add an event handler for the ComboBox:
  cmbobox1_SelectionChangeCommitted. 

5- inside this event handler, wirte the code of showing a form:
  Form frm = new Form();
           frm.ShowDialog();

6- try to run the project, and change the selection of your combobox, then trying to close the new form.... BANG:
 An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in system.windows.forms.dll 


Solution:
To avoid this, and if you really need to show a form in a selection changed event handler in Combobox:
1- create a function that calls frm.ShowDialog, or frm.Show.
2- create a delegate that can take this new function.
3- call the delegate using (BeginInvoke).

sample in c#:
 delegate void ComboDelegate();

void ComboSelectionAsync()
{
// calling the Show function goes in here
}

private void combobox1_SelectionChangeCommitted(object sender, System.EventArgs e)
{
      ComboDelegate d = new ComboDelegate(ComboSelectionAsync);
      combobox1.BeginInvoke(d);
}

hope you don't spend three hours trying to solve this, as it happend with me..

محترف مشرف عبد اللطيف حاجي علي مشاركة 2

Assured,
But strangely enough, if you call any other common dialog (Like OpenFileDialog, ColorChooser or even a simple MessageBox), every thing seems to work fine, so they must be doing something that we're missing; I'll look into it

Wanna hear something funnier (since you like to blame the compilers, althougth this one about unmanaged C++ compiler), try compiling the folowing code in Release mode (i.e. with the optimizations turned on); and see if it even gives logical results (for entries like 10 then 5):
// Some includes that I can't write explicitly, because of the site security issues...
using namespace std;

int main()
{
	int iInt1=0;
	int iInt2=0;

	cin >> iInt1 >> iInt2;

	bool bBool1 = false;
	bool bBool2 = false;
	//cout << iInt1 << endl << iInt2 << endl;

	if (iInt1 != iInt2)
	{
		bBool2 = iInt2 < iInt1;
		bBool1 = iInt1 < iInt2;
	}

	cout << "The smaller number is" << endl;

	if (bBool1)
		cout << iInt1;
	else if (bBool2)
		cout << iInt2;
	else
		cout << "neither" << endl;

	return 0;
}


Long time no see,

عبد اللطيف حاجي علي
مبرمج
In|Framez

  Jawad Abu Zakhem مشاركة 3

Hello Abdo,

it's very wierd bug, I couldn't figure what's the problem of the compiled code???
maybe it has something to do with compiling the operator (<) in the release mode...


it's nice to contact you again...

Jawad Abu Zakhem.

خبير مدير وسام البهنسي مشاركة 4

التعليق على مشاركة Abdo Haji-Ali في Dec 5, 2005 20:58 :

> // Some includes that I can't write explicitly, because of the site security issues...

الآن يمكنك إدراج code يحوي أية محارف بدون قيود تقريباً...

وسام البهنسي
مبرمج في إنفيديا وإنفريمز