I'm getting a strange issue when calling a member function of a class I've defined. I'm trying to do Perlin Noise and writing to screen using SDL in Visual C++ 2005.
The main code is
Code:#include <cstdio> #include "gfxcore.h" #include "sdl/sdl_opengl.h" #include "Level.h" #include "terrain.h" #ifdef _MSC_VER /* Visual C++ pragmas */ #pragma comment (lib, "opengl32") #pragma comment (lib, "glu32") #pragma comment (lib, "sdl") #pragma comment (lib, "sdlmain") #pragma comment (lib, "zdll") #endif int main(int argc, char** argv) { CGfxcore* gfxc = new CGfxcore(); if (!(gfxc->initialize(640,480,32))) { printf("Error initializing SDL\n"); delete gfxc; return -1; } CTerrain * tr = new CTerrain(384); tr->generatePerlinNoise ( 4, 0.1 );
The call marked in bold is where I'm getting problems (I pass e.g. 4 as first parameter, but the member function reads garbage like 498512 instead of 4!!!). The member functions as well as constructors/destructors of CTerrain class are:
TERRAIN.H
terrain.cpp follows...Code:#pragma once #include "sdl/sdl.h" // class for generating square terrains class CTerrain { public: CTerrain(void); CTerrain(int sq_size); ~CTerrain(void); void generatePerlinNoise (int n_oct, double pp); unsigned char* getPixelData () { return this->pixeldata; }; private: unsigned char* pixeldata; int tsize; // terrain square size };
What I was thinking is that the SDL.DLL library is corrupting my own program memory, but I think it runs on another memory space. Anyone tried luck with Visual C+SDL?Code:#include "Terrain.h" #include "Utility.h" #include <cstdio> CTerrain::CTerrain(void) { } CTerrain::~CTerrain(void) { delete[] pixeldata; } CTerrain::CTerrain(int sq_size) { // terrain size must be power of 2 if (sq_size && !(sq_size & (sq_size - 1))) printf ("WARN- CTerrain size %d - must be power of 2\n", sq_size); tsize = sq_size; pixeldata = new unsigned char[sq_size*sq_size]; } // perlin noise generation function // parameters: // n_oct - octaves // pp - persistence (defines frequency/amplitude for each octave) void CTerrain::generatePerlinNoise(int n_oct, double pp) { // HERE I'M GETTING GARBAGE VALUES FROM n_oct PARAMETER // However... pp is ALWAYS correct. }
Thank you very much.




Reply With Quote