Quick answer: A raylib or SDL game has no engine to lean on, so a bug report is four small pieces of your own code: a libcurl POST with a JSON body on a worker thread, a text box built from GetCharPressed(), a screenshot taken with LoadImageFromScreen() and ExportImageToMemory() and sent as base64 PNG, and a crash handler that writes a text file for the next launch to upload. All of it fits in about 300 lines of C++.

Games written straight on raylib or SDL tend to ship with printf as their only diagnostics. That works until the build is on someone else’s machine, where stdout goes nowhere and a segfault closes the window without a word. There is no SDK to drop in for a hand-rolled engine, but you do not need one. This guide builds a raylib bug report feature from first principles: a hotkey opens a form, the player types a sentence, and the note, a screenshot and the last 200 log lines arrive on a server. Then it covers the harder half, recording a crash in C++ when almost nothing is safe to call. The examples are C++17 with raylib 5.x; the SDL differences are near the end.

What a bug report from a custom engine needs

Posting JSON with libcurl

libcurl is the standard answer for HTTPS from C or C++. It is in every Linux package manager, in Homebrew, and in vcpkg for Windows. The example posts to Bugnet’s report endpoint, which takes the project key in an X-API-Key header; swap the URL and fields for any other JSON API.

// bug_report.cpp (part 1): build the JSON and POST it with libcurl
#include <curl/curl.h>
#include <cstdio>
#include <string>
#include <thread>

#define API_KEY      "sk_live_your_project_key"
#define GAME_VERSION "1.0.3"
#if defined(_WIN32)
#define PLATFORM_NAME "Windows"
#elif defined(__APPLE__)
#define PLATFORM_NAME "macOS"
#else
#define PLATFORM_NAME "Linux"
#endif

struct BugReport {
    std::string title;
    std::string description;
    std::string category = "other";
    std::string screenshot_b64;   // PNG as base64, optional
    std::string log_b64;          // text log as base64, optional
    bool auto_captured = false;
};

static std::string json_escape(const std::string& s) {
    std::string out;
    out.reserve(s.size() + 16);
    for (unsigned char c : s) {
        switch (c) {
            case '"':  out += "\\\""; break;
            case '\\': out += "\\\\"; break;
            case '\n': out += "\\n";  break;
            case '\r': out += "\\r";  break;
            case '\t': out += "\\t";  break;
            default:
                if (c < 0x20) {
                    char buf[8];
                    snprintf(buf, sizeof buf, "\\u%04x", c);
                    out += buf;
                } else {
                    out += static_cast<char>(c);
                }
        }
    }
    return out;
}

static std::string build_json(const BugReport& r) {
    std::string j = "{";
    j += "\"title\":\"" + json_escape(r.title.substr(0, 200)) + "\",";
    j += "\"description\":\"" + json_escape(r.description) + "\",";
    j += "\"category\":\"" + r.category + "\",";
    j += "\"platform\":\"" PLATFORM_NAME "\",";
    j += "\"game_version\":\"" GAME_VERSION "\",";
    j += std::string("\"auto_captured\":") + (r.auto_captured ? "true" : "false");
    if (!r.screenshot_b64.empty()) {
        j += ",\"screenshot\":\"" + r.screenshot_b64 + "\"";
    }
    if (!r.log_b64.empty()) {
        j += ",\"attachments\":[{\"filename\":\"game.log\",\"mime_type\":\"text/plain\","
             "\"data\":\"" + r.log_b64 + "\"}]";
    }
    return j + "}";
}

static size_t discard_response(char*, size_t size, size_t count, void*) {
    return size * count;
}

static bool post_report(const BugReport& report) {
    CURL* curl = curl_easy_init();
    if (!curl) return false;

    const std::string body = build_json(report);
    curl_slist* headers = nullptr;
    headers = curl_slist_append(headers, "Content-Type: application/json");
    headers = curl_slist_append(headers, "X-API-Key: " API_KEY);

    curl_easy_setopt(curl, CURLOPT_URL, "https://api.bugnet.io/api/bugs/submit");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, static_cast<curl_off_t>(body.size()));
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15L);
    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);   // needed when called off the main thread
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, discard_response);

    const CURLcode result = curl_easy_perform(curl);
    long status = 0;
    curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
    curl_slist_free_all(headers);
    curl_easy_cleanup(curl);
    return result == CURLE_OK && (status == 200 || status == 201);
}

// Never call post_report from the game loop: a slow network would freeze the frame.
static void send_async(BugReport report) {
    std::thread([r = std::move(report)] { post_report(r); }).detach();
}

