Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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++

share|improve this question
Shouldn't this be on StackOverflow? – Al E. Dec 2 '10 at 21:40
@Al Everett Don't know, it concerns the use of Visual Studio.. – Shawn Dec 3 '10 at 1:27
up vote 0 down vote accepted

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.

share|improve this answer
Any ideas for a quick fix using C++? – Shawn Dec 2 '10 at 21:20
@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 Dec 2 '10 at 21:21
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 Dec 6 '10 at 4:04
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 Dec 6 '10 at 5:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .