M
Marcus Kwok
I have been staring at this code and I cannot see what is wrong with it.
I am getting a NullReferenceException when trying to pass a value struct
to a method. This exception only happens in Release mode; Debug mode
runs fine. When I use the Debugger on Release mode, the debugger shows
valid values for "contour", but I still get this exception. If anybody
has any input at all, it would be much appreciated.
---------------------------
System.NullReferenceException: Object reference not set to an instance of an object.
at FSBSGui2.ControlPanel.write_contours_file(Contours& contours)
at FSBSGui2.ControlPanel.button_run_Click(Object sender, EventArgs e)
---------------------------
System::Void button_run_Click(System::Object * sender, System::EventArgs * e)
{
using System::Text::StringBuilder;
using System::Threading::Thread;
using System::Threading::ThreadStart;
using System::Windows::Forms::Button;
using System::Windows::Forms:ialogResult;
using System::Windows::Forms::MessageBox;
using System::Windows::Forms::MessageBoxButtons;
using System::Windows::Forms::MessageBoxIcon;
Button* button = __try_cast<Button*>(sender);
if (button->Text->Equals(S"&Cancel")) {
button_cancel_Click(sender, e);
return;
}
fill_FSBSParameters();
ContoursDialog::Contours contours; // HERE I INSTANTIATE
switch (run_type) {
case Xmtr_Avl:
contours = xmtr_avail_contours;
break;
case Fer:
contours = fer_contours;
break;
case Pcmr:
contours = pcmr_contours;
break;
default:
break;
}
VerificationDialog* vd = new VerificationDialog(*params, contours);
if (vd->ShowDialog() == DialogResult::OK) {
try {
write_contours_file(contours); // HERE I CALL
}
catch (System::NullReferenceException* e) {
System::Windows::Forms::MessageBox::Show(e->ToString());
}
}
}
// Here is the prototype for write_contours_file()
// I notice that the 'const' has been dropped in the stack trace above
System::Void write_contours_file(const ContoursDialog::Contours& contours);
// Here is the definition of ContoursDialog::Contours
__value struct Contours {
int num_contours;
__value struct ContourInfo {
double lower_bound;
int r;
int g;
int b;
};
ContourInfo contours[];
Contours()
: contours(new ContourInfo[max_contours])
{ }
};
I am getting a NullReferenceException when trying to pass a value struct
to a method. This exception only happens in Release mode; Debug mode
runs fine. When I use the Debugger on Release mode, the debugger shows
valid values for "contour", but I still get this exception. If anybody
has any input at all, it would be much appreciated.
---------------------------
System.NullReferenceException: Object reference not set to an instance of an object.
at FSBSGui2.ControlPanel.write_contours_file(Contours& contours)
at FSBSGui2.ControlPanel.button_run_Click(Object sender, EventArgs e)
---------------------------
System::Void button_run_Click(System::Object * sender, System::EventArgs * e)
{
using System::Text::StringBuilder;
using System::Threading::Thread;
using System::Threading::ThreadStart;
using System::Windows::Forms::Button;
using System::Windows::Forms:ialogResult;
using System::Windows::Forms::MessageBox;
using System::Windows::Forms::MessageBoxButtons;
using System::Windows::Forms::MessageBoxIcon;
Button* button = __try_cast<Button*>(sender);
if (button->Text->Equals(S"&Cancel")) {
button_cancel_Click(sender, e);
return;
}
fill_FSBSParameters();
ContoursDialog::Contours contours; // HERE I INSTANTIATE
switch (run_type) {
case Xmtr_Avl:
contours = xmtr_avail_contours;
break;
case Fer:
contours = fer_contours;
break;
case Pcmr:
contours = pcmr_contours;
break;
default:
break;
}
VerificationDialog* vd = new VerificationDialog(*params, contours);
if (vd->ShowDialog() == DialogResult::OK) {
try {
write_contours_file(contours); // HERE I CALL
}
catch (System::NullReferenceException* e) {
System::Windows::Forms::MessageBox::Show(e->ToString());
}
}
}
// Here is the prototype for write_contours_file()
// I notice that the 'const' has been dropped in the stack trace above
System::Void write_contours_file(const ContoursDialog::Contours& contours);
// Here is the definition of ContoursDialog::Contours
__value struct Contours {
int num_contours;
__value struct ContourInfo {
double lower_bound;
int r;
int g;
int b;
};
ContourInfo contours[];
Contours()
: contours(new ContourInfo[max_contours])
{ }
};