Memory Corruption Error

Jul 30, 2011 at 12:14 AM
Edited Jul 30, 2011 at 12:15 AM

Hi,

I was wondering if any of you have encounted any sort of memory corruption errors: I'm testing out the CharLS 1.0 engine by itself (since I was having issues with another program that was calling it) and wrote my own little test program that generates frames filled with random numbers from certain ranges. CharLS seems to work fine for certain ranges (like 90 to 245) but gives me a "Run Time Check Failure #2, stack around orig_data[my variable name] was corrupted" and it throws JLS_ERRORs for other ranges (like 0 to 255). I believe I called the methods correctly, but correct me if I didn't. Any help with this would be appreciated- thanks!

Yuki

(Below is my test program)

//
// main.cpp - test new CharLS engine 
// 
#define CHARLS_DLL
#include "interface.h"

#include <fstream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <iostream>

int main(int argc, const char* argv[]) {
	
	
	for(int curr = 1; curr <= 3; curr++) { 
	

	JlsParameters m_params = JlsParameters();	
	m_params.height = 640;
	m_params.width = 480;
	int m_depth = 8; 
	m_params.allowedlossyerror = 0;
	m_params.outputBgr = false;

	assert((m_depth >= 2  &&  m_depth <= 16) || m_depth == 24);
	
	if( 24 == m_depth ){  // color
		m_params.components = 3;
		m_params.bitspersample = 8;
		m_params.ilv = ILV_LINE; 
		m_params.outputBgr = true; 
	}
	else{
		m_params.components = 1;
		m_params.bitspersample = m_depth;
		m_params.ilv = ILV_NONE;  
	}

	


	enum {FRAME_SIZE = 640 * 480};
	unsigned char orig_data[FRAME_SIZE];
	unsigned char encoded_data[FRAME_SIZE];
	unsigned char decoded_data[FRAME_SIZE]; 


	//create random numbers to fill frame
		int low_num = 90;
		int high_num = 255;
		for (int t = 0; t < FRAME_SIZE; t++) {
			int num = (rand() % (high_num- low_num + 1)) + low_num;
			orig_data[t] = (unsigned char) num;
		}
	
	size_t cbyteCompressed = 0;	

	JLS_ERROR err1 = JpegLsEncode(encoded_data, sizeof(encoded_data), 
    &cbyteCompressed, orig_data, sizeof(orig_data), &m_params);

	JLS_ERROR err2 = JpegLsDecode(decoded_data, sizeof(decoded_data), 
    encoded_data, sizeof(encoded_data), &m_params);
	

	if(err1 != OK) {
		printf("JPEGLSENCODE has wrong parameters!\n");
		std::cout << err1 << "\n";
	}
	if(err2 != OK) {
		printf("JPEGLSDECODE has wrong parameters!\n");
		std::cout << err2 << "\n";
	}



	}
}