Notes on the parts that bite:

In plain C the same calls apply. Build the body into a char buffer and start the worker with pthread_create, SDL_CreateThread or C11 threads.

A raylib screenshot to memory, the log and a text box

// bug_report.cpp (part 2): screenshot, log buffer and text box with raylib
#include "raylib.h"
#include "rlgl.h"
#include <cstdarg>
#include <deque>
#include <mutex>

static std::string base64(const unsigned char* data, int size) {
    int encoded_size = 0;
    char* encoded = EncodeDataBase64(data, size, &encoded_size);
    if (!encoded) return {};
    std::string out(encoded, static_cast<size_t>(encoded_size));
    MemFree(encoded);
    // The buffer is not a C string in every raylib version: trust the size, drop any terminator.
    while (!out.empty() && out.back() == '\0') out.pop_back();
    return out;
}

// Call after the scene is drawn and before the report form is drawn.
static std::string capture_screenshot_b64() {
    rlDrawRenderBatchActive();                 // flush queued draw calls so the frame is complete
    Image shot = LoadImageFromScreen();
    ImageResize(&shot, shot.width / 2, shot.height / 2);
    int png_size = 0;
    unsigned char* png = ExportImageToMemory(shot, ".png", &png_size);
    UnloadImage(shot);
    if (!png) return {};
    std::string out = base64(png, png_size);
    MemFree(png);
    return out;
}

static std::mutex g_log_mutex;
static std::deque<std::string> g_log_lines;

static void log_callback(int, const char* format, va_list args) {
    char line[512];
    vsnprintf(line, sizeof line, format, args);
    fprintf(stderr, "%s\n", line);             // a custom callback replaces raylib's own output
    std::lock_guard<std::mutex> lock(g_log_mutex);
    g_log_lines.emplace_back(line);
    if (g_log_lines.size() > 200) g_log_lines.pop_front();
}

static std::string recent_log_b64() {
    std::string text;
    {
        std::lock_guard<std::mutex> lock(g_log_mutex);
        for (const std::string& line : g_log_lines) text += line + "\n";
    }
    return base64(reinterpret_cast<const unsigned char*>(text.data()), static_cast<int>(text.size()));
}

static void update_text_box(std::string& text, size_t max_length) {
    for (int c = GetCharPressed(); c > 0; c = GetCharPressed()) {
        if (c >= 32 && c < 127 && text.size() < max_length) {
            text.push_back(static_cast<char>(c));
        }
    }
    const bool erase = IsKeyPressed(KEY_BACKSPACE) || IsKeyPressedRepeat(KEY_BACKSPACE);
    if (erase && !text.empty()) text.pop_back();
}

The screenshot. LoadImageFromScreen() reads the framebuffer into an Image, and ExportImageToMemory() (raylib 5.0 and later) encodes it as PNG in memory, so nothing is written to disk. Three details matter. raylib batches draw calls, so rlDrawRenderBatchActive() from rlgl.h is called first to flush whatever is still queued; without it the screenshot can miss the last things you drew. The image is halved before encoding, because a 1080p PNG can run to several megabytes and nobody needs that to see a clipping bug. And the buffer from EncodeDataBase64 is copied using the returned size, since it is not a NUL-terminated string in raylib 5.x. Bugnet’s screenshot field expects a PNG of at most 5 MB, as base64.

The log. SetTraceLogCallback routes every raylib TraceLog call through your function. Setting it replaces raylib’s own console output, which is why the callback prints the line itself. Send your own game messages through TraceLog as well and the last 200 lines travel with every report as a text attachment. The mutex is there in case anything logs from a thread other than the one that reads the buffer.

The text box. GetCharPressed() returns queued characters one at a time and 0 when the queue is empty, so it is called in a loop. It returns Unicode code points. This version accepts printable ASCII only; to accept everything else, encode each code point as UTF-8 with raylib’s CodepointToUTF8 and make Backspace remove a whole character, not one byte.

Putting it in the game loop

// main.cpp: F8 opens the report form
static void update_game() {}
static void draw_game() {}

