24-07-2008 15:29:46

I've searched the forum and noticed some other people talking about problems with this function too, but none of them ever seemed to be resolved.

Every time I try to call addEventHandler my application crashes with "test.exe has triggered a breakpoint" in the m_deallocator function of the MMGR.

Here is my code (I know this probably doesn't help and I also know this code isn't very defensive, but it is for illustrative purposes):

QuickGUI::Sheet *sheet = gui->getDefaultSheet();
QuickGUI::Button *button = sheet->createButton();

The call stack looks pretty much the same as what everyone else in the past has complained about so I'm guessing it is the same issue.

test.exe!m_deallocator(const char * sourceFile=0x00433fa8, const unsigned int sourceLine=0, const char * sourceFunc=0x00433fa8, const unsigned int deallocationType=6, const void * reportedAddress=0x033ca0d8) Line 1451 + 0xd bytes C++
test.exe!operator delete(void * reportedAddress=0x033ca0d8) Line 1009 + 0x25 bytes C++
test.exe!std::allocator<QuickGUI::MemberFunctionSlot *>::deallocate(QuickGUI::MemberFunctionSlot * * _Ptr=0x033ca0d8, unsigned int __formal=1) Line 141 + 0x9 bytes C++
test.exe!std::vector<QuickGUI::MemberFunctionSlot *,std::allocator<QuickGUI::MemberFunctionSlot *> >::_Insert_n(std::_Vector_iterator<QuickGUI::MemberFunctionSlot *,std::allocator<QuickGUI::MemberFunctionSlot *> > _Where=0xfdfdfdfd, unsigned int _Count=2, QuickGUI::MemberFunctionSlot * const & _Val=0x033caab0) Line 1160 C++
test.exe!std::vector<QuickGUI::MemberFunctionSlot *,std::allocator<QuickGUI::MemberFunctionSlot *> >::insert(std::_Vector_iterator<QuickGUI::MemberFunctionSlot *,std::allocator<QuickGUI::MemberFunctionSlot *> > _Where=0xfdfdfdfd, QuickGUI::MemberFunctionSlot * const & _Val=0x033caab0) Line 855 C++
test.exe!std::vector<QuickGUI::MemberFunctionSlot *,std::allocator<QuickGUI::MemberFunctionSlot *> >::push_back(QuickGUI::MemberFunctionSlot * const & _Val=0x033caab0) Line 800 + 0x2d bytes C++
test.exe!QuickGUI::Widget::addEventHandler<TestApp>(QuickGUI::Widget::Event EVENT=EVENT_MOUSE_BUTTON_UP, void (const QuickGUI::EventArgs &)* function=0x00411be5, TestApp* obj=0x025a97c0) Line 162 C++
test.exe!TestApp::Run() Line 201 C++
test.exe!WinMain(HINSTANCE__ * hInst=0x00400000, HINSTANCE__ * __formal=0x00000000, char * strCmdLine=0x001e3733, HINSTANCE__ * __formal=0x00000000) Line 18 C++
test.exe!__tmainCRTStartup() Line 589 + 0x35 bytes C
test.exe!WinMainCRTStartup() Line 414 C
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]

I have basically stripped my application down to a bare basic shell believing that something was corrupting the heap, but no dice. In fact, I can take a copy of the most basic ogre initialisation code using the ExampleListener and drop QuickGUI in with nothing but a single button and the problem still happens so there is no way something can be corrupting the heap.

I've triple checked all my initialization code to make sure everything looks the same as the tutorials and the demo app (while I'm on that topic, I can't even run the demo app... it too just crashes unexplainably, probably for the same reason).

After seeing other people having the same issue, I'm starting to think that there is a problem with QuickGUI. If there is heap corruption going on, then it maybe QuickGUI that is doing it. I can run 1000's of lines of code in my application without ever noticing any so called "heap corruption" issues until I call addEventHandler.


24-07-2008 16:15:06

Can you throw up a link, or PM me a link to the code you use? I don't believe the corruption is caused on QuickGUI's side, there have been maybe 3 people with this issue, which I think is a small number of people, compared to the number who have run the demo and use the lib in their app. Maybe its some kind of compatibility problem? What IDE and OS are you running on? Either way, an Event Handler is just a function pointer. If I am able to repro the problem I can go about fixing it.

