Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

127 Neutral

About Axenation

  • Rank
  1. Axenation

    [SDL] Destructor Not Working

    I'll elaborate more on what AP above said so you can fully understand why your program is crashing. Here is what your constructor / destructors should look like with comments as to why I did what I did. // constructor Label() { // txt is a pointer to an SDL_Surface. All pointers, // when created, point to a random place in memory, // anywhere from memory address 0x00000000 to 0xFFFFFFFF. // Memory address 0 (0x00000000) is kinda reserved and // no valid pointer will ever point to memory address 0. // // Always initiate pointers to zero when you create them, // and when you free them point them back to 0. This way // you can check to see if the pointer points to memory // address 0. If it points to zero the pointer is invalid, // else if a valid pointer (unless its a hanging pointer). // When you free memory allocated to a valid pointer, but // forgot point it to memory address zero then its now // points to invalid data - this is called a hanging pointer. // Hanging pointers and pointers pointing to memory address // will crash your program if you try access memory they point // to txt = 0; // same thing as above but points to a TTF_Font font = 0; } // destructor ~Label() { if (txt != 0) { SDL_FreeSurface(txt); txt = 0; } if (font != 0) { TTF_CloseFont(font); font = 0; } } and here's psuedo code describing the different states of pointers durecing creation and destruction. Object* pointer; // pointer points to random memory // and is invalid and could be // considered a hanging pointer pointer = 0; // not points to memorey address 0x00000000 pointer = new Object(); // attempt to create a object if (pointer == 0) // unable to create Object() { printf("unable to create object"); // do some error handling here return; } else // else pointer points to a valid Object() { pointer->SayHello(); } if (pointer != 0) // if pointer is valid { delete pointer; // delete memory allocated to pointer // please take note that pointer is // now considered a "hanging pointer" // because it points to invalid data. // Any call on pointer will now crash // the program. EX: SDL_FreeSurface() pointer = 0; // point pointer to memory // address 0x00000000 // no longer a hanging pointer ^_^ } hope can make sense of my jabbering ^_^.
  2. Axenation

    SDL Help

    Quote:Original post by Will F Example: you create an array with 5 elements, then try to assign a value to the 7th element, you'll get a segmentation fault because you are trying to write to memory you aren't allowed to (the array only has 5 elements). That wont create a SDL segmentation fault unless you read/write beyond the programs allocated memory, but that's a rare bug. It usually wont crash a program but instead will create completely random bugs that are impossible to find. When i had one of these such bugs it seriously took me three months to find out that my map class was changing my characters names in my game. here's what i think you should always do to prevent bugs. 1. ALWAYS initiate pointers to zero. and always check to see if they are zero (NULL). This probably your problem. 2.use smart pointers for pointers that are tossed around alot in your program. 3.create a debug mode array class that checks and makes sure you arent tryign to access data outside of your array.
  3. Axenation

    [SDL] VRAM, RAM & transparency

    I've been down this road before. Your original surface is colorkeyed, so when you blit it onto the second surface it only blits the non-colorkeyed pixels. The colorkeyed pixels will be black or randomized on your destination surface. You have to turn off colorkeying when copying surfaces. psuedo code function CopySurface(origSurface, destSurface) { origColorKey = origSurface->colorkey; turnOffColorkey(origSurface); blitSurface(origSurface, destSurface) // set colorkey origSurface->colorKey = origColorKey; destSurface->colorKey = origColorKey; }
  4. Axenation

    hxRender Libraries Fail to Link

    guess i forgot about this page. It has 3rd party drivers on it. ps. sorry if i went a bit more off topic.
  5. Axenation

    hxRender Libraries Fail to Link

    Quote:Original post by PnP Bios I can barely get it to run at all on my voodoo3. Are you running WinXP? If so there arent any drivers for 3dfx cards, i know because an 8mg AccelStar card that i bought for $3.00 ran circles around my voodoo5. btw is there any more tuts/code we can look at other than the rotdemo?
  6. Axenation

    Lighting in 2D Game

    Irrlicht, is a simple to use 3D graphics engine that is great for 2d development. I belive it has a Java binding somewhere. You may want to check it out too.
  7. Axenation

    Lighting in 2D Game

    NickyP101, if you dont want to switch over to OpenGL just yet you can try to do light calculations yourself in software. I dont know a whole lot about Java, so i dont know what the API calls are to do this kind of stuff, But atleast ill try to push you in the right direction. If you have access to the actual pixels of each tile, then you could lighten and darken everything yourself at global light changes. Here is a link to Lode's site which will explain in detail how to do this in C. Since you know Java it shouldnt be hard to understand whats goin on in the C code. What i personally would do is have a global light variable ranged from something like negative forty (dark) to positive forty(light). You could then have a function that changes the light var, and the lighting on your tiles every so many clock ticks. pseudo code const Integer DARKEST = -40; const Integer LIGHTEST = +40; const Integer DARKER = -2; const Integer LIGHTER = +2; Integer g_globalLight = 0; Boolean g_isGettingDark = True; Function ApplyLightChange(Tileset tileset, Integer GlobalLight) { for (each tile in tileset) { Pixel = Tile.GetPixels(); for (each pixel in tile) { Pixel.Red += g_globalLight; Pixel.Green += g_globalLight; Pixel.Blue += g_globalLight; } } } Function CalcLightChange() { Static nextUpdateTime = 0; // update global light every 1000 miliseconds if (System.GetTime() is GreaterThan nextUpdateTime) { nextUpdateTime = System.GetTime() + 1000; if (g_isGettingDark() Equals True) { g_globalLight += DARKER; if (g_globalLight <= DARKEST) g_isGettingDark = false; } else { g_globalLight += LIGHTER; if (g_globalLight >= LIGHTEST) g_isGettingDark = true; } ApplyLightChange(tileset, g_globalLight); } } goodluck.
  8. You're adding new memory each frame, which mean's C# garbage collection is eventually going to start swapping new memory for old memory each loop. You may even be hitting a hardware memory max, which mean's new memory will be allocated on your harddrive as virtual memory.
  9. Axenation

    SDL Class Destuctor

    Your variable "image" is a pointer to an object. Now, your problem was you were not initializing the pointer to zero during intialization (construction), thus being set to "random gibberish" (instead of zero). In your destructor you were checking if the pointer was a valid pointer (ptr != null is the same as pointer != 0), so execution was flowing through that statement (because "random gibberish" rarely ever equals zero) and attempting to free some random memory (at memory address "random gibberish") instead of a valid surface address. A basic rule of thumb is to set all pointers to zero during initialization. Hope you caught what i said, goodluck :-)
  10. Axenation

    Huge Game Worlds

    I believe Ultima Online used the sector-based approach on it's maps. One of the maps was something 6500x4500, and now there are an additional 4 or 5 other maps which are each much smaller than the first. So if you're going big I'd say use sectors.
  11. [EDIT - same thing as MaulingMonkey's post, as i did not read it first] Simple work-around : passing parameters by reference ---------------------------------------------------- Here's some example functions I use for reading/writing size dependant data to a stream. void Stream::serialize(Sint8 data) { (Sint8&)m_buffer[m_size++] = data; } void Stream::serialize(Uint16 data) { (Uint16&)m_buffer[m_size] = data; m_size += 2; } void Stream::deserialize(Uint8& data) { data = (Uint8&)m_buffer[m_pos++]; } void Stream::deserialize(Uint16& data) { data = (Uint16&)m_buffer[m_pos]; m_pos += 2; } int main(int argc, char* argv[]) { Uint8 d1 = 2, d2 = 6; Uint16 d3 = 738, d4 = 4000; Stream s; //write data to the stream s.serialize(d1); //writes 1 byte to the stream s.serialize(d2); //writes 1 byte to the stream s.serialize(d3); //writes 2 bytes to the stream s.serialize(d4); //writes 2 bytes to the stream //set everything back to zero d1 = d2 = 0; d3 = d4 = 0; //read data from the stream s.deserialize(d1); //reads 1 byte from stream into d1 s.deserialize(d2); //reads 1 byte from stream into d2 s.deserialize(d3); //reads 2 bytes from stream into d3 s.deserialize(d4); //reads 2 bytes from stream into d4 //print debug info to the console printf("d1 = %i\n", d1); printf("d2 = %i\n", d2); printf("d3 = %i\n", d3); printf("d4 = %i\n", d4); }
  12. Axenation

    SDL slow on my machine - why?

    Post your code please. There's many things that can cause this that arent obvious. A few things that come to mind are... 1. The bit depth setting, considering your set up you should be doing 32 bit no matter what, using anything else can dramatically effect frame rates. 2. Use the SDL_GetVideoInfo() function before and after you create the display surface and see if any thing looks strange there. On my old computer I kept trying to set the video surface as 32-bit, but for some reason could only support 8, 16, and 24. SDL was forcing the display to 24-bit causing a tremendous bottle neck in the blitting. I figured that out with SDL_GetVideoInfo(). 3. Probably not worth mentioning but, do you have any other programs running that could be eating up the CPU? 4. When you call SDL_FillRect() does it return 0 or -1? Do you check the return codes on all other applicable functions?
  13. Axenation

    Guitarists: Help! I sound terrible

    Judging from what you said, I would say... 1. You may be bending the string while you press it to the fret, usually due to improper thumb positioning. 2. You may be pressing down on the string too hard forcing it to bend over the fret. Unless you're guitar is junk or you have an average priced acoustic, it should require very little effort to press the string to the fret. 3. You may have the guitar tuned too low easly causing #2 (above). Good luck, and happy shredding :-)
  14. Axenation

    knowledge needed for a general programming job?

    Thanks, everyone, for the replies. Ok, so more or less I need schooling. So for the highest salary do you suggest taking Software Enginering or Computer Science? Personally, I'm more intersted in computer science, but we all know money is devil. Should I also focus on something like Buisness Management (yuck!) to get a higher salary? What are expected salaries? MOST of the people i know have graduated college, and have found it impossible to find decent jobs. What would the chances be for me to not find a job after getting a degree? Sorry for asking so many questions, and thanks again to everyone for your time.
  15. What i want to know is how much knowledge is required to get a general (non-game) programming job, as i don't really want to pay for a college degree if i don't have to. What languages should i know? I have a good grasp of C++, C for the most part, and some x86 assembly. I'm guessing i will need to learn C#. What about OS specifics? I just started learning the win32 api, I know that's important. Should i set up another box and install Linux or something? Or should i start saving for school.
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!