Mail Archives: djgpp/1999/11/08/10:31:52
From: | "Philip Bock" <philipb AT escape DOT ca>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Memory access error?
|
Lines: | 202
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Newsreader: | Microsoft Outlook Express 5.00.2314.1300
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2314.1300
|
Message-ID: | <3fBV3.3521$1J5.335883@typhoon.mbnet.mb.ca>
|
Date: | Mon, 08 Nov 1999 14:37:51 GMT
|
NNTP-Posting-Host: | 216.81.26.50
|
X-Trace: | typhoon.mbnet.mb.ca 942071871 216.81.26.50 (Mon, 08 Nov 1999 08:37:51 CST)
|
NNTP-Posting-Date: | Mon, 08 Nov 1999 08:37:51 CST
|
Organization: | MBnet Networking Inc.
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
I have posted several questions about a program I am working on to this
group over the last few weeks, and I just wanted to thank you all for the
great help you've been! I finally got my program to compile without any
errors, which is a bit of a feat considering it's the first time I've tried
all this object-oriented stuff.
However, when I run it, it crashes with this error:
Shutting down Allegro
Exiting due to signal SIGSEGV
General Protection Fault at eip=000018e0
eax=65726168 ebx=00008394 ecx=00000000 edx=00000000 esi=00000054
edi=0005c6e8
ebp=000dc688 esp=000dc670 program=C:\DEVELOP\VECTOR2D\VECTOR.EXE
cs: sel=00a7 base=83949000 limit=000fffff
ds: sel=00af base=83949000 limit=000fffff
es: sel=00af base=83949000 limit=000fffff
fs: sel=00c7 base=00000000 limit=0010ffff
gs: sel=00c7 base=00000000 limit=0010ffff
ss: sel=00af base=83949000 limit=000fffff
App stack: [000dc6e8..0005c6e8] Exceptn stack: [0005c5c8..0005a688]
Call frame traceback EIPs:
0x000018e0
0x000015da
0x000355ae
Am I correct in assuming this has something to do with my constructors, or
what? (Note: the program doesn't include proper destructors, meaning that
some allocated memory is not explicitly deallocated. I was saving that for
version 2.0 : ) )
Code:
#include <allegro.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
struct coord
{
int x, y;
};
struct vector
{
coord c1, c2;
int color;
};
struct shape
{
int numvects;
int stype;
int sfill;
vector **vects;
shape(int newnumvects, int newstype, int newsfill);
};
struct vimg
{
int numvectors, numshapes;
vector *vectors;
shape **shapes;
vimg(int nnumv, int nnums, int vpers[]);
};
void program_init(char program_title[]);
void draw_vimg(vimg *vectimg, int x, int y, int xscale, int yscale);
vimg *gen_vimg(void);
int main(void)
{
program_init("Vector Graphics Rendering Demo");
getch();
set_gfx_mode(GFX_VESA1, 640, 480, 0, 0);
vimg *mygraphic;
mygraphic = gen_vimg();
draw_vimg(mygraphic, 200, 100, 1, 1);
getch();
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
}
void program_init(char program_title[])
{
clrscr();
textcolor(BLACK);
textbackground(LIGHTGRAY);
for(int c = 1; c != 81; c++)
{
gotoxy(c, 1);
cprintf(" ");
}
for(int x = 0; program_title[x] != '\0'; x++)
gotoxy(40 - (x / 2), 1);
cout << program_title << '\n';
textcolor(LIGHTGRAY);
textbackground(BLACK);
cout << "Initializing Allegro library...\n";
allegro_init();
cout << "Setting up timer...\n";
install_timer();
cout << "Initializing mouse routines...";
if (install_mouse() == -1)
cout << "failed\n";
else
cout << '\n';
cout << "Detected Operating System: ";
if (os_type == OSTYPE_UNKNOWN)
cout << "MS-DOS\n";
if (os_type == OSTYPE_WIN95)
cout << "Windows 95\n";
if (os_type == OSTYPE_DOSEMU)
cout << "Linux DOSEMU\n";
}
void draw_vimg(vimg *vectimg, int x, int y, int xscale, int yscale)
{
for(int a = 0; a != vectimg->numshapes; a++)
{
file://Code to draw one shape's outline
for(int b = 0; b != vectimg->shapes[a]->numvects; b++)
line(screen, (vectimg->shapes[a]->vects[b]->c1.x*xscale)+x,
(vectimg->shapes[a]->vects[b]->c1.y*yscale)+y,
(vectimg->shapes[a]->vects[b]->c2.x*xscale)+x,
(vectimg->shapes[a]->vects[b]->c2.y*yscale)+y,
vectimg->shapes[a]->vects[b]->color);
file://Code to fill shape goes here.
}
}
vimg *gen_vimg(void)
{
int vpers[]={6};
vimg newvimg(6, 1, vpers);
newvimg.vectors[0].c1.x = 50;
newvimg.vectors[0].c1.y = 1;
newvimg.vectors[0].c2.x = 100;
newvimg.vectors[0].c2.y = 1;
newvimg.vectors[0].color = 1;
newvimg.vectors[1].c1.x = 100;
newvimg.vectors[1].c1.y = 1;
newvimg.vectors[1].c2.x = 150;
newvimg.vectors[1].c2.y = 50;
newvimg.vectors[1].color = 1;
newvimg.vectors[2].c1.x = 150;
newvimg.vectors[2].c1.y = 50;
newvimg.vectors[2].c2.x = 100;
newvimg.vectors[2].c2.y = 100;
newvimg.vectors[2].color = 1;
newvimg.vectors[3].c1.x = 100;
newvimg.vectors[3].c1.y = 100;
newvimg.vectors[3].c2.x = 50;
newvimg.vectors[3].c2.y = 100;
newvimg.vectors[3].color = 1;
newvimg.vectors[4].c1.x = 50;
newvimg.vectors[4].c1.y = 100;
newvimg.vectors[4].c2.x = 1;
newvimg.vectors[4].c2.y = 50;
newvimg.vectors[4].color = 1;
newvimg.vectors[5].c1.x = 1;
newvimg.vectors[5].c1.y = 50;
newvimg.vectors[5].c2.x = 50;
newvimg.vectors[5].c2.y = 1;
newvimg.vectors[5].color = 1;
newvimg.shapes[0]->vects[0] = &newvimg.vectors[0];
newvimg.shapes[0]->vects[1] = &newvimg.vectors[1];
newvimg.shapes[0]->vects[2] = &newvimg.vectors[2];
newvimg.shapes[0]->vects[3] = &newvimg.vectors[3];
newvimg.shapes[0]->vects[4] = &newvimg.vectors[4];
newvimg.shapes[0]->vects[5] = &newvimg.vectors[5];
}
shape::shape(int newnumvects, int newstype, int newsfill)
{
numvects = newnumvects;
stype = newstype;
sfill = newsfill;
vects = new vector *[newnumvects];
}
vimg::vimg(int nnumv, int nnums, int vpers[])
{
numvectors = nnumv;
numshapes = nnums;
vectors = new vector [nnumv];
shapes = new shape *[nnums];
for (int c = 0; c != nnums; c++)
shapes[c] = new shape(vpers[c], 0, 0);
}
- Raw text -