Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
debug_internal.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
20// $File: //depot/GeneralsMD/Staging/code/Libraries/Source/debug/debug_internal.cpp $
21// $Author: mhoffe $
22// $Revision: #1 $
23// $DateTime: 2003/07/03 11:55:26 $
24//
25// ©2003 Electronic Arts
26//
27// Implementation of internal code
29#include "_pch.h"
30
31void DebugInternalAssert(const char *file, int line, const char *expr)
32{
33 // dangerous as well but since this function is used in this
34 // module only we know how long stuff can get
35 char buf[512];
36 wsprintf(buf,"File %s, line %i:\n%s",file,line,expr);
37 MessageBox(NULL,buf,"Internal assert failed",
38 MB_OK|MB_ICONSTOP|MB_TASKMODAL|MB_SETFOREGROUND);
39
40 // stop right now!
41 TerminateProcess(GetCurrentProcess(),666);
42}
43
44void *DebugAllocMemory(unsigned numBytes)
45{
46 HGLOBAL h=GlobalAlloc(GMEM_FIXED,numBytes);
47 if (!h)
48 DCRASH_RELEASE("Debug mem alloc failed");
49 return (void *)h;
50}
51
52void *DebugReAllocMemory(void *oldPtr, unsigned newSize)
53{
54 // Windows doesn't like ReAlloc with NULL handle/ptr...
55 if (!oldPtr)
56 return newSize?DebugAllocMemory(newSize):0;
57
58 // Shrinking to 0 size is basically freeing memory
59 if (!newSize)
60 {
61 GlobalFree((HGLOBAL)oldPtr);
62 return 0;
63 }
64
65 // now try GlobalReAlloc first
66 HGLOBAL h=GlobalReAlloc((HGLOBAL)oldPtr,newSize,0);
67 if (!h)
68 {
69 // this failed (Windows doesn't like ReAlloc'ing larger
70 // fixed memory blocks) - go with Alloc/Free instead
71 h=GlobalAlloc(GMEM_FIXED,newSize);
72 if (!h)
73 DCRASH_RELEASE("Debug mem realloc failed");
74 unsigned oldSize=GlobalSize((HGLOBAL)oldPtr);
75 memcpy((void *)h,oldPtr,oldSize<newSize?oldSize:newSize);
76 GlobalFree((HGLOBAL)oldPtr);
77 }
78
79 return (void *)h;
80}
81
82void DebugFreeMemory(void *ptr)
83{
84 if (ptr)
85 GlobalFree((HGLOBAL)ptr);
86}
#define NULL
Definition BaseType.h:92
void DebugInternalAssert(const char *file, int line, const char *expr)
void * DebugReAllocMemory(void *oldPtr, unsigned newSize)
void * DebugAllocMemory(unsigned numBytes)
void DebugFreeMemory(void *ptr)
#define DCRASH_RELEASE(msg)