OpenGLComponent in the TabbedComponent


#1

Hello!
I’ve got a problem with TabbedComponent and the OpenGL component in it. I’m trying to add an OGL component inside
one of the ‘tabs’ of the TabbedComponent and when i’m trying to switch between tabs my app. is crashing with 'Heap corrupted’
message. That is only happans under debugger (Visual Studio). Runing my app directly do not cos any problems.
Sample project is attached. Please, if some one meet any problems like that one, help! What is my mistake? :cry:
Thank You. Bye…
P.S. i’m using Windows 7 + SP1, Juce 1.54.27 and Visual Studio 9.0.30729.1

Appendix A: OpenGL component

class TstOgl : public OpenGLComponent {

public:
    TstOgl () {
       // removed..
       // setSize (100, 100); // argh..
    }
    ~TstOgl() {
   }
   void renderOpenGL () {
        // it's really doesn't matter what's happening in here..
    }
    void newOpenGLContextCreated () {
        // .. and in here too.
    }
};

Appendix B: crash screenshot

Appendix C: the app

This is how the app. look like. The ONE and ONLY problem is that WHEN I CLICK ON TAB #2 or #3 i’ve got an Appendix B result :oops:
One note. App. is crashing ONLY when i’m switching FROM the TAB with OpenGLComponent, but not when switching TO the tab
with OpenGLComponent.

Appendix D: calls stack screen shot


#2

So, this ok? And i shouldn’t worry about? :oops:


#3

No, it’s never ok to have a corrupted heap!

But I can’t tell from this description whether it’s a problem that I should worry about, or just some kind of mistake that you’ve made (e.g. deleting a dangling pointer, etc). If you can convince me that this is a juce bug, I’ll take a closer look.


#4

Hello, Jules… Thanks for Your reply.
Hm, i’m not so sure that i can explain clearly may be. But my problem is a simple, i guess.
I’ve attached a file “TstTabOgl.zip”. It is a simple project with TabbedComponent with three tabs in it.
One tab, first, contains an OpenGLComponent and two of the rest are empty. So, when i ran my app under
debugger in Visual Studio i’ve got a “Heap Crash”.

// Update: i’m was wrong in here.
//The only thing that solve the problem, is:
// //mainTabs->addTab (T("Tab #1"), Colour (0xffe4e4e4), new TstOgl(), true); // create an obj. and add it to the tab instead of 'new //TstOgl()' // //e.g. // //mainTabs->addTab (T("Tab #1"), Colour (0xffe4e4e4), tstogl, true); // //... some where //ScopedPointer <TstOgl> tstogl; //

Whould you excuse my? I think i’m was wrong… My mistake! Sorry. :cry:
Bye…


#5

A little update: Would You be so kind to take a look at zip file? Can You please open a project and test it. Just build and try
to switch between the tabs?
Am i blind? :cry:
Sometime it is crashes sometime it is not… In about 20 runs 1 or 2 it was fine :frowning:
I don’t understand, may be i’m really blind or it is a heat.


#6

You’re telling the tab comp to delete the component that you’re giving it, and also using a scopedpointer to delete the same object.


#7

I’m really sorry that i’m waste Your time and asking for a dumb questions. Sorry.
One more addition to the first post in the topic. When i’m add a simple component, not an OpenGlComponent based everything just fine.
Probably You may ignore my messages and it is not a Juce problem.
I’m really sorry again. Forgive my… :cry:


#8

Vinn! Help me!!! I’m sure u can… :lol:


#9

I already explained your mistake - read my last post carefully!


#10

Thanks. And without ScopedPointer i’ve got the same problem.
I’ve opened my project from the .zip file, change inheritance from OpenGLComponent to Component, remove GL related methods,
add paint() and everything works just fine… No crashes when i switch between tabs, ok.
Jules, i’m sorry for wasting Your time, forget it and excuse me, this is my problem i guess.
Thank you.


#11

his original code he posted in the zip file do not contains the tab component in a scoped ptr.
It should works fine AFAIK.

mainTabs should not be in a scoped_ptr though as it uses setContentOwned
Still it should not crash currently when switching tabs unless I’m missing something


#12

You have “ahhhh” in setSize in your constructor, so I think your crash/exception is different than what you originally posted. I’m away from my computer at the moment to run your project but…

  1. Why bother setting the size? The TabbedComponent will set the size of its children(your tstogl being a child)
  2. Probably best practise to not do too much in the constructor until your context callback is called anyway.

Best to break in the debugger and screenshot the callstack for us all


#13

Updated. Problem still exist. :cry:


#14

Hello! Please read!!
Solved by replacing default constructor within the :
… : OpenGLComponent(openGLDefault, true) … // by default it is false
and the component is now looks like this:

class TstOgl : public OpenGLComponent {

public:
	TstOgl () : OpenGLComponent(openGLDefault, true) {
    }

    ~TstOgl() {
    }

    void renderOpenGL () {
        // it's really doesn't matter what's happening in here..

    }

    void newOpenGLContextCreated () {
        // .. and in here too.
    }

};

And now the question is: why is it so? :oops: Am i stupid and can’t see obvious things?
Thank you.


#15

Last version also crashes, but in another way in the file juce_win32_OpenGLComponent.cpp at function

static void getWglExtensions (HDC dc, StringArray& result) noexcept
{
    PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;

    if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
        result.addTokens (String (wglGetExtensionsStringARB (dc)), false); // <- here
    else
        jassertfalse; // If this fails, it may be because you didn't activate the openGL context
}

Also founded, that git version from 2011-04-26 works just fine, but version from 2011-04-28 crashes with error from first post of this topic.
Well, i don’t know really what the problem in is… :frowning:
If i’m a bit paranoid, let it be.


#16

Things would have to be pretty badly messed-up to crash at that line! Can you find any more clues from debugging it about what exactly is crashing?