Reply
Thread Tools
Posts: 252 | Thanked: 252 times | Joined on Nov 2009
#1
I have been doing som Qt + OpenGL programming lately to check out the possibilities in making portable games and 3D graphics. It has been a happy adventure, until today.

When I was trying to run my latest changes on my N900 I encountered the strangest bug I have yet seen. What happened was that nothing was rendered on-screen on my N900. After a long debugging session I figured that if I removed some QMatrix4x4::rotate and scale functions, it would render again. However, I didn't want to do this, so I debugged a bit further, trying to find the source of the problem.

By coincidence, I added qDebug() << "something"; in my objects' draw function (which also contains the rotation and scaling). All of a sudden the rendering came back with rotation and scaling! But as you might know, calling qDebug() a couple of times each frame is going to hit the performance big-time. So I tried something out-of-the blue again and put my QShaderProgram::bind() function in an if-statement, which would output something with qDebug() if it ever failed (which it never does) - well, guess what? It actually worked!

Now my application compiles, runs and renders - but I have no idea why this piece of code would help anything:
Code:
    if(!program.bind()) {
        qDebug() << "Failed to bind program";
    }
Anyone here who's got a clue about why this did the trick?

By the way, it never fails to bind(), so the text is never outputted to the terminal.
 

The Following User Says Thank You to dragly For This Useful Post:
Posts: 77 | Thanked: 176 times | Joined on Dec 2009 @ Hamburg, Germany
#2
Adding that piece of code probably changes the memory layout of your program. Is it possible that you somehow corrupt your memory? Adding your "debugging" code might move the matrices in memory and thus prevent them from being destroyed.
__________________
Finally something useful for the N900's front camera:
My face tracking game
And a little 3d display demo
 

The Following User Says Thank You to jfk For This Useful Post:
Posts: 252 | Thanked: 252 times | Joined on Nov 2009
#3
I was thinking about memory errors, but I can't see that I have done anything to cause that. The source code for the project is hosted here:
http://github.com/dragly/loose_cannon
I guess glwidget.cpp and model.cpp are the most relevant files, if you would like to have a look at them?

I'm a bit more used to Java, so I haven't got that much hands-on experience with C/C++ and memory. I suppose I could have made some mistakes in-deliberately.
 
Posts: 252 | Thanked: 252 times | Joined on Nov 2009
#4
Alright!

You were correct. It was probably a memory issue. I figured I didn't initialize all my values (bools and integers), so I started doing this. At first it didn't help, but it made the application failed to run properly on my computer as well - but only if it was the first time I ran the application. This made it possible for me to debug the application, and after a quick look around I found that the QGLShaderProgram::attributeLocation() values were all wrong. Then I had a look at my functions and found this stupid function:
Code:
bool Model::linkShaderProgram() {
    if(program.link()) {
        qDebug() << "Program linked";
    } else {
        qDebug() << "Failed to link program:" << program.log();
    }
}
It is a bool function, but I forgot to let it return anything! For some reason I thought it was called every time, but I guess it wasn't. When called from here
Code:
bool Model::setShaderFiles(QString fragmentShader, QString vertexShader) {
    return setFragmentShaderFile(fragmentShader) && setVertexShaderFile(vertexShader) && linkShaderProgram() && initShaderProgram();;
}
it probably only called initShaderProgram() every now and then - that is, when linkShaderProgram() luckily returned true due to old memory values. I see now that it is a good thing to check my own boolean return values to see if they are correct

Anyways, thanks for the tip, jfk! It sent me in the right direction, and explained why silly workarounds actually made a change
 
Posts: 77 | Thanked: 176 times | Joined on Dec 2009 @ Hamburg, Germany
#5
That's great to hear. Unfortunately, I hadn't had the time to look over your code yet.

Good luck with your project!
__________________
Finally something useful for the N900's front camera:
My face tracking game
And a little 3d display demo
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 09:44.