How can I find missing glPopMatrix in Visual Studio

0

I have a theory according to which the bugs I'm experiencing are due to a glPushMatrix being used without a matching glPopMatrix. My project is rather big so I would like to be able to find these missing glPopMatrix() easily. I thought of using a search using regular expression, but I can't seem to find out how to find what I want (plus, regexp in visual studio isn't exactly the same as what I'm used to (php) so I'm a bit lost. Anyways, any ideas on how to do this?

edit: I'm using C++

Shawn

Posted 2010-12-02T20:57:30.750

Reputation: 1 219

1Shouldn't this be on StackOverflow? – ale – 2010-12-02T21:40:49.103

@Al Everett Don't know, it concerns the use of Visual Studio.. – Shawn – 2010-12-03T01:27:01.513

Answers

0

It might be simpler to modify the code to do the check for you.

Create new versions of glPushMatrix and glPopMatrix that set and unset a flag. Then if your new glPushMatrix gets called with the flag still set you know you've found the call after your culprit.

With suitable logging of call stacks etc. you should be able to find the culprit.

It's been a while since I did this sort of programming and you don't say what language you're using so I don't know whether you'd be able to override the methods directly or have to so some jiggery-pokery to get this to work.

ChrisF

Posted 2010-12-02T20:57:30.750

Reputation: 39 650

Any ideas for a quick fix using C++? – Shawn – 2010-12-02T21:20:23.303

@Shawn - it's been a while since I did c++ so I'm a bit rusty. In extremis you could run a global search and replace to swap out the calls or define a couple of macros? – ChrisF – 2010-12-02T21:21:48.980

I used find and replace, replacing glPushMatrix with glPushMatrix. Visual studio would then tell me how many replacements were done, effectively counting the number of glPushMatrix calls that were made.. Doing the same for pop, I could see if there was a mismatch.. or so I thought, in fact I had some glPushMatrix hidden in comments that messed up that counting strategy.. As for macros, you mean doing something like this? #define glPushMatrix(); glPushMatrix();cout<<"PUSH!"<<endl; If so, and if it works (can't test for the moment), that's a brilliant idea! – Shawn – 2010-12-06T04:04:40.370

ok so it doesn't work.. I guess the next thing would be to find and replace all pushes and pops by a custom function which modifies a counter or something before calling the original push or pop.. – Shawn – 2010-12-06T05:39:09.870