Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Exit code 3


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 HinataHyuga   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 January 2007 - 12:10 PM

I have an error in my program and its exiting with code 3 see here: The program '[800] Engine Test.exe: Native' has exited with code 3 (0x3). but it should exit with code 0. what does an exit code of 3 mean? Thanks Hinata

Sponsor:

#2 Nytegard   Members   -  Reputation: 824

Like
0Likes
Like

Posted 02 January 2007 - 12:15 PM

Exit Codes

(One of the first things Google came up with.

#3 HinataHyuga   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 January 2007 - 12:16 PM

I dont understand how that can be but thank you verrry much;
-Hinata

#4 Nytegard   Members   -  Reputation: 824

Like
0Likes
Like

Posted 02 January 2007 - 12:20 PM

Alright, here's a tip. Find a good debugger. Let's assume you use Visual C++. Place a break point near the beginning of the program. Now, step through every line of code, one by one. Continue going on, and you'll eventually crash. Look at the line where you crash.

I suggest you learn to debug your code, as it will make development a lot easier.

#5 HinataHyuga   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 January 2007 - 12:23 PM

i know where my error is but i dont know why i'm getting it it is here:

void EObject::Cleanup(){
ofstream file("debug.txt",ios::app);
file<<"DeleteingObjects"<<endl;
if(LiveObjects.size() > 0)
for(list<EObject *>::iterator i = LiveObjects.end(); i != LiveObjects.begin();i--){
file<<"Deleting live object!"<<endl;
EObject *obj = *i;
delete obj;<------------------------------------HEREEEEEEEEE
}
if(DeadObjects.size() > 0)
for(list<EObject *>::iterator c = DeadObjects.end(); c != DeadObjects.begin();c--){
file<<"Deleting dead object!"<<endl;
EObject *obj = *c;
delete obj;
}
if(LiveObjects.empty()){
file<<"LiveObjects deleted successfully."<<endl;
}
else{
file<<"Error deleting live objects!"<<endl;
}
if(DeadObjects.empty()){
file<<"DeadObjects deleted successfully."<<endl;
}
else{
file<<"Error deleting dead objects!"<<endl;
}
file<<"Deletion complete!"<<endl;
file.close();

}



here is my class.h file:

#ifndef EOBJECT_H
#define EOBJECT_H
#include<list>
#include<fstream>
using namespace std;
class EObject{
private:
static list<EObject *> LiveObjects;
static list<EObject *> DeadObjects;
int refcount;
protected:
EObject();
virtual ~EObject();
public:
int GetRefCount();
void AddRef();
void Release();
static void CollectGarbage();
static void Cleanup();
};
#endif



Thanks nyteguard
-Hinata
EDIT: yes i do use vc++

#6 Eagle32   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 January 2007 - 01:05 PM


for(list<EObject *>::iterator i = LiveObjects.end(); i !=LiveObjects.begin();i--){
file<<"Deleting live object!"<<endl;
EObject *obj = *i;
delete obj;<------------------------------------HEREEEEEEEEE
}

list<EObject *>::iterator i = LiveObjects.end(); Will point to the first empty space at the end of the list. So when you try to dereference i and assign it to *obj that's where the error is occurring.

Either start from the beginning of the list with something like this


for(list<Planet*>::iterator i = planets.begin(); i != planets.end();i++){
file<<"Deleting live object!"<<endl;
Planet *obj = *i;
delete obj;
}

Or use a reverse iterator instead. I suggest carefully reading an stl reference before you use the reverse iterator because i++ for a reverse iterator makes you go backwards through the list, which to me wasn't what I was expecting when I was being confused by lists two days ago. :)

[Edited by - Eagle32 on January 2, 2007 8:05:40 PM]

#7 HinataHyuga   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 January 2007 - 01:05 PM

i'm following the code in the enginuity article i thought it would work?
-Hinata

#8 djofdifjpodjfpodkpofdpofpd   Members   -  Reputation: 120

Like
0Likes
Like

Posted 02 January 2007 - 01:18 PM

OK start from the beginning,
The way you are removing objects is wrong as has been stated and I would suspect you have other problems in the member functions not shown.
to remove try
Quote:

for(std::list<EObject*>::iterator i = LiveObjects.begin(); i != LiveObjects.end(); )
{
EObject* o = *i;//dereference the iter
i = LiveObjects.erase(i);//remove the object from the list and increment the iter
delete o;//recovery memory
}


Hint a typedef in the class would be nice you that you don't have to keep typing the type of container. What also concerns me is the line
Quote:
if(LiveObjects.size() > 0)
why is this there you are dealing with iterators and there should be no need for it.?

Quote:
i'm following the code in the enginuity article i thought it would work?
It more than likely does, but have you followed it closely?

#9 HinataHyuga   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 January 2007 - 01:29 PM

i followed section 2 closely and am trying to build off of it. sorry also this:

for(list<EObject *>::iterator i = LiveObjects.begin(); i != LiveObjects.end();){
EObject* o = *i;//dereference the iter
i = LiveObjects.erase(i);//remove the object from the list and increment the iter
delete o;//recovery memory
}


doesnt work for me still same error.
I derive a EBitmap class from the EObject class and have a constructor and all for it that is the only object that i am making.EBitmap bit1("mybitmap.bmp",500,500);
and my program exits with code 3 every time. its very frustrating :-/
-Hinata

#10 HinataHyuga   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 January 2007 - 01:30 PM

Quote:
Original post by dmail
OK start from the beginning,
The way you are removing objects is wrong as has been stated and I would suspect you have other problems in the member functions not shown.
to remove try
Quote:

for(std::list<EObject*>::iterator i = LiveObjects.begin(); i != LiveObjects.end(); )
{
EObject* o = *i;//dereference the iter
i = LiveObjects.erase(i);//remove the object from the list and increment the iter
delete o;//recovery memory
}


Hint a typedef in the class would be nice you that you don't have to keep typing the type of container. What also concerns me is the line
Quote:
if(LiveObjects.size() > 0)
why is this there you are dealing with iterators and there should be no need for it.?

Quote:
i'm following the code in the enginuity article i thought it would work?
It more than likely does, but have you followed it closely?

I dont know how to use typdefs :-/
-Hinata


#11 djofdifjpodjfpodkpofdpofpd   Members   -  Reputation: 120

Like
0Likes
Like

Posted 02 January 2007 - 01:34 PM

As I said before I think you will have problems in other parts of your code. Lets just go crazy can you post all the code you have :)

