Thread: My Big Problem

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty

    My Big Problem

    Well there's been talk about making this section more active, and I suppose one way I could help is by participating in sharing my own troubles coding as well. Now the reason I haven't posted code in the longest is because I've been working on a rather large project, but about 1 month ago it grinded to a halt because I had a mysterious error. I didn't want to get help because I would have to release all my code. Even though Im all for open source I got kinda full of myself. I should have asked for help ages ago. So from now on I have decided I will make this project open source, and in the future may even make it a group project if anyone is interested.


    On to the problem. The technique Im using is pretty unique. Instead of creating and destroying a font object when I need it Im creating roughly 1250 font objects. A class manages all of the fonts. When finished accessing fonts it will optimize and destroy all unneccesary pointers. It also will create new font objects when you need them and deallocate them when you don't. Its sorta like a Java-style implementation for DirectX, in that the memory allocation is handled by the class.

    The problem I run into is on initializing the fonts. Now despite hours of tinkering I just don't know how to find the error. There's no way for me to debug it, because I must inject it into the D3D test environment.....

    Hmm... an idea just hit me that I could in fact compile the code into an executable instead of a DLL and create my own D3D environment. That would allow me to debug it. Ofcourse Im not good at debugging. So anyone who knows any good tutorials for debuugging please let me know.

    Also since the god of open source seems to have blessed me with this idea. Im going to go ahead and fulfill my promise and release the source and hope for the best:

    Header file for DPrint class
    Code:
    /*********************************************
    DPrint is a class that streamlines the simple
    2D DirectX functions often used in D3D Menus
    such as drawing Text, simple shapes, etc.
    Created By: why06 (why06mail@gmail.com)
    *********************************************/
    #include"HEADERS.h"
    #ifndef DPRINT_H
    #define DPRINT_H
    
    const unsigned int NUMTYPEFACES = 16;
    const unsigned int NUMFONTWEIGHTS = 10;
    const unsigned int NUMFONTSIZES = 26;
    const unsigned int LARGESTFONTSIZE = 50;
    const unsigned int LARGESTFONTWEIGHT = 1000;
    const unsigned int ITALICS = 2;
    const unsigned int MAXFONTS = (NUMTYPEFACES * NUMFONTSIZES * NUMFONTWEIGHTS * ITALICS);
    
    struct TYPEFACE
    {
    	static const UINT ARIAL = 0;
    	static const UINT ARIALBLACK = 1;
    	static const UINT BOOKANTIQUA = 2;
    	static const UINT CALIBRI = 3;
    	static const UINT COMICSANSMS = 4;
    	static const UINT COURIERNEW = 5;
    	static const UINT GEORGIA = 6;
    	static const UINT IMPACT = 7;
    	static const UINT LUCIDACONSOLE = 8;
    	static const UINT LUCIDASANSUNICODE = 9;
    	static const UINT MICROSOFTSANSSERIF = 10;
    	static const UINT SYMBOL = 11;
    	static const UINT TAHOMA = 12;
    	static const UINT TIMESNEWROMAN = 13;
    	static const UINT TREBUCHETMS = 14;
    	static const UINT VERDANA = 15;
    };
    
    typedef struct FFORMAT
    {
    	UINT typeface;
    	UINT fontweight;
    	UINT fontsize;
    	BOOL italic;
    	UINT ordinal;
    	BOOL In_use;
    }*LPFFORMAT;
    
    class DFont
    {
    	LPDIRECT3DDEVICE9 pDevice;
    	LPD3DXFONT* pfont;
    	string* fontnames;
    	void GenerateFont(unsigned int fontindex);
    public:
    	DFont(LPDIRECT3DDEVICE9 pDevice);
    	LPD3DXFONT GetFont(LPFFORMAT pFormat);
    	LPD3DXFONT GetFont(unsigned int index);
    	bool GetFontFormatFromIndex(LPFFORMAT pformat, UINT index);
    	int DeleteFont(unsigned int index);
    	int DeleteFontsExcept(int* intarray);
    	void PreReset();
    	void PostReset();
    };
    
    
    //***********************************************************************************
    //class: Dprint
    //purpose: A wrapper class for D3DFONT to simplify the construction of this menu base
    //***********************************************************************************
    class DPrint
    {
    	LPDIRECT3DDEVICE9 pDevice;
    	int origx, origy;
    	int x, y;
    	int vspacing;//vertical spacing
    	int width;
    	DFont* pDFont;
    	LPFFORMAT* UsedFonts;
    	unsigned int ufindex;
    	bool checkusage;
    
    	void AddtoUsedFonts(LPFFORMAT pFormat);
    	
    public:
    
    	//********************************************************************************
    	//funtion: DPrint()
    	//purpose: Contructs new Dprint object
    	//********************************************************************************
    	DPrint(int startx, int starty, int vertical_spacing, LPDIRECT3DDEVICE9 pdevice);
    	
    	
    	//********************************************************************
    	//function: TestPrint
    	//purpose:	Tests boundaries of a line of text, preparing to be written.
    	//returns:	An array of RECTs holding the calculated size of each character
    	//			in the text and the whole length of the text.
    	//********************************************************************
    	void TestPrintln(RECT* Rectarr, LPFFORMAT pFormat, char* str);
    
    
    	//*******************************************************************************************
    	//function:	CalcConcat
    	//purpose:	will return the least amount of letters that must be erased for a string in order
    	//			for that string to be concatenated with a new string and still fit in the pixel
    	//			limitations supplied.
    	//*******************************************************************************************
    	int CalcConcat(RECT* RectArr, char* bufout, char* bufin, int maxpixwidth, LPFFORMAT pFormat);
    
    
    	//*********************************************************************
    	//funtion: Println
    	//purpose: Will print a new line of text to screen
    	//returns: A reactangle holding the size of the text drawn
    	//*********************************************************************
    	void Println(RECT* Rectptr, D3DCOLOR fontColor, LPFFORMAT pFormat, char* str);
    
    
    	//*********************************************************************
    	//funtion: Print
    	//purpose: Will print text to the size of the RECT provided
    	//*********************************************************************
    	void Print(RECT* rbox, D3DCOLOR fontColor, LPFFORMAT pFormat, char* str);
    
    	
    	//*******************************************************
    	// function: DrawBox
    	// purpose: Will draw a box based on dimensions specified
    	// NOTE: Not mine. Leeched code.
    	//*******************************************************
    	void DrawBox(int x, int y, int w, int h, D3DCOLOR col);
    
    
    	//********************************************************
    	// function: TextBox
    	// purpose: Will try to draw text in the given RECT
    	// *******************************************************
    	void TextBox(RECT* Rectptr, RECT* FormatRect, string text, LPFFORMAT pFormat,  D3DCOLOR inside, D3DCOLOR border, D3DCOLOR textcol);
    
    
    //Font Functions
    	void DeleteUnusedFonts();
    	void DeleteFontsExcept(LPFFORMAT pFormat_arr[]);
    	void DeleteFont(LPFFORMAT pFormat);
    	void StopCheckingFonts();
    	void StartCheckingFonts();
    
    //Set Functions
    	void SetCursor(int newx, int newy);	//Set X and Y coords for text printing
    	void ResetCursor();
    	void Setvspc(int vertical_spacing);
    
    //Get Functions
    	int getx();
    	int gety();
    	int getvspc();
    
    //Resets Font Pointers
    	void PreReset();	//OnLostDevice
    	void PostReset();	//OnResetDevice
    
    //RECT HELPERS
    	static RECT* rectcpy(RECT* out, RECT* in); 
    	static int rectw(RECT* in);	//width
    	static int recth(RECT* in);	//height
    
    //TEXT HELPERS
    	// a bit misleading. Does not tick all the way through only to end of text. Does not loop.
    	static int TickerText(char* strin, char* strout, unsigned int constraint, int wait, int time); 
    
    };
    
    #endif
    Steal it. Leech it. Help me Improve it. I don't care. The benefit of sharing this code is greater then keeping it hidden.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  2. #2
    sam22's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Behind u
    Posts
    773
    Reputation
    33
    Thanks
    880
    My Mood
    Amazed
    u said u want to make into a dll not debug why don't u change the debug mode into realarse and hit compile. is that ur problem if not when get on my pc tomorow i will look at ur code

  3. #3
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    When I said debug I meant using a debugger to investigate where the exception is thrown. Try injecting the file into a test environment and you will see. I do wish it were that easy though. I examined all of my code including the massive arrays of font pointers, checking to see if each one was initialized, but I think it might be something deeper, such as a physical limit to the number of fontpointers I can create. I don't really know. no one has created this many before so I couldn't find any examples.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  4. #4
    Void's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Inline.
    Posts
    3,198
    Reputation
    205
    Thanks
    1,445
    My Mood
    Mellow
    [php]
    __asm
    {
    int 3h
    }
    [/php]

    Put that at the start of your main thread, run environment with loaded DLL in olly, start debugging?

  5. #5
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Simple solution, but I'll need to run it in a d3d enviroment or the errors won't come up.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  6. #6
    sam22's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Behind u
    Posts
    773
    Reputation
    33
    Thanks
    880
    My Mood
    Amazed
    Quote Originally Posted by why06 View Post
    When I said debug I meant using a debugger to investigate where the exception is thrown. Try injecting the file into a test environment and you will see. I do wish it were that easy though. I examined all of my code including the massive arrays of font pointers, checking to see if each one was initialized, but I think it might be something deeper, such as a physical limit to the number of fontpointers I can create. I don't really know. no one has created this many before so I couldn't find any examples.
    u meam u cant injecet it in d3 test envoiment it gave u an error right

  7. #7
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    yeh pretty much.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  8. #8
    sam22's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Behind u
    Posts
    773
    Reputation
    33
    Thanks
    880
    My Mood
    Amazed
    Quote Originally Posted by why06 View Post
    yeh pretty much.
    i cant help u now i am on my phone tomorrow i will

  9. #9
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    I've got a Droid. That shit is epic.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  10. #10
    sam22's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Behind u
    Posts
    773
    Reputation
    33
    Thanks
    880
    My Mood
    Amazed
    who is the moderter of this section i mean minion

  11. #11
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Hell_Demon. Speaking of which we should probably stop going or subject...

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  12. #12
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    DX base, add your shizzle to this and debug!
    Ah we-a blaze the fyah, make it bun dem!

  13. The Following User Says Thank You to Hell_Demon For This Useful Post:

    why06 (11-30-2010)

  14. #13
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Thanks HD. I'll load it up and see what happens. D:

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  15. #14
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    It's the absolute minimum that I could call DX base lol =P clears background to red and presents it =P shouldn't be too hard to add endscene call or whereever you draw =P

    beginscene()
    present()
    endscene()

    in the loop and then u can just hook endscene and do what you normally do, or integrate the code into the project w/o hooking =p
    Ah we-a blaze the fyah, make it bun dem!

  16. #15
    sam22's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Behind u
    Posts
    773
    Reputation
    33
    Thanks
    880
    My Mood
    Amazed
    Quote Originally Posted by Hell_Demon View Post
    It's the absolute minimum that I could call DX base lol =P clears background to red and presents it =P shouldn't be too hard to add endscene call or whereever you draw =P

    beginscene()
    present()
    endscene()

    in the loop and then u can just hook endscene and do what you normally do, or integrate the code into the project w/o hooking =p
    can you approve his attachment so i can see what kind erro he get and help him

Page 1 of 2 12 LastLast