Are you able to debug this? Adding a break point to the line where you add the event handler and stepping through would reveal more information. It looks as if the application is crashing when trying to store the MemberFunctionPointer, the iterator address is _Where=0xfdfdfdfd. Doesn't look like a valid memory address, which suggests corruption of the vector. Something is overwriting the vector data in memory.


25-07-2008 00:51:44

I agree. I think it is going to be some isolated issue that only occurs under very certain circumstances. I'm just wondering, might it have something to do with how QuickGUI is compiled. I downloaded the 0.9.7 package, opened the workspace in Visual Studio 2005 (under Vista) and hit compile without doing anything else. So I'm just wondering is that what I'm supposed to be doing?

ATM I'm using QuickGUI as a DLL so it won't let me step into the code. But if I add all the code to my project and compile it with my project, then I will be able to step into it. So I might give that a try.

Do you have a pre-compiled binary package of the demo (with all media and dependencies) that you know runs? Then I can download that and test it on my machine and see if it crashes. That way we know whether it is a QuickGUI issue or an issue with my machine or compilation of the demo.

In addition, do you have a compiled binary of QuickGUI against the latest Ogre v1.4.9 (i.e. dll and lib) that I can drop into my project and test with? If it works with yours, then perhaps it is a problem with the way some people (me included) are compiling QuickGUI.


25-07-2008 01:34:53

Odd, I think you should be able to step into the code. Maybe you need to put the .pdb in the working directory. Assuming QuickGUI was built from source on the same machine, it should allow stepping in.

I've been working with Ogre SVN for latest developments, but I can try and build a binary version using 0.9.7 with the last Ogre 1.4.9. I'm on xp using VS2k5, but I can test the exe on my vista tower.


25-07-2008 07:05:56

I'm not sure why but I wasn't able to get the 0.9.7 demo working with the short amount of time I had. It came down to some inconsistency between my OIS libs and dlls, and I didn't want to blow away everything to get a 0.9.7 demo working on Ogre 1.4.9.

Here is a link to the latest demo, its the test app I use for the current qgui developments:

If you are able to run this, and able to close the window, event handlers work fine. (The titlebar creates a handler which closes the window when its clicked)


25-07-2008 18:53:09

I just tried out my demo on my workstation using Vista and it fails to load. I wasn't able to run it on my tower at home because I don't have vs2k5 installed on it. I guess I should have built it in release mode. I know it works on my xp laptop at least, but that doesn't help too much.


27-07-2008 00:52:03

Hmm... the demo failed with a missing DLL error. MSVCP80D.DLL

Not sure why this is being caused since I have VS2005 installed and a quick Google search turned up nothing.

If the demo is failing on your machine (for another reason) it may very well be the addEventHandler, but you'd need to run it in the IDE to find out.

As soon as I have some spare time, I'm going to try to put together the smallest app possible that demonstrates the problem.


28-07-2008 08:29:29

I updated the link above, having built the demo in release mode. Its still not running on my vista machine. Not sure what I need to do to make the demo portable to vista...

Other option would be to build it on my vista machine, but my laptop is more powerful. You don't have any xp machines to test the demo on?


28-07-2008 12:59:10

Still no good on my Vista machine, different error though this time. I do have an XP machine and I will test it on that later and post my results.


29-07-2008 10:17:00

OK, tested on both my XP machine and Vista machine and receive the same Runtime Error on both, which says that the application has made an attempt to load the C runtime library incorrectly. This is the followed by a second message informing me that the application failed to initialize properly.

Obviously these errors are very generic and could mean anything, but I'm assuming you don't see these errors when running through the IDE, right? If not, it is a little odd.


29-07-2008 16:09:38

I'm able to run the demo fine on my machine. One thing that may have contributed was the fact that I didn't embed the manifest. I included the manifest in the zip, but it still doesn't run on Vista. I wish the error messages were a little more intuitive.

