• 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
F1rst_Unicorn

2 parameters having same address

8 posts in this topic

hey everyone, 

I have encountered a quite strange error. I have been working on my first little rpg and had never a problem with this function before

but since having made several changes in other positions my args width and height in init_system(int, int) are not defined correctly (having undetermined values) and also have the same address in memory-.-

 

EDIT: I'm using MS VC++ 2010 and ALLEGRO 5.0.8 for my program. 

 

Here the main file, other files may follow as necessary:





#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5\allegro_image.h>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include "GraphicsLibrary.h"
#include "Tile.h"
#include "Player.h"


using namespace std;

#define FPS 60


int init_system(int, int);
void tidy_up();
void drawScene();
void check_key(int);
void proceed_key();

ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
ALLEGRO_TIMER *timer = NULL;
bool keys[ALLEGRO_KEY_MAX];

Tile *currentRegion;
Player *player;
const int SCREEN_WIDTH = 1920;
const int SCREEN_HEIGHT = 1080;

int main(int argc, char *argv[])
{

	bool redraw = true;
   
    if (init_system(1920, 1080) == -1){
		system("pause");
	    return -1;
	}
	

    while(1){
	   ALLEGRO_EVENT ev;
	   al_wait_for_event(event_queue, &ev);

	   if (ev.type == ALLEGRO_EVENT_TIMER){
		   redraw = true;
	   }
	   else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
		   break;
	   }
	   else if (ev.type == ALLEGRO_EVENT_KEY_DOWN){
		   check_key(ev.keyboard.keycode);
	   }

	   if (redraw && al_is_event_queue_empty(event_queue)){
		   redraw = false;
		   drawScene();
		   al_flip_display();
	   }

	   proceed_key();
	   al_rest(0.01);

	}


	
	tidy_up();
}



int init_system(int width, int height){

	if(!al_init()) {
      fprintf(stderr, "failed to initialize allegro!\n");
      return -1;
   }
 
	if (!al_install_keyboard()){
		fprintf(stderr, "failed to initialize the keyboard!\n");
		return -1;
	}
 
	if (al_show_native_message_box(display, 
		"3DPogramming", 
		"Fullscreen", 
		"Do you want to launch in fullscreen mode?", 
		NULL, 
		ALLEGRO_MESSAGEBOX_YES_NO) == 1)
			al_set_new_display_flags(ALLEGRO_FULLSCREEN);


   display = al_create_display(width, height);
   if(!display) {
      fprintf(stderr, "failed to create display!\n");
      return -1;
   }
 
    event_queue = al_create_event_queue();
    if (!event_queue){
	    fprintf(stderr, "failed to create event queue!\n");
	    al_destroy_display(display);
	    return -1;
    }

    timer = al_create_timer(1.0 / FPS);
    if (!timer){
	    fprintf(stderr, "failed to create timer!\n");
	    al_destroy_display(display);
	    al_destroy_event_queue(event_queue);
    }

	if (!al_init_image_addon()){
		fprintf(stderr, "failed to init image addon!\n");
		al_destroy_display(display);
		al_destroy_event_queue(event_queue);
		al_destroy_timer(timer);
	}
   
    al_register_event_source(event_queue, al_get_display_event_source(display));

    al_register_event_source(event_queue, al_get_timer_event_source(timer));

    al_register_event_source(event_queue, al_get_keyboard_event_source());

    al_start_timer(timer);

	GraphicsLibrary::create();
	
	currentRegion = new CapitalCity();
	player = new Player();

    return 0;
}

void tidy_up(){
	al_destroy_timer(timer);
	al_destroy_display(display);
	al_destroy_event_queue(event_queue);
	al_shutdown_image_addon();
	exit(0);
}

void drawScene(){
	currentRegion->drawGround(player->getX(), player->getY());
	player->draw(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);



}

void check_key(int kc){
	keys[kc] = true;

	return;
}

void proceed_key(){
	if (keys[ALLEGRO_KEY_ESCAPE]){
		keys[ALLEGRO_KEY_ESCAPE] = false;
		tidy_up();
	}
}




Edited by F1rst_Unicorn
0

Share this post


Link to post
Share on other sites

What problem are you having? The values you pass are literals so shouldn't have the same address. However, if you never take the address the compiler may never allocate storage for them and they may not display the correct values in the debugger.

 

If you force the compiler to evaluate the literals e.g. printing them out, taking their address and doing something with them you may get different results.

0

Share this post


Link to post
Share on other sites

I discovered this as the root of my runtime crash. when trying to create a fullscreen display with e.g. 18361474x18361474 px it simply does nothing.

So I debugged the program step by step and tried to change the values of width and height on runtime inside the debugger. When changing one of the two

the other changes simultanously and so i found out using the debugger they have the same address in the stackframe of the function init_system(int, int). 

And my question is: why?!?! that's simply not possible

So my two problems are:

1. undetermined value of width and height

2. same address in memory

0

Share this post


Link to post
Share on other sites

Something might be corrupting the stack pointer. If the stack pointer is pointing at a bad location, the operating system might throw an exception error and neither value could be determined.

 

Using the stack frame, the compiler would know to look at the next sack position for height, so that doesn't make sense. I can't remember what order the parameters are pushed but you would end up with something like this on the stack:

sp-12: height

sp-8: width

sp-4: saved PC

 

If it was just referring to the same value, it should show 1920 for both.

 

Another idea, if you're compiling in release mode, you can't trust what the compiler is showing you. Optimization can make it hard for the debugger to determine where things are pointing.

Edited by cdoty
0

Share this post


Link to post
Share on other sites

that's what I thought as well

 

I actually am compiling in release mode, so that means I cannot take the debugger information for absolutely true?

Then the error may be at a completely different location...

0

Share this post


Link to post
Share on other sites

when using the debug mode the debugger and the program work without any problems. and since having worked on other issues the release mode also works as wanted^^

thanks for that hint :)

0

Share this post


Link to post
Share on other sites
Turn warnings to level 4 in the project settings and fix everything suspicious. Ice had some bugs because nonstandard extensions were used by the compiler, although it worked well at first.
0

Share this post


Link to post
Share on other sites

One thing that does tend to be visible to the debugger in release mode is global variables. It can be helpful to copy things you want to see into a global temporarily to help debug them. If you want to be really sure make the globals volatile so the compiler can't optimize away the writes to them.

 

Also be aware that in release mode uninitialized variables will have a different value to debug. The compiler will generally catch that problem for local variables and issue a warning, but it probably won't for class members, or anything allocated from the heap.

 

If that doesn't help you're going to want to learn to read disassembly so you can work out which register or memory address the compiler has put the data you want to see in. There's a guide to that at: http://www.altdevblogaday.com/2013/05/03/cc-low-level-curriculum-part-11-inheritance/ (that article has links to most of the parts, but you want to start with part 1).

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