1

I have the following function that is meant to close a panel:

def close_active_panel
  if (@active_panel and @active_panel.class <= Wx::Window)
    @sizer.detach(@active_panel)
    @sizer.remove(0) # 0 is index of first and only item, the active panel
    @active_panel.destroy_children
    @active_panel.destroy
  end
end

This works most of the time, but occasionally (I can't seem to find a pattern with when this happens), it will raise the following exception:

ArgumentError
Wrong arguments for overloaded method 'wxSizer.Detach'. Possible C/C++ prototypes are: bool wxSizer.Detach(wxWindow *window) bool wxSizer.Detach(wxSizer *sizer) bool wxSizer.Detach(size_t index)

It seems strange that this is happening because the only way it should even get to the detach method is if active_panel inherits from the Wx::Window class.

Is there some sort of inheritance trick I am missing here? I have tried outputting the class of the active panel and its parents to ensure it is indeed inheriting from Wx::Window, and the issue persists. Any help would be greatly appreciated.

sschilli
  • 2,021
  • 1
  • 13
  • 33
  • Can you isolate the problem with some sort of test? I'd also say to take a look at concurrency issues, it may be that the method is being called more than once and between your check and @size.detach(@activep_panel) another function has called @active_panel.destroy. – Zachary Moshansky Jun 25 '15 at 22:38
  • Thanks for the comment. I will look at potential concurrency issues, but I am not sure whether that would be the issue. I have omitted the exception handling part of my code, but it displays a message box with the class of the active panel object, then displays a custom error message box that gave me the exception quoted above. Everything checks out the line before the error message, could that still be susceptible to a concurrency issue? – sschilli Jun 25 '15 at 22:46
  • It's really tough to say without having the whole application. The most help would be to reproduce this consistently. For example, click the close button that calls on "close_active_panel" multiple times in quick succession to see if you can reliably reproduce the issue. – Zachary Moshansky Jun 25 '15 at 22:56
  • Alright, thanks for the tip. Say I can reliably fix it and I find out it is a concurrency issue. Is there any way to stop the function from being called multiple times before it has completed? – sschilli Jun 25 '15 at 22:58
  • http://ruby-doc.org/stdlib-2.1.2/libdoc/monitor/rdoc/Monitor.html should work, although I'm not intimately familiar. Otherwise, investigate Mutexes. – Zachary Moshansky Jun 26 '15 at 02:29

0 Answers0