int main() {
    curl_global_init(CURL_GLOBAL_DEFAULT);
    SetTraceLogCallback(log_callback);
    install_crash_handlers();
    InitWindow(1280, 720, "My Game");
    SetExitKey(KEY_NULL);                      // free Escape for closing the form
    SetTargetFPS(60);
    send_pending_crash();

    bool form_open = false;
    bool capture_requested = false;
    std::string note;
    std::string screenshot;

    while (!WindowShouldClose()) {
        if (form_open) {
            update_text_box(note, 400);
            if (IsKeyPressed(KEY_ENTER) && !note.empty()) {
                BugReport report;
                report.title = note.substr(0, 80);
                report.description = note;
                report.screenshot_b64 = screenshot;
                report.log_b64 = recent_log_b64();
                send_async(std::move(report));
                form_open = false;
            }
            if (IsKeyPressed(KEY_ESCAPE)) form_open = false;
        } else {
            if (IsKeyPressed(KEY_F8)) capture_requested = true;
            update_game();
        }

        BeginDrawing();
        ClearBackground(RAYWHITE);
        draw_game();
        if (capture_requested) {               // the scene is drawn, the form is not
            screenshot = capture_screenshot_b64();
            note.clear();
            form_open = true;
            capture_requested = false;
        }
        if (form_open) {
            DrawRectangle(240, 220, 800, 200, Fade(BLACK, 0.85f));
            DrawText("What went wrong? Enter sends, Esc cancels.", 260, 240, 20, RAYWHITE);
            DrawText(note.c_str(), 260, 290, 20, YELLOW);
        }
        EndDrawing();
    }

    CloseWindow();
    curl_global_cleanup();
    return 0;
}

The order of operations is the point of this block. Pressing F8 only sets a flag. The screenshot is taken later in the same frame, after draw_game() and before the form is drawn, so it shows the scene the player was looking at. While the form is open the game update is skipped, which also stops the typed letters from steering the character. SetExitKey(KEY_NULL) matters because raylib closes the window on Escape by default, and a player who presses Escape to cancel a bug report does not expect the game to quit.

The title is the first 80 characters of the note. Add what you can from your own state to the description: the level name, player position, random seed and anything else that lets you reproduce the report.

C++ crash reports: write a file now, send it on the next launch

A crash in native code arrives as a signal on Linux and macOS, as a structured exception on Windows, and as std::terminate for an uncaught C++ exception. In all three the process is in an unknown state, and inside a signal handler the rules are strict: only async-signal-safe functions may be called. malloc, printf, std::string and libcurl are all off the list. open, write and close are on it. So the handler writes a small text file and gets out, and the upload happens at the next start, when the process is healthy.

// bug_report.cpp (part 3): record a crash now, send it on the next launch
#include <csignal>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <fstream>
#include <iterator>

// Point this at your save directory at startup. The install folder may be read-only.
static char g_crash_path[512] = "crash_report.txt";

#if !defined(_WIN32)
#include <execinfo.h>
#include <fcntl.h>
#include <unistd.h>

// Signal handlers may only call async-signal-safe functions: no malloc, no printf, no curl.
static void on_fatal_signal(int sig) {
    const int fd = open(g_crash_path, O_WRONLY | O_CREAT | O_APPEND, 0644);
    if (fd >= 0) {
        const char* name = sig == SIGSEGV ? "SIGSEGV\n" : sig == SIGABRT ? "SIGABRT\n"
                         : sig == SIGFPE  ? "SIGFPE\n"  : sig == SIGILL  ? "SIGILL\n" : "SIGBUS\n";
        if (write(fd, name, strlen(name)) < 0) { /* nothing safe to do about it here */ }
        void* frames[64];
        const int count = backtrace(frames, 64);
        backtrace_symbols_fd(frames, count, fd);
        close(fd);
    }
    signal(sig, SIG_DFL);                      // restore the default action...
    raise(sig);                                // ...and let the process die the normal way
}
#else
#include <windows.h>

static LONG WINAPI on_unhandled_exception(EXCEPTION_POINTERS* info) {
    char text[256];
    const int length = snprintf(text, sizeof text, "Exception 0x%08lX\naddress %p\nmodule base %p\n",
        info->ExceptionRecord->ExceptionCode, info->ExceptionRecord->ExceptionAddress,
        static_cast<void*>(GetModuleHandle(nullptr)));
    HANDLE file = CreateFileA(g_crash_path, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS,
                              FILE_ATTRIBUTE_NORMAL, nullptr);
    if (file != INVALID_HANDLE_VALUE) {
        DWORD written = 0;
        WriteFile(file, text, static_cast<DWORD>(length), &written, nullptr);
        CloseHandle(file);
    }
    return EXCEPTION_EXECUTE_HANDLER;
}
#endif

static void on_terminate() {
    std::string what = "unknown exception";
    try {
        if (std::exception_ptr e = std::current_exception()) std::rethrow_exception(e);
    } catch (const std::exception& e) {
        what = e.what();
    } catch (...) {
    }
    std::ofstream(g_crash_path) << "Uncaught C++ exception: " << what << "\n";
    std::abort();                              // raises SIGABRT, which appends the backtrace
}