[edit]Note to other members. Seeing as VS express is suggested to all new comers, is there an article on the board about debugging in VS?
[edit edit]Superpig explains debugging

#12 HinataHyuga   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 January 2007 - 01:42 PM

sure here we go:
test.cpp which contains the application

#include<windows.h>
#include"EObject.h"
#include"EBitmap.h"
#include"EText.h"
bool appdone = false;
const string classname = "cory";
const string windowname = "window";
EBitmap bit("fuck",500,500);
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hpInstance, PSTR cmdLine, int iCmd){
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = classname.c_str();
wc.lpszMenuName = NULL;
wc.style = CS_VREDRAW|CS_HREDRAW;
RegisterClass(&wc);
HWND hwnd = CreateWindow(classname.c_str(),windowname.c_str(),WS_OVERLAPPEDWINDOW,0,0,800,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmd);
UpdateWindow(hwnd);
MSG msg;
while(!appdone){
if(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else{
}
}
EObject::Cleanup();
UnregisterClass(classname.c_str(),hInstance);
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam){
switch(iMsg){
case WM_DESTROY:
PostQuitMessage(0);
appdone = true;
break;
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd,&ps);
//bit1.Draw(250,250,hwnd);
EndPaint(hwnd,&ps);
break;
}
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}


EObject.h

#ifndef EOBJECT_H
#define EOBJECT_H
#include<list>
#include<fstream>
using namespace std;
class EObject{
private:
static list<EObject *> LiveObjects;
static list<EObject *> DeadObjects;
int refcount;
protected:
EObject();
virtual ~EObject();
public:
int GetRefCount();
void AddRef();
void Release();
static void CollectGarbage();
static void Cleanup();
};
#endif


EObject.cpp

