|
정확히 모르시겠다고 하셔서
다시 질문드려요..
에러는 delete시에 발생하구요..
메시지 내용은
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 00000000.
Read of address 00000000'.
입니다.
소스는 아래와 같구요..
레이블2는 미사일이구요..
레이블1은 적군 쯤 되고 충돌하면
미사일을 delete 하도록 짠것입니다.
TForm1 *Form1;
double x1, y1, x2, y2, b_x, b_y, line, accel_x, accel_y, m_x, m_y;
int cnt;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y)
{
Label2 = new TLabel(this);
Label2->Parent = Form1;
Label2->Top = Y;
Label2->Left = X;
Label2->Caption = "ㅁ";
b_x = rand() % 10 - 5;
b_y = rand() % 10 - 5;
cnt = 0;
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
x2 = Label2->Left;
y2 = Label2->Top;
if(x1-5 <= x2 && x1+5 >= x2 && y1-5 <= y2 && y1+5 >= y2)
{
delete Label2;
}
line = sqrt(pow(y1-y2,2) + pow(x1-x2,2));
acceleration(line, x1-x2, y1-y2);
move();
Label2->Left += m_x;
Label2->Top += m_y;
cnt++;
/*
x = aceel(x);
x = (x*pow(cnt, 2))/2;
x = sqrt(sqrt(x));
*/
}
//---------------------------------------------------------------------------
void __fastcall TForm1::acceleration(double l, double x, double y)
{
accel_x = x/l;
accel_y = y/l;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::move()
{
m_x = b_x*3 + accel_x*cnt;
m_y = b_y*3 + accel_y*cnt;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
srand(time(NULL));
x1 = Label1->Left;
y1 = Label1->Top;
}
아루스 님이 쓰신 글 :
: 삭제후에 접근을 하나보죠.
: 다른 코드가 없으니 모르겠네요.
: 오류메세지도 제대로 없어서 access violation 으로 추측만되고 read 인지 write 인지도 모르겠구요.
:
:
:
: 외토리 님이 쓰신 글 :
: : 헤더에
: : TLabel *Label2;
: :
: : 마우스 왼쪽 클릭떄
: : Label2 = new TLabel(this);
: :
: : timer 에서 어떠한 조건이 완성되었을떄
: : delete Label2;
: :
: :
: : 조건이 완성되기전까지는 잘돌아가다가..
: : 조건이 완성과 동시에 address 어쩌구 저쩌구 뜸니다..
: :
: : 뭐가 문제일까여??
|