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

Archived

This topic is now archived and is closed to further replies.

Splat

Weird array problems

14 posts in this topic


well, you just ran into the #1 classic C error that alot of people make. Basically, you're indexing past the end of your array. Consider this :

you told VC++ to make 100 instances of your structure. Ok, it did that.

Now look at your for loop. You count from 0 to 100, inclusive. Well, if you count from 1 to 100, you get, 100. But counting from **0**, you get 101. (try counting to 10 on your fingers starting at 1 and 0 to verify this.) So you're indexing 1 past the end of your allocated space.

To fix this, change your loop to :

for (i = 0; i < 100; i++) {
myStructs[i].member1 = 0;
myStructs[i].member2 = 0;
}

basically, just remember : when starting at 0 you always want to have the stop condition be 1 less than the number of members you have allocated.

-- Remnant

0

Share this post


Link to post
Share on other sites
My God! Don't I feel foolish. I never was able to replicate this problem consistantly, so I always though it was the compiler. I guess another variable was allocated right at the end of my array so sometimes that last entry would go into the other variable. It's amazing: I ALWAYS though that int array[10] meant the upper bound was 10 and the lower bound was 0! All I can say is - Silly me!

I've never had anything in the form of instruction on ANY programming language, and I originally (8 years ago) became proficient in Visual Basic, where the number of entries was ALSO the upper bound!

Oh yeah, you can stop chuckling now hehe

- Splat

[This message has been edited by Splat (edited October 27, 1999).]

0

Share this post


Link to post
Share on other sites
hehe. S'ok, almost everyone has a similar blunder to tell about. Just be careful next time before you claim that the compiler is messing up.

-- Remnant

0

Share this post


Link to post
Share on other sites
If you've been polluted by VB, I can easily understand your confusion ... VB has the most perculiar implementation of arrays that I've ever seen.

/Niels

0

Share this post


Link to post
Share on other sites
Oh, about blunders, dig this:

In my game, I use an event system to tie the game code to the various (sound/graphics/network) engines. This works by having a base C++ eventlistener class with a virtual method that is implemented in the various subclasses that needs to know about the event (similar to the way it works in Java).

Very neat.

However, all of a sudden I started getting these very strange null pointer exceptions in my event handling - apparently the compiler failed to overload the virtual method in the sub classes. Or not.

The problem as it turned out, was a small macro I had created to avoid uninitialized data in my classes:

#define init(class) { ZeroMemory(this,sizeof(class)); }

Guess what, virtul methods in C++ are really invisible member variables, clearing the class also clears the virtual functions.. Doh!

/Niels

0

Share this post


Link to post
Share on other sites
That's really interesting! I guess C++ stores the virtual function table IN the class data. There might be interesting uses of that, like manually overloading a function in runtime.

Oh yeah. Niels: Yeah, I haven't programmed in VB for some time now - It's nice for real quick Windows application development, but C++ can be and most of the time is SO much better than everything I've ever programmed in

- Splat

[This message has been edited by Splat (edited October 28, 1999).]

0

Share this post


Link to post
Share on other sites
Before you get too addicted to C++, check out Java - it's a much much better language. It's not quite as fast, but it IS getting there (and it IS WAY BEYOND VB)...

(I have a feeling it would be ultimate for writing game code, I.e. do the engine in C++/asm whatever, put it in a DLL, and then use Java to glue it all together)...

/Niels

0

Share this post


Link to post
Share on other sites
I had a relatively bad experience with Java. I used it for a while, but it was slow (before JIT compilers) so I stopped. Now, I think that when I'm done my game engine in might just write games in Java. One question, off topic: Can you compile a Java application into platform-specific executables? Kinda like funneling off the JIT compiler output into an EXE file? That would be great, and remove my last qualm about programming a real application in Java.

- Splat

0

Share this post


Link to post
Share on other sites
Yes, you can.

However, I think that in a few years we'll be in a situation where we'll see bytecode that out performs precompiled code.

The reason is simple: Bytecode can be optimized on-the-fly to fit the exact architecture of the machine it is running on (I.e. Anything from processor, memory size and cache to bus speed and various addon hardware (DSP, GPU etc.) can be considered during optimization - something you can't do in precompilation, unless you want 5000 different executables)

And because of the extremely strict rules that the bytecode adhere to, it is much easier to optimize than e.g. C++.

SUN's hotspot compiler is the first preview of the capabilities of this awesome technology!

/Niels

0

Share this post


Link to post
Share on other sites
That will certainly be cool. However, my reason for wanting to be able to create Java executables is more for esae of use and install:

I don't want to have to install a Java interpreter and then run my program through the interpreter. I'd rather just be able to click on an EXE file and it will start up.

I'm not sure about the size of the bytecode interpreter, but what might be cool is to in the future attach the interpreter to the bytecode in such a way that basically running the EXE runs the interpreter to load the attached bytecode and run it.

Enough blabbering.

- Splat

0

Share this post


Link to post
Share on other sites
Since you talk .exe's I assume you are targeting the windows platform - Any windows platform with IE (or NS for that matter) installed WILL also have the Java run-time installed (Unless they went through a lot of trouble to get rid of it ).

If you want to get a better idea of whats possible in pure Java today, check out demos such as "forward" (I think it's by "komplex" or something like that, might be wrong tho')...

Their new stuff is at (haven't seen it yet):

ftp://ftp.scene.org/pub/incoming/ASSEMBLY99/java/

/Niels

0

Share this post


Link to post
Share on other sites
This is a reply to an earlier question from Splat. The latest version of the GNU C/C++ compiler (version 2.95) comes with a Java compiler that can generate native code for a lot of platforms, including Windows. And its free! I've looked at the code it generates and its quite good. That was for an ARM processor mind you!

Lastly, anyone interested in fast Java VMs should check out Sun's Hotspot VM. It figures out which part of your code should be compiled and which should be interpreted at runtime.

0

Share this post


Link to post
Share on other sites
Ok, this has been bugging me for a while and I'm pretty sure it's Visual C++ screwing up but here it goes:

I have a class defined as follows:

class ... {
public:
....
private:
struct ... myStructs[100];
}

Ok, now, I initialize the variables in another function.

void ...::Initialize() {
int i;
for (i = 0; i <= 100; i++) {
myStructs[i].member1 = 0;
myStructs[i].member2 = 0;
}
}

Ok, here's where it really screws up: When the program quits, it tells me "HEAP[GameTest.exe]: Heap block at 008C6F20 modified at 008C7558 past requested size of 630"

Now, I've found 2 ways to fix this: One is to increase the array size by 1, and NEVER touch that last entry. The second is to not touch the "member2" member of the structure. Either one will avoid the heap overflow.

I have encountered variations of this problem before in Visual C++. Even without structures, with simple int arrays.

WTF is going on?!?!?!?! Is Visual C++ not allocating enough space for scoped arrays??

I can avoid it for now with the additional element at the end of the array, but I would REALLY REALLY REALLY like to know why this is happening to me.

- Splat

[This message has been edited by Splat (edited October 26, 1999).]

0

Share this post


Link to post
Share on other sites