Lifecycle of an OpenGLAppComponent in Juce - c++

I can't seem to get a good grasp on how these OpenGLAppComponents come and go. Can someone please correct my thinking if it is wrong?
Object is created that inheirts from OpenGLAppComponents and Timer. Object exists in the AudioProcessorEditor.
Call initialise() (This is where we attach to an openGLContext? A timer is started.)
addAndMakeVisible(&my_gl_appcomponent); is called from the editor, telling it that this will be drawn.
my_gl_appcomponent.setBounds(...) is called specifying the size and location of the GL component.
The timer callback calls repaint() repeatedly, updating your display.
When the editor is closed, we call shutdown(), where we detach from the openGLContext.
Delete my_gl_component, calling shutdownOpenGL() in the destructor
We are free to open the editor again, goto 2.
Am I missing anything? Do I have extra things? I've been trying to find the cause of this GL_INVALID_FRAMEBUFFER_OPERATION error for the second day in a row and I'm getting pretty frustrated.

Related

duplicate spinbox decliration in QT causing build issue

im sure you get this a lot, but im still learning the ropes.
enter image description here
Here is an error I get because I created a second slot for a spinboxValue changed.
I can comment it out and run the program with no issue but the issue keeps returning.
what is the correct way to remove this slot.
For reference, i right clicked and selected the go to slot for a second time, thinking that it will take me to the slot that was already created.
The error is in a file that i did not create and can only access it by forcing the error to reoccurred (to my knowledge)

How do you disable a CComboBox in C++?

I've searched this extensively, and the answer I came up with about 20 times is to use CWnd::EnableWindow(FALSE). Currently, I have:
GetDlgItem(myComboBox)->EnableWindow(FALSE);
Instead of disabling the ComboBox, now the entire Dialog doesn't show up, and since it's a modal dialog (or at least I'm guessing that's the reason), the entire program gets locked up because I can't close the dialog if it's not there.
Is there a way to disable editing to this box without making it disappear entirely; similar to what SetReadOnly() does for a CEdit?
Edit:
Suddenly, the syntax above started working the next morning. I'm still not entirely sure why it didn't work in the first place.
EnableWindow(FALSE) is the correct function to call but your syntax looks like it may be incorrect (but it's hard to say with such a minimal example).
Is myComboBox an instance of CComboBox? If so, I'd expect to see:
myComboBox.EnableWindow(FALSE);
or, using the associated resource ID:
((CComboBox*)GetDlgItem(IDC_MY_COMBO_BOX))->EnableWindow(FALSE);
Threading issues or duplicate resource ID's can also cause weird issues.
It seems you are trying to call EnableWindow() from a different thread than the dialog's
You could try this, and see if it works for you:
GetDlgItem(myComboBox)->PostMessage(WM_ENABLE, (WPARAM)FALSE);

In MFC, when opening a file or creating a file, is WM_PAINT generated?

I am learning MFC programming with the book "Programming Windows with MFC (2nd Edition)". I have some questions about the book example from chapter 9.
When I open a file or click new file, the function CSquaresView::OnDraw() is called. I checked the stack, the reason is that CView::OnPaint() calls this function.
But I don't understand how CView::OnPaint() is called. Is the message WM_PAINT generated if CSingleDocTemplate::OpenDocumentFile() is called by the default setting? Is
it possible to change the behavior?
Thanks,
Brian
WM_PAINT is triggered for every window that just was created and gets visible.
But internally the following code is executed (depending of MDI/SDI) that forces a window update:
CSingle/MultiDocTemplate::OpenDocumentFile.
So either a new CDocument is created or a previous one is reused and prepared.
A new Frame window is created or reused.
The new view is created or the old ne reused.
finally InitialUpdateFrame is called!
InitialUpdateFrame sends a message to all created frames and this finally causes CView::OnInitialUpdate to be called.
OnInitialUpdate just calles again CView::OnUpdate and the default implementation calles CWnd::Invalidate
Now on the next turn in the message loop the window receives a WM_PAINT message.
Preventing OnDraw to be executed wouldn't be wise, because the contents of your document can't be displayed to the user in this case. And this has to be done, always when the window is new, or the contents of the document just changed (here it changed after loading a new document).
While I don't have the book or know what the sample is about (and I don't think many readers of this do...), I conjecture that the reason you're getting a WM_PAINT is because a file open dialog is opened which covers your drawing area at some point, and when it is closed, that area is invalidated. Is that possible?
Am I missing something? This is standard windows behavior. CView::OnPaint() is called because windows has generated WM_PAINT message. If you are debugging and set a break point in OnDraw() it will always break there because the debugger and application takes turns to run (but unless you application is running on a separate monitor) and WM_PAINT is generated. If you do want to stop redrawing though, try SetRedraw