static void install_crash_handlers() {
    std::set_terminate(on_terminate);
#if !defined(_WIN32)
    void* warmup[1];
    backtrace(warmup, 1);                      // load the unwinder now, not inside the handler
    for (int sig : {SIGSEGV, SIGABRT, SIGFPE, SIGILL, SIGBUS}) signal(sig, on_fatal_signal);
#else
    SetUnhandledExceptionFilter(on_unhandled_exception);
#endif
}

static void send_pending_crash() {
    std::ifstream in(g_crash_path);
    if (!in) return;
    const std::string text((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
    in.close();
    std::remove(g_crash_path);

    BugReport report;
    report.title = "Crash: " + text.substr(0, text.find('\n')) + " (" PLATFORM_NAME " " GAME_VERSION ")";
    report.description = text;
    report.category = "crash";
    report.auto_captured = true;
    send_async(std::move(report));
}

What each piece does:

A line from the Linux file looks like ./game(+0x88c1)[0x55c7e7e778c1]. The absolute address changes on every run, but the offset in parentheses is the same for every player on the same build. Resolve it with addr2line -f -C -e ./game 0x88c1 against an unstripped copy of that exact binary, and keep one for every release. Linking with -rdynamic makes function names appear in the file directly.

Two limits to know about. A stack overflow cannot run this handler on the overflowed stack; it needs an alternate signal stack set up with sigaltstack. And Bugnet’s attachments take text, images, video and JSON, not binary .dmp files, so send the text trace and keep minidumps for local debugging.

The crash title is deliberately coarse: the signal or exception message, the platform and the version. Every SIGSEGV on Linux 1.0.3 stacks into one report, with the individual backtraces inside it. If you want finer grouping, append the offset of the first frame that belongs to your executable.

The same thing in an SDL game

The sender, the JSON and the crash handlers do not depend on raylib at all. Three things change with SDL:

Emscripten builds

In a browser build there is no libcurl and no signal handler. Send the request with the Emscripten Fetch API or a few lines of JavaScript calling fetch, and catch failures with window.onerror in the HTML shell. The request is cross-origin, so the server has to allow it; Bugnet’s report endpoint accepts browser requests from any origin.

Where the reports go

The code posts to Bugnet’s public report API: POST /api/bugs/submit with the project key in X-API-Key. There is no raylib or SDL SDK; the HTTP API is the integration, and it accepts the screenshot and up to ten attachments in the same request. The key is an ingestion key, safe to compile into the binary, because it can file reports but cannot read them.

Each report shows up in the dashboard with the note, the screenshot, the log attachment, the platform and the version. Reports with identical titles stack into one entry with an occurrence count, so crash reports group by signal and build on their own. You can assign and prioritize them, forward new ones to Discord, and publish fixed issues on a public tracker and changelog. The free plan covers one project and up to 100 bug reports. The quickstart shows where the key is, and the API explorer lets you send a test report before writing any C++.

Frequently asked questions

How do I send an HTTP POST with JSON from a C or C++ game?

Use libcurl. Set CURLOPT_URL, add Content-Type and any API key header with curl_slist_append and CURLOPT_HTTPHEADER, pass the body with CURLOPT_POSTFIELDS, call curl_easy_perform and read CURLINFO_RESPONSE_CODE. Run it on a worker thread so a slow network never freezes a frame.

How do I take a screenshot to memory in raylib?

Call LoadImageFromScreen to get an Image, then ExportImageToMemory(image, ".png", &size) to get PNG bytes without touching the disk. Free the bytes with MemFree and the image with UnloadImage. ExportImageToMemory needs raylib 5.0 or later.

Can a C++ game catch a segfault and send a crash report?

It can catch the signal, but a signal handler may only call async-signal-safe functions, which rules out memory allocation and networking. Write a small crash file with open, write and backtrace_symbols_fd, re-raise the signal, and send the file when the game next starts.

Can I upload a minidump file to Bugnet?

No. Bugnet attachments accept text, images, video and JSON, not binary .dmp files. Send a text stack trace or the output of your debugger’s analysis, and keep the dump itself for local debugging.

Does the same bug reporting code work with SDL2 and SDL3?

The networking, JSON and crash handling are plain C++ and do not depend on the windowing library. Only the screenshot and text input differ: read pixels with SDL_RenderReadPixels and encode them as PNG yourself, and collect typed text from SDL’s text input events.

In a signal handler you can write a file and nothing else. Record the crash in the few safe calls you have, and let the next launch do the networking.