There was a problem using dynamic allocations (with new) in many of the

graphics classes.  In many places the code was written assuming default values
of 0, especially for pointers and booleans.  While that's true in the case of
a static instance with the default constructors, it not generally true with
dynamic allocation unless the default constructor is replaced.  Therefore I've
added constructors in the following classes/structs:  MOVING_TEXT_PANEL, COLOR,
PROGRESS, PROGRESS_2D, TEXTURE_DESC, REDUCED_ARRAY.

This will be a problem is any are used from C code unless the constructors
declarations are enclosed in "#ifdef __cplusplus" blocks.

There was also a problem that showed up under Windows when dynamic allocations
were used.  app_graphics_resize() gets called before app_graphics_init().  This
usually results in a crash since classes haven't yet been constructed.  To work
around this I've added a case for WM_CREATE in the WndProc() which calls
app_graphics_init.  Under windows this will get passed before WM_SIZE does.

svn path=/trunk/boinc/; revision=5395
This commit is contained in:
Eric J. Korpela 2005-02-11 02:15:20 +00:00
parent d80fe863cc
commit 7450ffd910
4 changed files with 37 additions and 5 deletions

View File

@ -415,6 +415,19 @@ void draw_text_right(
}
}
MOVING_TEXT_PANEL::MOVING_TEXT_PANEL() :
theta(0), dtheta(0), color(0), char_height(0), line_width(0), line_spacing(0), margin(0)
{
int i;
for (i=0;i<3;i++) {
base_pos[i]=size[i]=0;
}
for (i=0;i<PANEL_MAX_LINES;i++) {
memset(&(text[i][0]),0,256);
}
}
void MOVING_TEXT_PANEL::init(
float* p, float* s, COLOR& c, double d, double ch, double lw, double ls, double m
) {

View File

@ -29,6 +29,7 @@ struct COLOR {
float g;
float b;
float a;
COLOR(float rr=0,float gg=0, float bb=0, float aa=0) : r(rr),g(gg),b(bb),a(aa) {};
};
extern void HLStoRGB( double H, double L, double S, COLOR& c);
@ -99,6 +100,11 @@ public:
float pos[3];
void init(float* pos, float len, float diam, float inner, float* c, float* ic);
void draw(float);
PROGRESS() : len(0), rad(0), inner_rad(0) {
memset(color,0,sizeof(color));
memset(inner_color,0,sizeof(inner_color));
memset(pos,0,sizeof(pos));
};
};
//2d progress bar
@ -110,6 +116,11 @@ public:
void set_pos(float*);
void init(float* pos, float len, float width, float inner_width, float* c, float* ic);
void draw(float);
PROGRESS_2D() : len(0), width(0), inner_width(0) {
memset(color,0,sizeof(color));
memset(inner_color,0,sizeof(inner_color));
memset(pos,0,sizeof(pos));
};
};
// a graph of a function of 1 variable drawn as a ribbon in 3D
@ -147,6 +158,7 @@ class MOVING_TEXT_PANEL {
double margin;
char text[PANEL_MAX_LINES][256];
public:
MOVING_TEXT_PANEL();
float pos[3];
void init(float* pos, float* size, COLOR& color, double dtheta, double ch, double lw, double ls, double margin);
void draw();
@ -196,6 +208,7 @@ struct TEXTURE_DESC {
unsigned int id;
double xsize; // size of underlying image
double ysize;
TEXTURE_DESC() : present(false),id(0),xsize(0),ysize(0) {};
void draw(float* pos, float* size, int xalign, int yalign);
int load_image_file(const char* filename);
int CreateTextureJPG(const char* strFileName);

View File

@ -43,13 +43,16 @@
#include "gutil.h"
#include "reduce.h"
REDUCED_ARRAY::REDUCED_ARRAY() {
rdata = 0;
ftemp = 0;
itemp = 0;
reduce_method = REDUCE_METHOD_AVG;
REDUCED_ARRAY::REDUCED_ARRAY() : sdimx(0), sdimy(0), rdimx(0), rdimy(0), rdimx_max(0), rdimy_max(0), scury(0),
rdata(0), rdata_max(0), rdata_min(0), ftemp(0), itemp(0), last_ry(0), last_ry_count(0), nvalid_rows(0),
ndrawn_rows(0), draw_deltax(0), draw_deltaz(0), reduce_method(REDUCE_METHOD_AVG), hue0(0), dhue(0),
alpha(0), xlabel(0), ylabel(0), zlabel(0)
{
memset(draw_pos,0,sizeof(draw_pos));
memset(draw_size,0,sizeof(draw_size));
}
REDUCED_ARRAY::~REDUCED_ARRAY() {
if (rdata) free(rdata);
if (ftemp) free(ftemp);

View File

@ -313,6 +313,9 @@ LRESULT CALLBACK WndProc(
FillRect(pdc, &winRect, (HBRUSH)GetStockObject(BLACK_BRUSH));
EndPaint(hWnd, &ps);
return 0;
case WM_CREATE:
app_graphics_init();
return 0;
case WM_SIZE:
if ( SIZE_MINIMIZED == wParam ) {
visible = FALSE;