Glide Radio buttons generate object disposed error

I have 2 radio buttons on a form and when I load the form and then create the window.

Definition at the top of the class.


static RadioButton Gauge1RadioButton;
static RadioButton Gauge2RadioButton;

Then this code creates the window and tries to set the checked state of one of them depending on the settings.


CurrentWindow = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.optionsWindow));

Gauge1RadioButton = (RadioButton)CurrentWindow.GetChildByName("Gauge1RadioButton");
Gauge2RadioButton = (RadioButton)CurrentWindow.GetChildByName("Gauge2RadioButton");

if (isDualType())
     Gauge1RadioButton.Checked = true;
else
     Gauge2RadioButton.Checked = true;

It fails at the setting of the checked state. Both Radio Buttons have the same group name.

This is the exception

#### Exception System.ObjectDisposedException - CLR_E_OBJECT_DISPOSED (3) ####
#### Message: 
#### Microsoft.SPOT.Bitmap:: DrawImage [IP: 0000] ####
#### Microsoft.SPOT.Bitmap:: DrawImage [IP: 0014] ####
#### GHI.Glide.Glide::Flush [IP: 0024] ####
#### GHI.Glide.Glide::Flush [IP: 0023] ####
#### GHI.Glide.Display.DisplayObject::Invalidate [IP: 0008] ####
#### AX9100DG.Program::InitOptionsWin [IP: 0075] ####

I get this every time I try to do this.

OK. I decided to use the Glide source and this allowed me to dig into the code.

It seems that you cannot set the check state until Glide.Mainwindow is actually set. Once I moved the code that sets the checked state out to the setup function and put it after Glide.Mainwindow = CurrentWindow then everything works fine.

It seems that the call to Check causes the Glide driver to try and flush the image and because the Window is not yet created, it throws the exception.

Hope this helps anyone else who comes across this issue?

1 Like

@ Dave McLaughlin -

It is always nice to see how a problem was solved.