Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old April 3, 2018, 14:34   #1
Gordon
Scout
 
Join Date: Jan 2010
Posts: 31
Gordon is on a distinguished road
Solution for Angband crash on startup when compiled with Visual Studio

Symptoms:

Birth screens work fine, but Angband crashes with an access violation code 0xc0000005 in ntdll.dll just after displaying "Please wait..." in ui_leave_init().

Problem:

Shortly after calling ui_enter_world(), Term_xtra(TERM_XTRA_REACT, 0) is called which then calls init_graphics() in main-win.c This calls ReadDIB2_PNG() in readpng.c to read in the graphic tiles. The crash occurs when png_read_info(png_ptr, info_ptr) is called at line 102.

Solution:

libpng12.dll is multi-threaded and so requires Angband to be compiled with support for multi-threaded dlls. To do this you must set Use run-time library to Multithreaded DLL under Code Generation on the C/C++ tab in Project Settings. This causes the /MD flag to be set in the project Makefile.

Testing Environment:

Angband Version: 4.05
OS Version: Windows XP SP3
Visual Studio Version: 6.0 SP6

This very important detail should be added to angband_visual_studio_step_by_step.txt.
Gordon is offline   Reply With Quote
Old April 6, 2018, 19:54   #2
Gordon
Scout
 
Join Date: Jan 2010
Posts: 31
Gordon is on a distinguished road
Well, it seems that this doesn't work with Visual Studio 2008. I found an alternate solution that seems to work in both Visual Studio 6.0 and Visual Studio 2008. This requires modification of readpng.c. At the beginning of the file, we need to add a function that forces libpng to use our runtime version of fread() instead of the one it was compiled with:

Code:
/** 
 * Forces libpng to use the version of fread() from the run time library 
 * that this program was compiled with.
 */
void ReadFileFunc(png_structp png_ptr, png_bytep data, png_size_t length) {
	FILE *file = (FILE *)png_get_io_ptr(png_ptr);
	fread(data, sizeof(png_byte), length, file);
}

/**
 * Imports a DIB from a PNG file. Once
 * the DIB is loaded, the function also creates a bitmap
 * and palette out of the DIB for a device-dependent form.
 *
 * Returns TRUE if the DIB is loaded and the bitmap/palette created, in which
 * case, the DIBINIT structure pointed to by pInfo is filled with the
 * appropriate handles, and FALSE if something went wrong.
 */
BOOL ReadDIB2_PNG(HWND hWnd, LPSTR lpFileName, DIBINIT *pInfo, DIBINIT *pMask, BOOL premultiply) {
Then in the body of ReadDIB2(), replace these lines:

Code:
	/* setup error handling for init */
	png_init_io(png_ptr, fp);
	png_set_sig_bytes(png_ptr, 8);
	
	png_read_info(png_ptr, info_ptr);
With these:

Code:
	/* setup error handling for init */
	png_set_read_fn(png_ptr, fp, ReadFileFunc);	
	png_set_sig_bytes(png_ptr, 8);
	
	png_read_info(png_ptr, info_ptr);
Testing Environment:

Angband Version: 4.0.5
OS Version: Windows XP SP3, Windows 7 SP1 64 bit
Visual Studio Version: 6.0 SP6, 2008 SP1
Gordon is offline   Reply With Quote
Old December 17, 2019, 05:39   #3
eastwind
Apprentice
 
Join Date: Dec 2019
Location: Mexico, undisclosed location
Posts: 79
eastwind is on a distinguished road
still a bug, fix still good

I've been working to get a build with VS 2019. I hit this bug after character rolling, just as described. My project was using /MDd for the debug configuration (same as /MD except with debug crt library), so I applied the code fix in the second post and it fixed the bug.

So I can verify that
1) the bug is still there,
2) /MD still doesn't fix it
3) the code fix does still fix it.

Thanks for the fix Gordon!
eastwind is offline   Reply With Quote
Old December 17, 2019, 11:11   #4
Nick
Vanilla maintainer
 
Nick's Avatar
 
Join Date: Apr 2007
Location: Canberra, Australia
Age: 55
Posts: 8,457
Donated: $60
Nick will become famous soon enough
Thanks, I've filed this and your other recent fix as bugs to be fixed (well, I've filed bugs, which the aforementioned are the fixes for).
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.
Nick is offline   Reply With Quote
Old December 17, 2019, 22:42   #5
eastwind
Apprentice
 
Join Date: Dec 2019
Location: Mexico, undisclosed location
Posts: 79
eastwind is on a distinguished road
I've created a github account and made a local clone (as opposed to just downloading the src zip), so I'm getting closer to being able to submit bugs and fixes myself.
eastwind is offline   Reply With Quote
Old January 4, 2020, 03:44   #6
eastwind
Apprentice
 
Join Date: Dec 2019
Location: Mexico, undisclosed location
Posts: 79
eastwind is on a distinguished road
screenshot crashes

Something is still not right in png-land for windows (VS compiler). Running with the above fix applied, I tried to take a screenshot, and Angband exited with code 3. No popup, no exceptions. I debugged it, and png_write_image or something it calls within the same dll is calling abort().

It's dying in this code from SaveWindow_PNG:

Code:
		SelectObject(hDC, hbmOld);
		DeleteObject(hbmScreen);
		DeleteDC(hDC);
	}  

	/* Write the file */
	if (noerror) {
		png_write_image(png_ptr, row_pointers);  /* <=== dies here */
		png_write_end(png_ptr, NULL);
	}

	/* Release the image memory */
	for (y = 0; y < height; ++y)
		free(row_pointers[y]);
	free(row_pointers);
I don't have symbols for libpng12.dll, but I haven't tried real hard to find them. I stepped through the assembly for a while, just to exercise old fading skills. It's getting into the function, doing some stuff, and gets to a loop that is supposed to iterate 692 times - and 692 is the 'height' from screenshot.c. It iterates that loop about 420 times before calling abort() from a libpng subroutine called out of that 'screen height' loop.

With the particular save game, and with the exact same term window setup, it was repeatable at that same 420 iterations point.

Then I gave up and went to bed.

The obvious workaround is don't take screenshots using the in-game function, just use the windows screenshot function.
eastwind is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with compliing Angband with Visual Studio 2016 Nekoninja Development 2 August 21, 2016 23:34
Visual Studio challenges jeritind Development 4 January 1, 2014 19:26
Visual Studio 2010 Express, help for the newbie? Chud Development 12 June 14, 2013 22:40
3.3.0 crash on startup Chud Vanilla 6 September 20, 2011 18:17
Visual Studio 2008 - building 32 & 64 bit now! LanceDiamond Development 5 April 25, 2009 13:59


All times are GMT +1. The time now is 19:54.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.