Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lodepng crashes ntdll.dll #188

Open
mankrip opened this issue Apr 23, 2024 · 0 comments
Open

lodepng crashes ntdll.dll #188

mankrip opened this issue Apr 23, 2024 · 0 comments

Comments

@mankrip
Copy link

mankrip commented Apr 23, 2024

lodepng crashes the function ntdll!RtlUserThreadStart() from ntdll.dll when I try to create a PNG image.

This is my C code to save 8-bit indexed color screenshots. Lodepng.cpp was also renamed to .c to ensure C compatibility:

#include "lodepng.h"
void WritePNGfile (const char *filename, const byte *image, unsigned width, unsigned height)
{
	LodePNGState pngstate;
	byte *png;
	size_t pngsize;
	unsigned error;

	// initialize state data
	lodepng_state_init (&pngstate);

	// generate PNG palette
	for(int i = 0; i < 256; i++)
	{
		byte r = palette_screentint[i].r; // palette_screenbase
		byte g = palette_screentint[i].g;
		byte b = palette_screentint[i].b;
		byte a = (i == TRANSPARENT_COLOR) ? 0 : 255;

		// palette must be added both to input and output color mode, because
		// in this sample both the raw image and the expected PNG image use that palette.
		lodepng_palette_add (&pngstate.info_raw      , r, g, b, a);
		lodepng_palette_add (&pngstate.info_png.color, r, g, b, a);
	}

	// customize state
	// both the raw image and the encoded image must get colorType 3 (palette).
	pngstate.info_raw.colortype = LCT_PALETTE;
	pngstate.info_raw.bitdepth = 8;
	pngstate.encoder.auto_convert = 0; // we specify ourselves exactly what output PNG color mode we want
	pngstate.info_png.color.colortype = LCT_PALETTE; // if you comment this line, and create the above palette in info_raw instead, then you get the same image in a RGBA PNG.
	pngstate.info_png.color.bitdepth = 8;

	// encode and save
	error = lodepng_encode (&png, &pngsize, image, width, height, &pngstate);
	if (error)
		Con_Printf ("error %u: %s\n", error, lodepng_error_text (error));
	else
		lodepng_save_file (png, pngsize, filename);

	// finish
	lodepng_state_cleanup (&pngstate);
	free (png);
}

This code compiles without warnings, but crashes. When looking at the debug info, the only thing I got was the mention of ntdll!RtlUserThreadStart().

My program is single-threaded, and compiled with the TDM-GCC 32-bit x86 compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant