Author Topic: CodeBlocks program built with CB 10.05 and wxSmith will not close.  (Read 4398 times)

Offline Grouch

  • Multiple posting newcomer
  • *
  • Posts: 40
Using Code::Blocks 10.05 on Ubuntu 10.10, I build and run the wxSmith example just as it is provided by clicking the "new project" URL.
As far as I understand, there are three alternative ways to build and run a program:
(1) In the main menu, click Build | Build and run
(2) Tap F9
(3) Click the "gear and triangle" icon for which the tool tip is "Build and run"

Methods (2) and (3) produce a program that behaves as expected. But method (1) -- which was the first I tried -- produces a program which refuses to close. Not only does the function coded into the program fail to close it, but clicking on the x in the upper left corner of the frame fails to close it. It will minimize or maximize or stretch, but it will not close. I have found no way to get rid of it save to reboot. Obviously, I can use only methods (2) and (3), but it doesn't build confidence that method (1) produces such an ill-behaved rascal. Any explanation or advice?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: CodeBlocks program built with CB 10.05 and wxSmith will not close.
« Reply #1 on: April 24, 2011, 09:33:44 am »
All three methods work fine here and do exactly the same (they call the same function to build and run a project).

You do not need to reboot to close a program that can not be stopped (for whatever reason).
The easiest way is to open a console and type killall [name_of_the_executable], if that's not enough than try killall -9 [name_of_the_executable].

Or use taskmanager to kill the program, which one to use depnds on your installation and it's your turn to find one.

If your exe can not be closed, it's most likely an error in your code.

Offline Grouch

  • Multiple posting newcomer
  • *
  • Posts: 40
Re: CodeBlocks program built with CB 10.05 and wxSmith will not close.
« Reply #2 on: April 27, 2011, 12:40:46 am »
Thanks, Jens, for your prompt reply. As I mentioned, I was running EXACTLY the code that came from the CodeBlocks site when I clicked on "Create a new project" and selected a wxSlmith application. (Further experiments showed that F9 and the "Build and run" icon also usually built programs that would not close.)  It did not occur to me that there was an error in this tiny bit of code which many people must have run.

But there is. At the very end, you will find the lines:

void helloFrame::OnClose(wxCloseEvent& event)
{
}

I realized that those lines looked like a close function that did not close, so I changed them to:

void helloFrame::OnClose(wxCloseEvent& event)
{
    Close();
}

and now everything works well no matter how the "Build and run" is done. What I do not understand is why occasionally a build would would work properly, but I can proceed without understanding that. 

I do hope you will want to add that line of code to save others the hours of frustration and perplexity its absence has cost me.

Thanks also for assigning me the exercise of finding out how to use the system monitor on Ubuntu 10.10 to kill a process. The answer is: Click "System" on the top bar; then "Administration", and then "System monitor". Spot the process, in this case "hello" in the long list of processes, put the cursor on it, and click the "End Process" box on the lower right.





Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: CodeBlocks program built with CB 10.05 and wxSmith will not close.
« Reply #3 on: April 27, 2011, 07:08:22 pm »
In my installation C::B does not build an OnClose-event-handler automatically.
But if you double-click the empty item, and the first event in the list has no event-handler, one will be created.
For wxFrame the first event is the EVT_CLOSE.

I guess you (accidently) double-clicked the frame and the event-handler was created.