• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
HinataHyuga

Exit code 3

13 posts in this topic

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
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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++
0

Share this post


Link to post
Share on other sites

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]
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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]
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0