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