#include"EObject.h"
list<EObject *> EObject::LiveObjects;
list<EObject *> EObject::DeadObjects;
EObject::EObject(){
LiveObjects.push_back(this);
refcount = 0;
}
EObject::~EObject(){
}
void EObject::AddRef(){
++refcount;
}
void EObject::Release(){
--refcount;
if(refcount<=0){
LiveObjects.remove(this);
DeadObjects.push_back(this);
}
}
void EObject::CollectGarbage(){
for(list<EObject *>::iterator it = DeadObjects.begin();it != DeadObjects.end();it++){
EObject *obj = *it;
delete obj;
}
}
void EObject::Cleanup(){
ofstream file("debug.txt",ios::app);
file<<"DeleteingObjects"<<endl;
if(LiveObjects.size() > 0)

for(list<EObject *>::iterator i = LiveObjects.begin(); i != LiveObjects.end();){
EObject* o = *i;//dereference the iter
i = LiveObjects.erase(i);//remove the object from the list and increment the iter
delete o;//recovery memory
}
if(DeadObjects.size() > 0)
for(list<EObject *>::iterator c = DeadObjects.end(); c != DeadObjects.begin();c--){
file<<"Deleting dead object!"<<endl;
EObject *obj = *c;
delete obj;
}
if(LiveObjects.empty()){
file<<"LiveObjects deleted successfully."<<endl;
}
else{
file<<"Error deleting live objects!"<<endl;
}
if(DeadObjects.empty()){
file<<"DeadObjects deleted successfully."<<endl;
}
else{
file<<"Error deleting dead objects!"<<endl;
}
file<<"Deletion complete!"<<endl;
file.close();

}
int EObject::GetRefCount(){
return refcount;
}


EBitmap.h

#ifndef EBITMAP_H
#define EBITMAP_H
#include<windows.h>
#include"EObject.h"
class EBitmap : public EObject{
private:
int width;
int height;
HBITMAP bitmap;
public:
int GetWidth();
int GetHeight();
void Draw(int x, int y, HWND hwnd);
EBitmap(string location, int width, int height);
~EBitmap();
};
#endif


EBitmap.cpp

#include"EBitmap.h"
int EBitmap::GetWidth(){
return width;
}
int EBitmap::GetHeight(){
return height;
}
void EBitmap::Draw(int x,int y, HWND hwnd){
HDC hdc = GetDC(hwnd);
HDC idc = CreateCompatibleDC(hdc);
SelectObject(idc,bitmap);
BitBlt(hdc,x,y,x+width,y+height,idc,0,0,SRCCOPY);
DeleteDC(idc);
ReleaseDC(hwnd,hdc);
}

EBitmap::EBitmap(const string location,const int iwidth,const int iheight){
width = iwidth;
height = iheight;
bitmap = (HBITMAP)LoadImage(NULL,location.c_str(),IMAGE_BITMAP,width,height,LR_LOADFROMFILE);
}
EBitmap::~EBitmap(){
}


also there is EText but it contains nothing so i have not posted its source
Thanks,
Hinata

#13 djofdifjpodjfpodkpofdpofpd   Members   -  Reputation: 120

Like
0Likes
Like

Posted 02 January 2007 - 01:51 PM

Looks like I'm going to have read the article and see how the memory management is working as it pushed the this pointer onto the list.

Ok the article goes on to explain smart pointers which are used to wrap the objects and handle the scope of them. The problem you are having is that you create the bitmap in global scope on stack and then you are deleting it in the function which is throwing the error, the tracking of memory objects is only for memory which is created with the keyword "new" so if you want to wrap it up in the memory manager create it in main using
Quote:


int main(...)
{
EBitmap* bit = new EBitmap("duck",500,500);
...
}

[edit]
You either need to add incorporate the reference counting the article goes on to take about( I think you really need to read all the article before using it) or do it your self by calling the member function ::AddRef and ::Release and checking this as the article code shows.


[Edited by - dmail on January 2, 2007 8:51:16 PM]

#14 HinataHyuga   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 January 2007 - 03:53 PM

i will test your solution in just a minute but the reason i didn't go on to try the rest of the article is it has things i dont understand like templates functors and so on. I need to read a book on advanced c++ topics before i can do that section.
Thanks for the input i'll let you know if it works.
-Hinata
EDIT: YES IT WORKED :-) Now i have to figure out how to draw my bitmap without it being in global scope lol.
I'm so confussed.
-Hinata




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS