Remove Some Macros
This commit is contained in:
parent
acec86b9b5
commit
e1d9fc492b
@ -70,15 +70,21 @@ struct CrashReport final : Frame {
|
||||
};
|
||||
|
||||
// Show Crash Report Dialog
|
||||
static void redirect_file(FILE *file, const char *mode) {
|
||||
const FILE *ret = freopen("/dev/null", mode, file);
|
||||
if (!ret) {
|
||||
IMPOSSIBLE();
|
||||
}
|
||||
}
|
||||
void show_report(const char *log_filename) {
|
||||
// Fork
|
||||
const pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
// Child
|
||||
setsid();
|
||||
ALLOC_CHECK(freopen("/dev/null", "w", stdout));
|
||||
ALLOC_CHECK(freopen("/dev/null", "w", stderr));
|
||||
ALLOC_CHECK(freopen("/dev/null", "r", stdin));
|
||||
redirect_file(stdout, "w");
|
||||
redirect_file(stderr, "w");
|
||||
redirect_file(stdin, "r");
|
||||
CrashReport ui(log_filename);
|
||||
ui.run();
|
||||
exit(EXIT_SUCCESS);
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <libreborn/log.h>
|
||||
#include <libreborn/env.h>
|
||||
#include <libreborn/util.h>
|
||||
#include <libreborn/config.h>
|
||||
|
||||
// $PATH
|
||||
@ -41,7 +41,9 @@ void setup_home() {
|
||||
} else {
|
||||
// Set Home To Current Directory, So World Data Is Stored There
|
||||
char *launch_directory = getcwd(nullptr, 0);
|
||||
ALLOC_CHECK(launch_directory);
|
||||
if (launch_directory == nullptr) {
|
||||
IMPOSSIBLE();
|
||||
}
|
||||
home = launch_directory;
|
||||
free(launch_directory);
|
||||
}
|
||||
|
@ -5,25 +5,8 @@
|
||||
|
||||
#include "log.h"
|
||||
|
||||
// Check Memory Allocation
|
||||
#define ALLOC_CHECK(obj) \
|
||||
{ \
|
||||
if ((obj) == nullptr) { \
|
||||
ERR("Memory Allocation Failed"); \
|
||||
} \
|
||||
}
|
||||
|
||||
// Align Number
|
||||
#define ALIGN_UP(x, alignment) \
|
||||
({ \
|
||||
int _align_x = (x); \
|
||||
int _align_alignment = (alignment); \
|
||||
int _align_diff = _align_x % _align_alignment; \
|
||||
if (_align_diff > 0) { \
|
||||
_align_x += (_align_alignment - _align_diff); \
|
||||
} \
|
||||
_align_x; \
|
||||
})
|
||||
int align_up(int x, int alignment);
|
||||
|
||||
// Hook Library Function
|
||||
#define HOOK(name, return_type, args) \
|
||||
|
@ -7,6 +7,15 @@
|
||||
#include <libreborn/config.h>
|
||||
#include <libreborn/env.h>
|
||||
|
||||
// Align Number
|
||||
int align_up(int x, const int alignment) {
|
||||
const int diff = x % alignment;
|
||||
if (diff > 0) {
|
||||
x += (alignment - diff);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
// Safe Version Of pipe()
|
||||
Pipe::Pipe(): read(-1), write(-1) {
|
||||
int out[2];
|
||||
|
@ -302,7 +302,7 @@ static int get_texture_size(const GLsizei width, const GLsizei height, const GLe
|
||||
int alignment;
|
||||
media_glGetIntegerv(is_upload ? GL_UNPACK_ALIGNMENT : GL_PACK_ALIGNMENT, &alignment);
|
||||
// Round
|
||||
line_size = ALIGN_UP(line_size, alignment);
|
||||
line_size = align_up(line_size, alignment);
|
||||
}
|
||||
// Return
|
||||
return line_size * height;
|
||||
|
@ -130,7 +130,7 @@ static void generate_atlas(Minecraft *minecraft) {
|
||||
int alignment;
|
||||
media_glGetIntegerv(GL_PACK_ALIGNMENT, &alignment);
|
||||
// Round
|
||||
line_size = ALIGN_UP(line_size, alignment);
|
||||
line_size = align_up(line_size, alignment);
|
||||
}
|
||||
Texture texture;
|
||||
texture.width = atlas_texture_size;
|
||||
|
@ -215,7 +215,6 @@ static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injectio
|
||||
// Read File
|
||||
const std::streamoff len = stream.tellg();
|
||||
char *buf = new char[len];
|
||||
ALLOC_CHECK(buf);
|
||||
stream.seekg(0, std::ifstream::beg);
|
||||
stream.read(buf, len);
|
||||
stream.close();
|
||||
|
@ -79,13 +79,12 @@ void screenshot_take(Gui *gui) {
|
||||
int alignment;
|
||||
media_glGetIntegerv(GL_PACK_ALIGNMENT, &alignment);
|
||||
// Round
|
||||
line_size = ALIGN_UP(line_size, alignment);
|
||||
line_size = align_up(line_size, alignment);
|
||||
}
|
||||
const int size = height * line_size;
|
||||
|
||||
// Read Pixels
|
||||
unsigned char *pixels = new unsigned char[size];
|
||||
ALLOC_CHECK(pixels);
|
||||
media_glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
|
||||
// Save Image
|
||||
|
@ -51,7 +51,7 @@ static int get_line_size(const int width) {
|
||||
int alignment;
|
||||
media_glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
|
||||
// Round
|
||||
line_size = ALIGN_UP(line_size, alignment);
|
||||
line_size = align_up(line_size, alignment);
|
||||
}
|
||||
return line_size;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user