Tonight I'll start moving files from my bin folder to some random folder to see what exactly I need on my xp machine to run. Everything needed should be in that folder or the system32 folder. Sorry to be tossing this back and forth so much. Are you on Vista 32 bit?


30-07-2008 01:46:42

Just to update, I had some friends successfully run the demo now that I put the manifest in there. Its working in win xp, give it a shot. :)


30-07-2008 15:28:43

I don't mind going back and forth. I want to get it working so I can actually use QuickGUI in one of my projects.

I'm running on Vista 32 bit and still no dice with the updated demo. I won't have access to my XP machine until Friday to test on, so I'll try it on there then.

Do you happen to have a small project that just does the bare basics (i.e. starts up Ogre and QuickGUI and sets up a single button for example) that you are able to compile and run without any complaints from addEventHandler? If so, can you upload a zip of the solution and files. I'd like to compare it against mine as perhaps I have just done something wrong in set up or I have an incorrect project setting.


01-08-2008 18:16:27

The demo works on my vista box, I had to install service pack 1. I can also confirm the demo ran on my nephew's vista machine. Its run successfully on 5 other xp boxes, and everybody was able to close the window. Do you have sp1 installed?


13-08-2008 05:13:41

Yes I have SP1 on my Vista machine. Have tried on three vista machines and an XP machine and the demo doesn't work on any of them.

Anyway, just putting that aside for now and going back to the original problem. I think I have narrowed it down some more. I did some more testing on this by including QuickGUI in one of the sample projects included with Ogre. When I tested it, everything ran fine and it didn't crash at the addEventHandler line. So I went through comparing everything between the sample project and my project (including compiler settings) and found that my project is using the MMGR while the Ogre sample projects are not.

It appears as though there is a memory corruption issue with QuickGUI that is only exposed by MMGR. You can try this for yourself by adding MMGR to your project (i.e. add the header and library file). I'll be very surprised if you do not receive the crash at the addEventHandler line when using MMGR.


13-08-2008 16:03:56

So odd that it doesn't work on any of the machines you've tried. :(

How do I turn on the MMGR? (Memory Manager?) Is this a Visual Studio setting or other?


15-08-2008 02:31:51

MMGR is a memory manager written by Paul Nettle and is considered to be infallible at catching memory leaks and memory corruption issues. Basically whenever it tells you there is a memory leak or corruption... it is never wrong.

Ogre uses it, however it is disabled by default. To enable it, you just need to include the paths to the MMGR header files and library file and include MMGR as an additional library file.

You will need to download and compile it first however. Here is the link.

An easy way to test if it is running is to create a memory leak, such as:
int *test = new int[10];
If MMGR is working, after you execute the code (without deleteing the array or course) you will have a memleaks.txt file in the working directory showing the memory leak.

Then when you run QuickGUI and make a call to addEventHandler you will hit an assert informing you that you are tampering with memory that you did not allocate.


15-08-2008 18:04:29

I will try to get to this sometime on the weekend, although I'm pushing to put out a demo, as preparation for a release.

Could it be the case that the MMGR does not regonize function pointers correctly? I do allocate space for the MemberFunctionPtr class, but its just a very simple class that stores the address of a member function pointer, for easy execution of the function at a later time. There really isn't any room for error in the way its designed, in fact its the same way CEGUI does its event handlers. (I got the design from them :) )


17-08-2008 13:35:43

I'm no expert on this, but after further investigation it appears as though MMGR is complaining because the memory for MemberFunctionPtr is allocated from within an external DLL. Apparently this kind of thing has been a problem for the Ogre developers too, so they solved it by canning MMGR. Not really the best solution... but what can you do :roll:

Sinbad did say in one post (forget where now) that it can work. It just requires some reordering of the included headers. It's all getting too complicated and I'd prefer to be working on my game, so I've decided to disable MMGR for now. If anyone has any suggestions on memory leak detection, I'm all ears.


17-08-2008 18:50:07

I think Sinbad implemented custom memory trackers for 1.6 so you could just use that


18-08-2008 01:25:28

OK thanks for your suggestion. I'm very new to Ogre so I'll have to dig around to see if I can find that.