Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 38 additions & 32 deletions src/backends/sdl2_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace {
void showDriverInUse(const Context &ctx) {
ctx.mLogger(LogSeverity::Message, "Driver in use:");
SDL_RendererInfo info;
SDL_GetRendererInfo(ctx.mSDLContext.mRenderer, &info);
SDL_GetRendererInfo(ctx.mSDLContext->mRenderer, &info);
printDriverInfo(info);
}

Expand Down Expand Up @@ -178,10 +178,16 @@ ret_code Renderer::releaseRenderer(Context &ctx) {
delete ctx.mDefaultFont;
ctx.mDefaultFont = nullptr;
}

IMG_Quit();
SDL_DestroyRenderer(ctx.mSDLContext.mRenderer);
ctx.mSDLContext.mRenderer = nullptr;
if (ctx.mSDLContext == nullptr) {
SDL_Quit();
return ResultOk;
}

if (ctx.mSDLContext->mRenderer != nullptr) {
SDL_DestroyRenderer(ctx.mSDLContext->mRenderer);
ctx.mSDLContext->mRenderer = nullptr;
}
SDL_Quit();

return ResultOk;
Expand Down Expand Up @@ -214,7 +220,7 @@ ret_code Renderer::drawText(Context &ctx, const char *string, Font *font, const
return ErrorCode;
}

SDL_Texture *messageTexture = SDL_CreateTextureFromSurface(ctx.mSDLContext.mRenderer, surfaceMessage);
SDL_Texture *messageTexture = SDL_CreateTextureFromSurface(ctx.mSDLContext->mRenderer, surfaceMessage);
if (messageTexture == nullptr) {
const std::string msg = "Cannot create texture: " + std::string(SDL_GetError()) + ".";
ctx.mLogger(LogSeverity::Error, msg.c_str());
Expand Down Expand Up @@ -244,7 +250,7 @@ ret_code Renderer::drawText(Context &ctx, const char *string, Font *font, const
break;
}

SDL_RenderCopy(ctx.mSDLContext.mRenderer, messageTexture, NULL, &Message_rect);
SDL_RenderCopy(ctx.mSDLContext->mRenderer, messageTexture, nullptr, &Message_rect);
SDL_FreeSurface(surfaceMessage);
SDL_DestroyTexture(messageTexture);

Expand All @@ -256,8 +262,8 @@ ret_code Renderer::initScreen(Context &ctx, int32_t x, int32_t y, int32_t w, int
ctx.mLogger(LogSeverity::Error, "Not initialzed.");
return ErrorCode;
}

if (ctx.mSDLContext.mWindow != nullptr ) {
ctx.mSDLContext = SDLContext::create();
if (ctx.mSDLContext->mWindow != nullptr) {
ctx.mLogger(LogSeverity::Error, "Already created.");
return ErrorCode;
}
Comment thread
kimkulling marked this conversation as resolved.
Expand All @@ -277,8 +283,8 @@ ret_code Renderer::initScreen(Context &ctx, int32_t x, int32_t y, int32_t w, int
title = "TinyUI Window";
}

ctx.mSDLContext.mWindow = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
if (ctx.mSDLContext.mWindow == nullptr) {
ctx.mSDLContext->mWindow = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (ctx.mSDLContext->mWindow == nullptr) {
const std::string msg = "Error while SDL_CreateWindow: " + std::string(SDL_GetError()) + ".";
ctx.mLogger(LogSeverity::Error, msg.c_str());
return ErrorCode;
Expand All @@ -290,8 +296,8 @@ ret_code Renderer::initScreen(Context &ctx, int32_t x, int32_t y, int32_t w, int
return ErrorCode;
}

ctx.mSDLContext.mRenderer = SDL_CreateRenderer(ctx.mSDLContext.mWindow, driverIndex, SDL_RENDERER_ACCELERATED);
if (nullptr == ctx.mSDLContext.mRenderer) {
ctx.mSDLContext->mRenderer = SDL_CreateRenderer(ctx.mSDLContext->mWindow, driverIndex, SDL_RENDERER_ACCELERATED);
if (nullptr == ctx.mSDLContext->mRenderer) {
const std::string msg = "Error while SDL_CreateRenderer: " + std::string(SDL_GetError()) + ".";
ctx.mLogger(LogSeverity::Error, msg.c_str());
return ErrorCode;
Expand All @@ -303,8 +309,8 @@ ret_code Renderer::initScreen(Context &ctx, int32_t x, int32_t y, int32_t w, int

showDriverInUse(ctx);

ctx.mSDLContext.mSurface = SDL_GetWindowSurface(ctx.mSDLContext.mWindow);
if (ctx.mSDLContext.mSurface == nullptr) {
ctx.mSDLContext->mSurface = SDL_GetWindowSurface(ctx.mSDLContext->mWindow);
if (ctx.mSDLContext->mSurface == nullptr) {
ctx.mLogger(LogSeverity::Error, "Surface pointer from window is nullptr.");
return ErrorCode;
}
Expand All @@ -325,13 +331,13 @@ ret_code Renderer::initScreen(Context &ctx, SDL_Window *window, SDL_Renderer *re

TTF_Init();

ctx.mSDLContext.mRenderer = renderer;
ctx.mSDLContext.mWindow = window;
ctx.mSDLContext->mRenderer = renderer;
ctx.mSDLContext->mWindow = window;

Comment on lines +334 to 336
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

cd /tmp && find . -name "sdl2_renderer.cpp" -o -name "sdl2_renderer.h" 2>/dev/null | head -20

Repository: kimkulling/tiny_ui

Length of output: 44


🏁 Script executed:

find . -name "sdl2_renderer.cpp" -o -name "sdl2_renderer.h" 2>/dev/null

Repository: kimkulling/tiny_ui

Length of output: 125


🏁 Script executed:

find . -type f -name "*sdl2*" 2>/dev/null | head -20

Repository: kimkulling/tiny_ui

Length of output: 189


🏁 Script executed:

git ls-files | grep -i sdl2

Repository: kimkulling/tiny_ui

Length of output: 181


🏁 Script executed:

git ls-files | grep -E "\.(cpp|h|hpp)$" | head -20

Repository: kimkulling/tiny_ui

Length of output: 306


🏁 Script executed:

git ls-files | grep -E "src/backends" | head -20

Repository: kimkulling/tiny_ui

Length of output: 181


🏁 Script executed:

ls -la src/backends/ 2>/dev/null || echo "Directory not found"

Repository: kimkulling/tiny_ui

Length of output: 443


🏁 Script executed:

git ls-files | head -30

Repository: kimkulling/tiny_ui

Length of output: 566


🏁 Script executed:

rg -l "initScreen" --type cpp --type h

Repository: kimkulling/tiny_ui

Length of output: 166


🏁 Script executed:

rg "initScreen" -A 5 -B 2 --type cpp --type h | head -100

Repository: kimkulling/tiny_ui

Length of output: 3559


🏁 Script executed:

test -f "src/backends/sdl2_renderer.cpp" && echo "File exists" || echo "File does not exist"

Repository: kimkulling/tiny_ui

Length of output: 73


🏁 Script executed:

find . -type f \( -name "*.cpp" -o -name "*.h" \) 2>/dev/null | sort

Repository: kimkulling/tiny_ui

Length of output: 328


🏁 Script executed:

ls -la

Repository: kimkulling/tiny_ui

Length of output: 1118


🏁 Script executed:

pwd && ls -la src/ 2>/dev/null | head -20

Repository: kimkulling/tiny_ui

Length of output: 561


🏁 Script executed:

find . -path "*backends*" -name "*.cpp" -o -path "*backends*" -name "*.h" | head -20

Repository: kimkulling/tiny_ui

Length of output: 189


🏁 Script executed:

find . -name "*sdl2_renderer*" -type f

Repository: kimkulling/tiny_ui

Length of output: 125


🏁 Script executed:

rg "initScreen" -C 20 | head -150

Repository: kimkulling/tiny_ui

Length of output: 7254


🏁 Script executed:

rg "mSDLContext->mRenderer" -B 5 -A 2

Repository: kimkulling/tiny_ui

Length of output: 10343


🏁 Script executed:

cat "src/backends/sdl2_renderer.cpp" 2>/dev/null | head -50

Repository: kimkulling/tiny_ui

Length of output: 1869


🏁 Script executed:

ls -la src/ 2>/dev/null || ls -la

Repository: kimkulling/tiny_ui

Length of output: 542


🏁 Script executed:

git ls-files --cached 2>/dev/null | head -30

Repository: kimkulling/tiny_ui

Length of output: 566


🏁 Script executed:

git status 2>&1 | head -10
git ls-files 2>/dev/null | wc -l

Repository: kimkulling/tiny_ui

Length of output: 265


🏁 Script executed:

find . -type f -name "*.cpp" 2>/dev/null | head -20

Repository: kimkulling/tiny_ui

Length of output: 181


🏁 Script executed:

ls -la && find . -maxdepth 3 -type f \( -name "*.cpp" -o -name "*.h" \) 2>/dev/null | head -30

Repository: kimkulling/tiny_ui

Length of output: 1385


🌐 Web query:

SDL2 initScreen null pointer safety pattern C++

💡 Result:

A solid “null-pointer safe” initScreen() pattern for SDL2 in C++ is:

  1. Check every SDL call that can fail (returns nullptr/NULL or <0) and bail immediately, logging SDL_GetError() (e.g., SDL_CreateWindow returns NULL on failure and you should call SDL_GetError() for details). [1]
  2. Use RAII so partially-initialized resources don’t leak if you early-return (wrap SDL_Window*, SDL_Renderer*, etc. in std::unique_ptr with SDL destroy functions as custom deleters). [2][3]
`#include` <SDL.h>
`#include` <memory>
`#include` <stdexcept>
`#include` <string>

struct SdlError : std::runtime_error {
  using std::runtime_error::runtime_error;
};

using Window   = std::unique_ptr<SDL_Window,   decltype(&SDL_DestroyWindow)>;
using Renderer = std::unique_ptr<SDL_Renderer, decltype(&SDL_DestroyRenderer)>;

struct Screen {
  Window   window   {nullptr, SDL_DestroyWindow};
  Renderer renderer {nullptr, SDL_DestroyRenderer};
};

inline void sdl_ok(int rc, const char* what) {
  if (rc < 0) throw SdlError(std::string(what) + ": " + SDL_GetError());
}

inline Screen initScreen(const char* title, int w, int h) {
  sdl_ok(SDL_Init(SDL_INIT_VIDEO), "SDL_Init");

  Screen s;

  s.window.reset(SDL_CreateWindow(title,
                                 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                 w, h, SDL_WINDOW_SHOWN));
  if (!s.window) throw SdlError(std::string("SDL_CreateWindow: ") + SDL_GetError());

  s.renderer.reset(SDL_CreateRenderer(s.window.get(), -1,
                                      SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC));
  if (!s.renderer) throw SdlError(std::string("SDL_CreateRenderer: ") + SDL_GetError());

  return s; // move/NRVO
}

// Usage:
// int main() {
//   try {
//     auto screen = initScreen("My Game", 1280, 720);
//     ...
//   } catch (const std::exception& e) {
//     SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s\n", e.what());
//   }
//   SDL_Quit(); // or wrap SDL_Init/SDL_Quit in its own RAII guard
// }

Why this is “null-safe”: you never dereference window/renderer unless the unique_ptr is non-null, and failures immediately stop initialization (with an error message from SDL_GetError()). [1][2]

Sources: SDL “returns NULL on failure; call SDL_GetError()” guidance [1]; RAII with unique_ptr + SDL destroy-function deleters [2][3].

[1] SDL Wiki: SDL_CreateWindow return value / SDL_GetError() on failure (wiki.libsdl.org)
[2] RAII + unique_ptr custom deleter technique (SDL example) (lethalguitar.wordpress.com)
[3] SDL resource wrappers using unique_ptr custom deleters (swarminglogic.com)

Citations:


🏁 Script executed:

rg "mSDLContext" -B 10 -A 5 --type cpp

Repository: kimkulling/tiny_ui

Length of output: 23230


🏁 Script executed:

rg "ctx.mSDLContext->mRenderer" -B 20 -A 5

Repository: kimkulling/tiny_ui

Length of output: 26191


🏁 Script executed:

rg "ret_code initScreen" -A 30 --type cpp

Repository: kimkulling/tiny_ui

Length of output: 3344


🏁 Script executed:

rg "initScreen\s*\(" -B 2 -A 15 --type cpp | head -200

Repository: kimkulling/tiny_ui

Length of output: 7173


🏁 Script executed:

ast-grep --pattern 'fn initScreen($$$) { $$$ }' 2>/dev/null || rg "void initScreen|ret_code initScreen" -A 20

Repository: kimkulling/tiny_ui

Length of output: 2836


🏁 Script executed:

rg "SDLContext" --type cpp --type h | head -40

Repository: kimkulling/tiny_ui

Length of output: 3201


🏁 Script executed:

ls -la src/backends/

Repository: kimkulling/tiny_ui

Length of output: 443


External-window initScreen dereferences mSDLContext without null check.

At lines 328-330, the function directly dereferences ctx.mSDLContext->mRenderer and ctx.mSDLContext->mWindow without first ensuring mSDLContext is initialized. Unlike the coordinate-based initScreen overload which calls SDLContext::create(), this external-window variant assumes the pointer already exists. If called without prior initialization, this causes a null pointer dereference. Validate that mSDLContext is not null before dereferencing, or initialize it if needed.

Proposed fix
-    ctx.mSDLContext->mRenderer = renderer;
-    ctx.mSDLContext->mWindow = window;
+    if (ctx.mSDLContext == nullptr) {
+        ctx.mSDLContext = SDLContext::create();
+    }
+    if (ctx.mSDLContext == nullptr) {
+        return ErrorCode;
+    }
+    ctx.mSDLContext->mRenderer = renderer;
+    ctx.mSDLContext->mWindow = window;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ctx.mSDLContext->mRenderer = renderer;
ctx.mSDLContext->mWindow = window;
if (ctx.mSDLContext == nullptr) {
ctx.mSDLContext = SDLContext::create();
}
if (ctx.mSDLContext == nullptr) {
return ErrorCode;
}
ctx.mSDLContext->mRenderer = renderer;
ctx.mSDLContext->mWindow = window;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/backends/sdl2_renderer.cpp` around lines 328 - 330, The external-window
overload of initScreen currently dereferences ctx.mSDLContext->mRenderer and
->mWindow without ensuring ctx.mSDLContext is valid; modify that initScreen
variant to check if ctx.mSDLContext is null and if so call SDLContext::create()
(the same initialization path used by the coordinate-based initScreen), then
assign mRenderer and mWindow; ensure you update references to ctx.mSDLContext,
mRenderer and mWindow only after confirming/creating ctx.mSDLContext to avoid
null-pointer dereference.

showDriverInUse(ctx);

ctx.mSDLContext.mSurface = SDL_GetWindowSurface(ctx.mSDLContext.mWindow);
ctx.mSDLContext.mOwner = false;
ctx.mSDLContext->mSurface = SDL_GetWindowSurface(ctx.mSDLContext->mWindow);
ctx.mSDLContext->mOwner = false;
ctx.mCreated = true;

return ResultOk;
Expand All @@ -343,8 +349,8 @@ ret_code Renderer::releaseScreen(Context &ctx) {
return ErrorCode;
}

SDL_DestroyWindow(ctx.mSDLContext.mWindow);
ctx.mSDLContext.mWindow = nullptr;
SDL_DestroyWindow(ctx.mSDLContext->mWindow);
ctx.mSDLContext->mWindow = nullptr;

return ResultOk;
}
Expand All @@ -356,19 +362,19 @@ ret_code Renderer::beginRender(Context &ctx, Color4 bg, SDL_Texture *renderTarge
}

const SDL_Color sdl_bg = getSDLColor(bg);
SDL_SetRenderDrawColor(ctx.mSDLContext.mRenderer, sdl_bg.r, sdl_bg.g, sdl_bg.b, sdl_bg.a);
SDL_RenderClear(ctx.mSDLContext.mRenderer);
SDL_SetRenderDrawColor(ctx.mSDLContext->mRenderer, sdl_bg.r, sdl_bg.g, sdl_bg.b, sdl_bg.a);
SDL_RenderClear(ctx.mSDLContext->mRenderer);

return ResultOk;
}

ret_code Renderer::drawRect(Context &ctx, int32_t x, int32_t y, int32_t w, int32_t h, bool filled, Color4 fg) {
SDL_Rect r = {x, y, w, h};
SDL_SetRenderDrawColor(ctx.mSDLContext.mRenderer, fg.r, fg.g, fg.b, fg.a);
SDL_SetRenderDrawColor(ctx.mSDLContext->mRenderer, fg.r, fg.g, fg.b, fg.a);
if (filled) {
SDL_RenderFillRect(ctx.mSDLContext.mRenderer, &r);
SDL_RenderFillRect(ctx.mSDLContext->mRenderer, &r);
} else {
SDL_RenderDrawRect(ctx.mSDLContext.mRenderer, &r);
SDL_RenderDrawRect(ctx.mSDLContext->mRenderer, &r);
}

return ResultOk;
Expand All @@ -380,28 +386,28 @@ ret_code Renderer::drawImage(Context &ctx, int32_t x, int32_t y, int32_t w, int3
}

SDL_Rect imageRect = {x, y, w, h};
SDL_Texture *tex = SDL_CreateTextureFromSurface(ctx.mSDLContext.mRenderer, image->mSurfaceImpl->mSurface);
SDL_RenderCopy(ctx.mSDLContext.mRenderer, tex, nullptr, &imageRect);
SDL_Texture *tex = SDL_CreateTextureFromSurface(ctx.mSDLContext->mRenderer, image->mSurfaceImpl->mSurface);
SDL_RenderCopy(ctx.mSDLContext->mRenderer, tex, nullptr, &imageRect);
SDL_DestroyTexture(tex);

return ResultOk;
}

ret_code Renderer::closeScreen(Context &ctx) {
if (ctx.mSDLContext.mWindow == nullptr) {
if (ctx.mSDLContext->mWindow == nullptr) {
return ErrorCode;
}

TTF_Quit();

SDL_DestroyWindow(ctx.mSDLContext.mWindow);
ctx.mSDLContext.mWindow = nullptr;
SDL_DestroyWindow(ctx.mSDLContext->mWindow);
ctx.mSDLContext->mWindow = nullptr;

return ResultOk;
}

ret_code Renderer::endRender(Context &ctx) {
SDL_RenderPresent(ctx.mSDLContext.mRenderer);
SDL_RenderPresent(ctx.mSDLContext->mRenderer);

return ResultOk;
}
Expand All @@ -410,7 +416,7 @@ ret_code Renderer::createRenderTexture(Context &ctx, int w, int h, SDL_Texture *
if (texture == nullptr) {
return ErrorCode;
}
*texture = SDL_CreateTexture(ctx.mSDLContext.mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, w, h);
*texture = SDL_CreateTexture(ctx.mSDLContext->mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, w, h);

return ResultOk;
}
Expand Down
30 changes: 30 additions & 0 deletions src/backends/sdl2_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,36 @@ struct FontImpl {
}
};

/// @brief The SDL context.
struct SDLContext {
SDL_Window *mWindow{ nullptr }; ///< The window.
SDL_Surface *mSurface{ nullptr }; ///< The surface.
SDL_Renderer *mRenderer{ nullptr }; ///< The renderer.
bool mOwner{ false }; ///< The owner state.

/// @brief Will create a new SDL context.
/// @return The created SDL context.
static SDLContext *create() {
return new SDLContext;
}

/// @brief Will destroy the SDL context and all its resources.
void destroy() {
if (mOwner) {
if (mRenderer != nullptr) {
SDL_DestroyRenderer(mRenderer);
mRenderer = nullptr;
}
if (mWindow != nullptr) {
SDL_DestroyWindow(mWindow);
mWindow = nullptr;
}
}
delete this;
}
};


/// @brief The renderer implementation using the SDL2 library.
struct Renderer {
static ret_code initRenderer(Context &ctx);
Expand Down
10 changes: 5 additions & 5 deletions src/tinyui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ ret_code TinyUi::getSurfaceInfo(int32_t &w, int32_t &h) {
return ErrorCode;
}

if (ctx.mSDLContext.mSurface == nullptr) {
if (ctx.mSDLContext->mSurface == nullptr) {
return ErrorCode;
}

w = ctx.mSDLContext.mSurface->w;
h = ctx.mSDLContext.mSurface->h;
w = ctx.mSDLContext->mSurface->w;
h = ctx.mSDLContext->mSurface->h;

return ResultOk;
}
Expand Down Expand Up @@ -171,8 +171,8 @@ ret_code TinyUi::release() {
}
Renderer::releaseRenderer(ctx);
Renderer::releaseScreen(ctx);
ctx.mSDLContext.mRenderer = nullptr;
ctx.mSDLContext.mWindow = nullptr;
ctx.mSDLContext->mRenderer = nullptr;
ctx.mSDLContext->mWindow = nullptr;
Comment thread
kimkulling marked this conversation as resolved.
ctx.mRoot = nullptr;

ctx.mCreated = false;
Expand Down
12 changes: 3 additions & 9 deletions src/tinyui.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ struct SurfaceImpl;
struct FontImpl;
struct Widget;

struct SDLContext;

// Type declarations ----------------------------------------------------------

/// @brief This enum is used to describe the alignment of a widget.
Expand Down Expand Up @@ -380,14 +382,6 @@ using EventDispatchMap = std::map<int32_t, EventCallbackArray>;
/// @brief Function pointer declaration for callbacks.
typedef void (*tui_log_func) (LogSeverity severity, const char *message);

/// @brief The SDL context.
struct SDLContext {
SDL_Window *mWindow{nullptr}; ///< The window.
SDL_Surface *mSurface{ nullptr }; ///< The surface.
SDL_Renderer *mRenderer{ nullptr }; ///< The renderer.
bool mOwner{ false }; ///< The owner state.
};

/// @brief The update callback list.
using UpdateCallbackList = std::list<CallbackI*>;

Expand All @@ -397,7 +391,7 @@ struct Context {
bool mRequestShutdown{false}; ///< The request shutdown state.
const char *mAppTitle{nullptr}; ///< The application title.
const char *mWindowsTitle{nullptr}; ///< The window title.
SDLContext mSDLContext; ///< The SDL context.
SDLContext *mSDLContext{ nullptr }; ///< The SDL context.
Style mStyle{}; ///< The active style.
Widget *mRoot{nullptr}; ///< The root widget.
Widget *mFocus{nullptr}; ///< The widget which is in focus.
Expand Down
20 changes: 10 additions & 10 deletions src/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void Widgets::findSelectedWidget(int x, int y, Widget *currentChild, Widget **fo

ret_code Widgets::label(Id id, Id parentId, const char *text, const Rect &rect, Alignment alignment) {
auto &ctx = TinyUi::getContext();
if (ctx.mSDLContext.mRenderer == nullptr) {
if (ctx.mSDLContext->mRenderer == nullptr) {
Comment thread
kimkulling marked this conversation as resolved.
return InvalidRenderHandle;
}

Expand All @@ -243,7 +243,7 @@ ret_code Widgets::label(Id id, Id parentId, const char *text, const Rect &rect,

ret_code Widgets::inputText(Id id, Id parentId, const Rect &rect, Alignment alignment) {
auto &ctx = TinyUi::getContext();
if (ctx.mSDLContext.mRenderer == nullptr) {
if (ctx.mSDLContext->mRenderer == nullptr) {
return InvalidRenderHandle;
}

Expand All @@ -263,7 +263,7 @@ ret_code Widgets::inputText(Id id, Id parentId, const Rect &rect, Alignment alig

ret_code Widgets::button(Id id, Id parentId, const char *text, const Rect &rect, CallbackI *callback) {
auto &ctx = TinyUi::getContext();
if (ctx.mSDLContext.mRenderer == nullptr) {
if (ctx.mSDLContext->mRenderer == nullptr) {
return InvalidRenderHandle;
}

Expand All @@ -289,7 +289,7 @@ ret_code Widgets::button(Id id, Id parentId, const char *text, const Rect &rect,

ret_code Widgets::imageButton(Id id, Id parentId, const char *image, const Rect &rect, CallbackI *callback) {
auto &ctx = TinyUi::getContext();
if (ctx.mSDLContext.mRenderer == nullptr) {
if (ctx.mSDLContext->mRenderer == nullptr) {
return InvalidRenderHandle;
}

Expand All @@ -316,7 +316,7 @@ ret_code Widgets::imageButton(Id id, Id parentId, const char *image, const Rect

ret_code Widgets::box(Id id, Id parentId, const Rect &rect, bool filled) {
auto &ctx = TinyUi::getContext();
if (ctx.mSDLContext.mRenderer == nullptr) {
if (ctx.mSDLContext->mRenderer == nullptr) {
return InvalidRenderHandle;
}

Expand All @@ -336,7 +336,7 @@ ret_code Widgets::box(Id id, Id parentId, const Rect &rect, bool filled) {

ret_code Widgets::imageBox(Id id, Id parentId, const char* image, const Rect& rect, bool filled) {
auto &ctx = TinyUi::getContext();
if (ctx.mSDLContext.mRenderer == nullptr) {
if (ctx.mSDLContext->mRenderer == nullptr) {
return InvalidRenderHandle;
}

Expand All @@ -358,7 +358,7 @@ ret_code Widgets::imageBox(Id id, Id parentId, const char* image, const Rect& re

ret_code Widgets::panel(Id id, Id parentId, const char *title, const Rect &rect, CallbackI *callback) {
auto &ctx = TinyUi::getContext();
if (ctx.mSDLContext.mRenderer == nullptr) {
if (ctx.mSDLContext->mRenderer == nullptr) {
return InvalidRenderHandle;
}

Expand Down Expand Up @@ -388,7 +388,7 @@ static int onTreeViewItemClicked(Id id, void *data) {

ret_code Widgets::treeView(Id id, Id parentId, const char *title, const Rect &rect) {
auto &ctx = TinyUi::getContext();
if (ctx.mSDLContext.mRenderer == nullptr) {
if (ctx.mSDLContext->mRenderer == nullptr) {
return InvalidRenderHandle;
}

Expand Down Expand Up @@ -417,7 +417,7 @@ ret_code Widgets::treeView(Id id, Id parentId, const char *title, const Rect &re

ret_code Widgets::treeItem(Id id, Id parentItemId, const char *text) {
auto &ctx = TinyUi::getContext();
if (ctx.mSDLContext.mRenderer == nullptr) {
if (ctx.mSDLContext->mRenderer == nullptr) {
return InvalidRenderHandle;
}

Expand Down Expand Up @@ -453,7 +453,7 @@ ret_code Widgets::treeItem(Id id, Id parentItemId, const char *text) {

ret_code Widgets::progressBar(Id id, Id parentId, const Rect &rect, int fillRate, CallbackI *callback) {
auto &ctx = TinyUi::getContext();
if (ctx.mSDLContext.mRenderer == nullptr) {
if (ctx.mSDLContext->mRenderer == nullptr) {
return InvalidRenderHandle;
}

Expand Down
Loading