Debug Draw Problem.

Hey guys, i have a problem with my Debug Draw Class! It compiles fine but when i run my application it displays nothing.
Here is my code:
Code:
    b2Color Color(255, 255, 255);
    DebugDraw DebugDraw(mI);
    //Flags use to manage Drawing in Box2D
    uint32 flagsDraw = DebugDraw::e_shapeBit|DebugDraw::e_jointBit|DebugDraw::e_aabbBit;
   
    DebugDraw.SetFlags(flagsDraw);
    world.SetDebugDraw(&DebugDraw);

thank you.
That part of the code looks about right, but what does your DebugDraw class look like?
It has to be derived from and override the virtual methods of the b2DebugDraw class, because the b2DebugDraw is just an abstract class and doesn't actually draw anything to your system. You must define your own methods for drawing circles, lines and polygons in your DebugDraw class.

If you've done all that, maybe you're forgetting to call the b2World::DrawDebugData() in your draw function?
I tryed the DrawDebugData function but the result is the same: no debug on screen. 😠
If you've declared the flags and calling the DrawDebugData it can only be a problem with your draw methods in your own DebugDraw class, as far as I can tell.
Care to post your DebugDraw class?

What graphics platform are you using? SDL, openGL, DirectX or some other?

Is your DebugDraw instance kept alive? Remember you're giving a pointer of it, so it must remain in scope or b2World::DrawDebugData will access garbage. You can't declare it in the stack of a function and then call DrawDebugData after returning from that function. I usually declare it as a global variable to keep it alive throughout the program's life.
Here my class
Code:
#include "CIndieLib_vc2008.h"
#include <Box2D/Box2D.h>
#include "d:\programmazione\ide-compilatori-librerie\box2d_v2.1.2\box2d\box2d\dynamics\b2worldcallbacks.h"
#pragma once

class DebugDraw :
   public b2DebugDraw
{
public:

   DebugDraw()
   {
   }
   void SetIndielib(CIndieLib* ilib)
   {
      indielib = ilib;
   }
   ~DebugDraw(void)
   {
   }

void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
{
   if(!indielib) return;
   
   //mpILib->Gfx_BeginScene();
   for (int32 i = 0, j = 1; i < vertexCount; ++i, j++)
   {
      j = (j>=vertexCount)?0:j;
     indielib->Render->BlitLine(static_cast<int>(mScale * vertices[i].x),
                        static_cast<int>(mOffsetY - mScale * vertices[i].y),
                        static_cast<int>(mScale * vertices[j].x),
                        static_cast<int>(mOffsetY - mScale * vertices[j].y),
                        255,
                        static_cast<byte>(color.r*255),
                        static_cast<byte>(color.g*255),
                        static_cast<byte>(color.b*255)
                        );
   }
   //mpILib->Gfx_EndScene();
}

void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
{
   if(!indielib) return;
   
   //mpILib->Gfx_BeginScene();
   for (int32 i = 0, j = 1; i < vertexCount; ++i, j++)
   {
      j = (j>=vertexCount)?0:j;
     indielib->Render->BlitLine(static_cast<int>(mScale * vertices[i].x),
                        static_cast<int>(mOffsetY - mScale * vertices[i].y),
                        static_cast<int>(mScale * vertices[j].x),
                        static_cast<int>(mOffsetY - mScale * vertices[j].y),
                        200,
                        static_cast<byte>(color.r*255),
                        static_cast<byte>(color.g*255),
                        static_cast<byte>(color.b*255)
                        );
   }
}

void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color)
{
   if(!indielib) return;

   int NUMPOINTS = 24+(int)radius/20;

   std::vector<b2Vec2> vertices;
   int i;//,j;
   float X;
   float Y;
   float Theta;
   float WedgeAngle;   //Size of angle between two points on the circle (single wedge)

   //Precompute WedgeAngle
   WedgeAngle = static_cast<float>(((2*PI) / NUMPOINTS));

   //Set up vertices for a circle
   //Used <= in the for statement to ensure last point meets first point (closed circle)
   for(i=0; i<=NUMPOINTS; i++)
   {
      //Calculate theta for this vertex
      Theta = i * WedgeAngle;
     
      //Compute X and Y locations
      X = static_cast<float>((center.x + radius * cos(Theta)));
      Y = static_cast<float>((center.y - radius * sin(Theta)));

      vertices.push_back(b2Vec2(X, Y));
   }

   //mpILib->Gfx_BeginScene();
   for (int32 k = 0, j = 1; k < (signed)vertices.size(); ++k, ++j)
   {
      j = (j>=(signed)vertices.size())?0:j;
     indielib->Render->BlitLine(static_cast<int>(mScale * vertices[k].x),
                        static_cast<int>(mOffsetY - mScale * vertices[k].y),
                        static_cast<int>(mScale * vertices[j].x),
                        static_cast<int>(mOffsetY - mScale * vertices[j].y),
                        255,
                        static_cast<byte>(color.r*255),
                        static_cast<byte>(color.g*255),
                        static_cast<byte>(color.b*255)
                        );
   }

}

