Non trivial bug on OpenGLContext with Component painting.

Discussion and support for general JUCE issues

Non trivial bug on OpenGLContext with Component painting.

Postby alexdlabs » Sat Jun 30, 2012 10:27 am

I think I found a problem on OpenGLContext with shouldPaintComponent set to true.

Quick creation/destruction sometime perform a null pointer indirection (CachedImage threading made this bug non systematics)

OpenGLContext::setAssociatedObject assert at line 619 before crash

Code: Select all
jassert (c != nullptr && nativeContext != nullptr);


with nativeContext not null but c null.


Here a snippet helping you to reproduce the problem :

Code: Select all
// dummy renderer
class VoidRenderer : public OpenGLRenderer
{
  virtual void newOpenGLContextCreated() {}
  virtual void renderOpenGL() {}
  virtual void openGLContextClosing() {}
};

//  Ugly component owning renderer and context with public attach/detach.
class VoidRendererAndContextComponent : public Component
{
public:
  VoidRendererAndContextComponent()
    {glContext.setComponentPaintingEnabled(true); glContext.setRenderer(&renderer);}
  ~VoidRendererAndContextComponent()
    {jassert(!glContext.isAttached())}
  void attach()
    {glContext.attachTo(*this);};
  void detach()
    {glContext.detach();}
private:
  VoidRenderer renderer;
  OpenGLContext glContext;
};

// Todo: add a Timer inheritance to a Component class of your choice and a startThread(100)  when it's visible.
// ...

// Trick to ensure !MessageManagerLock::lockWasGained() succeed on CachedImage::run() :
// I call creation-attachement / detachement-deletion alternately in a timerCallback
virtual void timerCallback()
{
  static bool mustCreateAndAttach = false;  // static alternator
  mustCreateAndAttach = !mustCreateAndAttach ;

  static VoidRendererAndContextComponent* component = NULL; // ugly static just for testing
   
  if (mustCreateAndAttach)
  {
    component = new VoidRendererAndContextComponent();
    component->setSize(42, 42);
    addAndMakeVisible(component);
    component->attach();
  }
  else // detach and delete
  {
    component->detach();
    removeChildComponent(component);
    delete component;
  }
}

//...
// end of your Component class...
alexdlabs
JUCE Obsessive
 
Posts: 55
Joined: Tue Mar 08, 2011 10:12 am
Location: Paris

Re: Non trivial bug on OpenGLContext with Component painting

Postby alexdlabs » Sat Jun 30, 2012 12:34 pm

Some additionnal infos for helping:

I'm running on Win7-64-SP1
Last Juce Git builded with Visual Studio 2008
Callstack :

Code: Select all
   juce::OpenGLContext::setAssociatedObject(name=0x0000000140fb3e58, newObject=0x0000000015f36250) Line 619   C++
   juce::OpenGLContext::copyTexture'::`7'::OverlayShaderProgram::select(context={...}) Line 666   C++
   juce::OpenGLContext::copyTexture(targetClipArea={...}, anchorPosAndTextureSize={...}, contextWidth=42, contextHeight=42) Line 731   C++
   juce::OpenGLContext::CachedImage::paintComponent() Line 209   C++
   juce::OpenGLContext::CachedImage::renderFrame() Line 158   C++
   juce::OpenGLContext::CachedImage::run() Line 261   C++
   juce::Thread::threadEntryPoint() Line 98   C++
   juce::juce_threadEntryPoint(userData=0x0000000015f34d48) Line 106   C++
   juce::threadEntryProc(userData=0x0000000015f34d48) Line 121   C++
alexdlabs
JUCE Obsessive
 
Posts: 55
Joined: Tue Mar 08, 2011 10:12 am
Location: Paris

Re: Non trivial bug on OpenGLContext with Component painting

Postby jules » Tue Jul 03, 2012 11:07 am

Thanks! I've done some fixing - try it now!
User avatar
jules
Fearless Leader
 
Posts: 17364
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: Non trivial bug on OpenGLContext with Component painting

Postby alexdlabs » Tue Jul 03, 2012 2:07 pm

Your fix seems correct this issue perfectly.

Thanks a lot for that !
alexdlabs
JUCE Obsessive
 
Posts: 55
Joined: Tue Mar 08, 2011 10:12 am
Location: Paris


Return to General JUCE discussion

Who is online

Users browsing this forum: Bing [Bot], WizardFish and 5 guests