   SDL wont draw[solved]
  Im pretty sure i have had this problem before, and i posted here, and it got solved. Now i think im having that problem again and i have forgotten the solution.The problem is that SDL wont draw:. All the DLL's are in the right place. All the linker settings are in the right place.. The screen surface is not NULL. The image that im trying to draw's surface is not NULL. The drawing and image loading code is taken out one of my other projects that workedhere is my drawing function://www.lazyfoo.netvoid E_CORE::DrawImg(int x, int y, SDL_Surface *source, SDL_Surface *destination, SDL_Rect* clip = NULL){SDL_Rect offset;offset.x = x;offset.y = y;SDL_BlitSurface(source, clip, destination, &offset);}here is the image loading code://www.lazyfoo.netSDL_Surface* E_CORE::LoadImg(string filename){SDL_Surface* loadedImage = NULL;SDL_Surface* optimizedImage = NULL;loadedImage = IMG_Load(filename.c_str());//check for errorsif(loadedImage != NULL){//if there were no errorsoptimizedImage = SDL_DisplayFormat(loadedImage);SDL_FreeSurface(loadedImage);if(optimizedImage != NULL){//set the colour keyUint32 colorkey = SDL_MapRGB(optimizedImage->format, 255, 0, 255);SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY, colorkey);}}if(optimizedImage == NULL){cout << "Failed to load " << filename << endl;}else{cout << "Loaded " << filename << endl;}return optimizedImage;}the image is not all pink(colour keying colour).Please can someone help me[Edited by - Lith on May 13, 2010 11:25:51 AM]
  I can't see anything wrong. Do you call SDL_Flip to update the screen?   ;  Yes i do, also i check to see if it's failed and it doesnt:bool E_CORE::UpdateScreen(){if(SDL_Flip(ScreenPointer) == -1){cout << "Error Updating Screen\n";return false;}return true;};  If the code you pasted works in a different program then the error probably isn't there, so post the rest (or more) of the code :PDo you properly call SDL_SetVideoMode on ScreenPointer?   ;  SDL_BlitSurface() has a return code. Inspect it and print SDL_GetError() in the event of failure. This might be revealing.   ;  Okay, ill post my main:#include "E_CORE.h"#include "E_LUA.h"#include "SDL.h"#include <string>extern "C" {#include "lua.h"#include "lualib.h"#include "lauxlib.h"}using namespace std;#define WIDTH 640#define HEIGHT 480int main(int argc, char **argv){bool quit = false;SDL_Event Event;Uint8 *keystates;SDL_Surface* Screen = NULL;SDL_Surface* image = NULL;//InitializationE_CORE EngineCore;EngineCore.Init();EngineCore.ScreenInit(WIDTH,HEIGHT,false,"E_CORE rendering test");E_LUA EngineLUA;EngineLUA.Init();Screen = EngineCore.GetScreenSurface();Event = EngineCore.GetEventPointer();//load an imageimage = EngineCore.LoadImg("image.bmp");//execute a scriptEngineLUA.ExecuteScript("data/scripts/script01.lua");while(quit == false){//and update the keystates structkeystates = SDL_GetKeyState(NULL);//Process Input (RAW SDL)while(SDL_PollEvent(&Event)){if(Event.type == SDL_QUIT){quit = true;cout << "Exiting Main Loop\n";}}//Do Logic//RenderEngineCore.DrawImg(20,20,image,Screen,NULL);//update the screen with changes/*EngineCore.UpdateScreen();*/SDL_Flip(Screen);}cout << "Freeing Surfaces\n";SDL_FreeSurface(image);cout << "Calling E_LUA.End(\n)";EngineLUA.End();cout << "Calling E_CORE.End()\n";EngineCore.End();return 0;}E_CORE init code:bool E_CORE::Init(){//This will initialize everything that the core deals with:/*GraphicsSound*///Init SDLif(SDL_Init(SDL_INIT_EVERYTHING) == -1){//there was an error setting up SDLreturn false;}//Init TTF Libsif(TTF_Init() == -1){//there was a problem setting up TTFreturn false;}if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1){//there was an error setting up the audioreturn false;}//if we get here then everything went finereturn true;}E_CORE screen init code:bool E_CORE::ScreenInit(int width, int height, bool fullscreen, string caption){if(fullscreen == false){ScreenPointer = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE);if(ScreenPointer == NULL){return false;}}else{ScreenPointer = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE|SDL_FULLSCREEN);if(ScreenPointer == NULL){return false;}}//now we set the caption of the windowSDL_WM_SetCaption(caption.c_str(), NULL);return true;}i will try the things that rip-off said   ;  I put cout << SDL_GetError(); in all of the failed initialization things and blit surface, but they all didnt fail!Also i made it print out the return value of blitsurface, event if there want an error, and it was 0EDIT:im going to come back to this tommorow   ;  You know this forum keeps an history of your posts right? If this is really the same problem as before, here's your thread:http://www.gamedev.net/community/forums/topic.asp?topic_id=552650edit: Reading a bit, doesn't seems to be the same problem.   ;  What happens at runtime? Do you get a black window?If you do I'd try using SDL_FillRect on Screen and see if you can at least render that   ;  Try to reduce the code down to the essentials. For example, temporarily disable or comment out your Lua code. Likewise, you could use SDL_GetVideoSurface() as the argument to SDL_Flip(). Fill your code with assertions, particularly around pointers.Don't forget to try some other things to check, for example fill the screen with a random colour using SDL_FillRect() (and disable your image drawing).If you keep eliminating stuff, you will eventually find the error, or you will have a minimal program that you can post here and we can try it out.It might look something like this (quicky error handling here, just to demonstrate):#include <iostream>#include <stdexcept>#include "SDL.h"#include "SDL_image.h"void break(){   // Will bring the debugger up   int *ptr = 0;   *ptr = 42;}void checkError(int result){   if(result != 0)   {  break();   }}void checkError(void *pointer){   if(!pointer)   {  break();   }}int main(int, char **){    checkError(SDL_Init(SDL_INIT_VIDEO));    SDL_Surface *screen = SDL_SetVideoMode(800, 600, 32, SDL_ANYFORMAT);    checkError(screen);    SDL_Surface *surface = IMG_Load("image.bmp");    checkError(surface);    bool running = true;    while(running)    {   SDL_Event event;   while(SDL_PollEvent(&event))   {  if(event.type == SDL_QUIT)  { running = false;  }   }   checkError(SDL_FillRect(screen, 0, 0));   checkError(SDL_BlitSurface(surface, 0, screen, 0));   checkError(SDL_Flip(screen));    }}