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
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 09:43.


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