void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2&, const b2Color& color)
{
   if(!indielib) return;

   int NUMPOINTS = 24+(int)radius/20;

   std::vector<b2Vec2> vertices;

   int i;//,j;
   float X;
   float Y;
   float Theta;
   float WedgeAngle;   //Size of angle between two points on the circle (single wedge)

   //Precompute WedgeAngle
   WedgeAngle = static_cast<float>(((2*PI) / NUMPOINTS));

   //Set up vertices for a circle
   //Used <= in the for statement to ensure last point meets first point (closed circle)
   for(i=0; i<=NUMPOINTS; i++)
   {
      //Calculate theta for this vertex
      Theta = i * WedgeAngle;
     
      //Compute X and Y locations
      X = static_cast<float>((center.x + radius * cos(Theta)));
      Y = static_cast<float>((center.y - radius * sin(Theta)));

      vertices.push_back(b2Vec2(X, Y));//Circle[i] = mpILibVector(X, Y);
   }

   //mpILib->Gfx_BeginScene();
   
   for (int32 k = 0, j = 1; k < (signed)vertices.size(); ++k, ++j)
   {
      j = (j>=(signed)vertices.size())?0:j;
     indielib->Render->BlitLine(static_cast<int>(mScale * vertices[k].x),
                        static_cast<int>(mOffsetY - mScale * vertices[k].y),
                        static_cast<int>(mScale * vertices[j].x),
                        static_cast<int>(mOffsetY - mScale * vertices[j].y),
                        200,
                        static_cast<byte>(color.r*255),
                        static_cast<byte>(color.g*255),
                        static_cast<byte>(color.b*255)
                        );
   }

}

void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
{
   if(!indielib) return;

   //mpILib->Gfx_BeginScene();
   indielib->Render->BlitLine(static_cast<int>(mScale * p1.x),
                     static_cast<int>(mOffsetY - mScale * p1.y),
                      static_cast<int>(mScale * p2.x),
                      static_cast<int>(mOffsetY- mScale * p2.y),
                     255,
                     static_cast<byte>(color.r*255),
                     static_cast<byte>(color.g*255),
                     static_cast<byte>(color.b*255)
                     );
}

void DrawTransform(const b2Transform& xf)
{
   if(!indielib) return;

   b2Vec2 p1 = xf.position, p2;
   const float32 k_axisScale = 0.4f;
   //mpILib->Gfx_BeginScene();
   
   p2 = p1 + k_axisScale * xf.R.col1;
   indielib->Render->BlitLine(static_cast<int>(mScale * p1.x),
                     static_cast<int>(mOffsetY - mScale * p1.y),
                     static_cast<int>(mScale * p2.x),
                     static_cast<int>(mOffsetY - mScale * p2.y),
                     255,
                     255,
                     0,
                     0);
   p2 = p1 + k_axisScale * xf.R.col2;
   indielib->Render->BlitLine(static_cast<int>(mScale * p1.x),
                      static_cast<int>(mOffsetY - mScale * p1.y),
                     static_cast<int>(mScale * p2.x),
                     static_cast<int>(mOffsetY - mScale * p2.y),
                     255,
                     0,
                     255,
                     0);
}

private:
   CIndieLib* indielib;
   float mScale;               //Scaling factor to draw primitives
   float mOffsetY;               //Offset to draw y axis in correct direction, as IndieLib coords of pixels start at 0 in upper position.
};
No one can help me?
Does you DebugDraw instance stay in scope? b2World does not copy your class, it just points to your instance.
Erin Catto wrote:
Does you DebugDraw instance stay in scope? b2World does not copy your class, it just points to your instance.

Yes, i declare my DebugDraw var out of the main. this should mean that the var is always in scope. am i right?
So set a break point in your debug draw functions and see what happens.
I can't do that, because indielib (the graphic library that i'm using for this project) doesn't allow the debug mode (in other words, indielib don't compile in debug mode).
I'm going crazy...

Original thread: https://box2d.org/forum/viewtopic.php?t=6608