2006-03-20 16:43:15 +00:00
/*
2014-06-01 17:55:23 +00:00
* Portions of this file are copyright Rebirth contributors and licensed as
* described in COPYING . txt .
* Portions of this file are copyright Parallax Software and licensed
* according to the Parallax license below .
* See COPYING . txt for license details .
2006-03-20 16:43:15 +00:00
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ( " PARALLAX " ) . PARALLAX , IN DISTRIBUTING THE CODE TO
END - USERS , AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN , GRANTS A
ROYALTY - FREE , PERPETUAL LICENSE TO SUCH END - USERS FOR USE BY SUCH END - USERS
IN USING , DISPLAYING , AND CREATING DERIVATIVE WORKS THEREOF , SO LONG AS
SUCH USE , DISPLAY OR CREATION IS FOR NON - COMMERCIAL , ROYALTY OR REVENUE
FREE PURPOSES . IN NO EVENT SHALL THE END - USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE - BEARING PURPOSES . THE END - USER UNDERSTANDS
2013-02-24 02:39:48 +00:00
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE .
2006-03-20 16:43:15 +00:00
COPYRIGHT 1993 - 1998 PARALLAX SOFTWARE CORPORATION . ALL RIGHTS RESERVED .
*/
2008-01-23 17:25:09 +00:00
2006-03-20 16:43:15 +00:00
/*
*
* Header for error handling / printing / exiting code
*
*/
2014-12-07 23:43:51 +00:00
# pragma once
2008-01-23 17:25:09 +00:00
2022-02-12 18:57:12 +00:00
# include <cassert>
2015-10-09 02:46:11 +00:00
# include <cstddef>
2022-02-12 18:57:12 +00:00
# include <cstdio>
2022-09-24 17:47:53 +00:00
# include <span>
2016-03-19 19:08:10 +00:00
# include "dsx-ns.h"
2022-02-12 18:57:12 +00:00
# include "fmtcheck.h"
2008-01-23 17:25:09 +00:00
2015-12-13 18:00:49 +00:00
namespace dcx {
2015-12-05 22:57:24 +00:00
2013-12-08 23:37:40 +00:00
void Warning_puts ( const char * str ) __attribute_nonnull ( ) ;
2013-06-27 02:35:22 +00:00
void Warning ( const char * fmt , . . . ) __attribute_format_printf ( 1 , 2 ) ; //print out warning message to user
2013-12-08 23:37:40 +00:00
# define Warning(F,...) dxx_call_printf_checked(Warning,Warning_puts,(),(F),##__VA_ARGS__)
2018-12-30 00:43:58 +00:00
# if DXX_USE_EDITOR
2022-09-24 17:47:53 +00:00
void set_warn_func ( void ( * f ) ( std : : span < const char > s ) ) ; //specifies the function to call with warning messages
2021-09-12 16:20:52 +00:00
# if !(defined(WIN32) || defined(__APPLE__) || defined(__MACH__))
2013-06-08 23:12:44 +00:00
void clear_warn_func ( ) ; //say this function no longer valid
2018-12-30 00:43:58 +00:00
# endif
2021-09-12 16:20:52 +00:00
# endif
2021-06-28 03:37:50 +00:00
[ [ noreturn ] ]
2021-06-28 03:37:51 +00:00
__attribute_nonnull ( )
2015-10-11 22:21:00 +00:00
void Error_puts ( const char * file , unsigned line , const char * func , const char * str ) ;
# define Error_puts(F) Error_puts(__FILE__, __LINE__, __func__, F)
2021-06-28 03:37:51 +00:00
[ [ noreturn ] ]
2015-10-11 22:21:00 +00:00
__attribute_format_printf ( 4 , 5 )
__attribute_nonnull ( )
void Error ( const char * file , unsigned line , const char * func , const char * fmt , . . . ) ; //exit with error code=1, print message
# define Error(F,...) dxx_call_printf_checked(Error,(Error_puts),(__FILE__, __LINE__, __func__),(F),##__VA_ARGS__)
2015-10-09 02:46:11 +00:00
2021-06-28 03:37:50 +00:00
[ [ noreturn ] ]
2015-10-09 02:46:11 +00:00
void UserError_puts ( const char * str , std : : size_t ) ;
template < std : : size_t len >
2021-06-28 03:37:50 +00:00
[ [ noreturn ] ]
2015-10-09 02:46:11 +00:00
static inline void UserError_puts ( const char ( & str ) [ len ] )
{
UserError_puts ( str , len - 1 ) ;
}
2021-06-28 03:37:50 +00:00
[ [ noreturn ] ]
void UserError ( const char * fmt , . . . ) __attribute_format_printf ( 1 , 2 ) ;
2015-12-23 03:28:17 +00:00
}
2016-04-03 17:50:42 +00:00
# define DXX_STRINGIZE_FL2(F,L,S) F ":" #L ": " S
# define DXX_STRINGIZE_FL(F,L,S) DXX_STRINGIZE_FL2(F, L, S)
# define UserError(F,...) dxx_call_printf_checked(UserError,(UserError_puts),(),DXX_STRINGIZE_FL(__FILE__, __LINE__, F),##__VA_ARGS__)
2013-06-23 02:28:43 +00:00
# define Assert assert
2006-03-20 16:43:15 +00:00
Scrub invalid primary textures at level load
Past releases, when rendering an invalid primary texture, would
Int3() and then reset the texture to zero. Commit d767f7c changed the
logic to return without resetting the texture, since the reset seemed to
be unnecessary. Unfortunately, it is necessary. Some levels, including
those shipped with the retail game data, specify bogus primary textures
on some surfaces. After d767f7c, rendering a surface with an invalid
primary texture causes the surface to be invisible, even if it has a
valid secondary texture.
Remove the return statement added in d767f7c. Extend
validate_segment_side to validate the primary texture on the tested
side. When an invalid texture is found, reset it and log a diagnostic.
For built-in levels, log at level CON_VERBOSE since players cannot
readily fix the level. For external levels, log at level CON_URGENT so
that level authors know to fix their level before releasing it.
Fixes: d767f7cd5ee99c5a4ce50c995045f0b7e422983a ("Pass vcsegptridx to render_face")
2016-12-22 05:21:16 +00:00
# define LevelErrorV(V,F,...) con_printf(V, DXX_STRINGIZE_FL(__FILE__, __LINE__, F " Please report this to the level author, not to the Rebirth maintainers."), ##__VA_ARGS__)
# define LevelError(F,...) LevelErrorV(CON_URGENT, F, ##__VA_ARGS__)
2016-10-17 03:49:32 +00:00
2014-12-07 23:43:51 +00:00
/* Compatibility with x86-specific name */
# define Int3() d_debugbreak()
# ifndef NDEBUG //macros for debugging
2014-12-24 03:34:33 +00:00
# define DXX_ENABLE_DEBUGBREAK_TRAP
2014-12-07 23:43:51 +00:00
# endif
2006-03-20 16:43:15 +00:00
2014-12-07 23:43:51 +00:00
/* Allow macro override */
2014-12-08 03:01:55 +00:00
2014-12-24 03:34:33 +00:00
# if defined(DXX_ENABLE_DEBUGBREAK_TRAP) && !defined(DXX_DEBUGBREAK_TRAP)
2006-03-20 16:43:15 +00:00
2014-12-07 23:43:51 +00:00
# if defined __clang__
/* Must be first, since clang also defines __GNUC__ */
2014-12-24 03:34:33 +00:00
# define DXX_DEBUGBREAK_TRAP() __builtin_debugtrap()
2014-12-07 23:43:51 +00:00
# elif defined __GNUC__
# if defined(__i386__) || defined(__amd64__)
2014-12-24 03:34:33 +00:00
# define DXX_DEBUGBREAK_TRAP() __asm__ __volatile__("int3" ::: "cc", "memory")
2014-12-07 23:43:51 +00:00
# endif
# elif defined _MSC_VER
2014-12-24 03:34:33 +00:00
# define DXX_DEBUGBREAK_TRAP() __debugbreak()
# endif
# ifndef DXX_DEBUGBREAK_TRAP
# if defined __unix__
/* for raise */
# include <signal.h>
# define DXX_DEBUGBREAK_TRAP() raise(SIGTRAP)
# elif defined __GNUC__
/* May terminate execution */
# define DXX_DEBUGBREAK_TRAP() __builtin_trap()
# endif
2006-03-20 16:43:15 +00:00
# endif
2008-01-23 17:25:09 +00:00
2014-12-07 23:43:51 +00:00
# endif
2014-12-24 03:34:33 +00:00
2015-12-23 03:28:17 +00:00
namespace dcx {
2014-12-24 03:34:33 +00:00
// Encourage optimizer to treat d_debugbreak paths as unlikely
__attribute_cold
// Requested by btb to force Xcode to stay in the calling function
2015-01-18 01:58:33 +00:00
__attribute_always_inline ( )
2014-12-24 03:34:33 +00:00
static inline void d_debugbreak ( )
{
/* Allow explicit activation in NDEBUG builds */
# ifdef DXX_DEBUGBREAK_TRAP
DXX_DEBUGBREAK_TRAP ( ) ;
2012-11-11 22:12:51 +00:00
# endif
2014-12-24 03:34:33 +00:00
}
2015-12-05 22:57:24 +00:00
}