C++ wxWidgets Gui-App stays in memory after closing it

The subject says it all. After i closed my app, it stays in the list of processes with some memory. I tried google perf tools and hours of debugging to find the leak.
Are there other tools to test it and find the problem?
Thank you.
My guess is that you have closed the top level window, and thus all its child windows, but you have not closed the app itself.
This does not happen if your program is arranged in a 'normal' way, but if you have, deliberately or by accident, used an unusual arrangement this can happen.
Fixing it, of course, depends on how exactly you have arranged your code. However, here is a suggestion to begin.
The usual way to close the app is to call wxApp::OnExit() which normally occurs when the top level window closes.
Do you have your own class, derived from wxApp? Do you have an override of OnExit()? If not, then make it so and use the debugger to check whether or not it is being called. If it is not being called, work out how to ensure that it is called.
Another idea: use the following to check that your top level window will close the app
bool wxApp::GetExitOnFrameDelete() const
Returns true if the application will exit when the top-level window is
deleted, false otherwise.
If this return false, use the corresponding set to make it so.
A 3rd idea: The application will not exit while there are any top level windows open. So perhaps you have another top level window that is minimized or invisible but has not been closed? Any wxDialog or WxFrame or window derived from these is a top level window and will prevent the application from closing.
A 4th idea: Do you have any globals or attributes of the application object, whose destructors could enter an endless loop? These destructors are called after the windows are destroyed and if one of them does not return you would see the behaviour you describe.
You may try to look at wxWidget's sample folder. You'll find lots of small but complete applications that contain the full init/exit application cycle.
Inspect some samples and compare with your app's workflow.
Yes...problem solved. A TopLevelWindow that was not destroyed. A Memory Leak....stupid mistake.

Animation in Qt 4.6

I've a block of code where I've used Qt's new animation framework. I needed the animation just in that block of code and I don't need the animation related variables in other places. Clearly, the animation won't work if it is destroyed before the animation completed. For example, the following doesn't work:
if (animate)
{
QPropertyAnimation animation(_piece_images[svg_index].getImage(), "pos");
animation.setDuration(200);
animation.setEndValue(getCellPos(row, col));
animation.setEasingCurve(QEasingCurve::InOutSine);
animation.start();
}
So I'm using animation using pointer:
if (animate)
{
QPropertyAnimation *animation = new
QPropertyAnimation(_piece_images[svg_index].getImage(), "pos");
animation->setDuration(200);
animation->setEndValue(getCellPos(row, col));
animation->setEasingCurve(QEasingCurve::InOutSine);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
My question is, is there any memory leak in the above solution? Please provide reference if possible, probably I've missed something.
By passing in QAbstractAnimation::DeleteWhenStopped to the start() method, you should be covered so long as you allow the animation to run to completion, manually call stop(), or explicitly call delete at some point. Though if your loop count is -1 (infinite) then you must make the manual call to stop() or delete.
The documentation for the DeletionPolicy parameter to start() makes this as explicit as I'd think one would need. But you can certainly put some debug code in to check and make sure the destructor gets called when you think it should.
Moreover, it couldn't hurt to regularly run Valgrind or another leak-checker. Good to get in the habit sooner rather than later!
UPDATE: If you're curious as to how an object is able to "delete this", the trick is that there's something called QObject::deleteLater(). It queues the deletion so that it happens the next time the event loop runs. If you're ever curious about the mechanics of a Qt routine, don't be afraid to go look at the source... it's usually very clear:
http://qt.gitorious.org/qt/qt/blobs/HEAD/src/corelib/animation/qabstractanimation.cpp#line599