Last active
May 30, 2020 14:35
-
-
Save Twinklebear/3b247c6ee1a76091d3f37057d6fb237e to your computer and use it in GitHub Desktop.
SDL2 + TBB Malloc Proxy Repro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.5) | |
project(sdl2_test) | |
find_package(SDL2 REQUIRED) | |
find_package(OpenGL REQUIRED) | |
find_package(TBB REQUIRED) | |
add_executable(sdl2_test | |
main.cpp) | |
set_target_properties(sdl2_test PROPERTIES | |
CXX_STANDARD 14 | |
CXX_STANDARD_REQUIRED ON) | |
target_include_directories(sdl2_test PUBLIC | |
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/glad/include/> | |
$<BUILD_INTERFACE:${SDL2_INCLUDE_DIRS}> | |
$<BUILD_INTERFACE:${OPENGL_INCLUDE_DIR}>) | |
target_link_libraries(sdl2_test PUBLIC | |
TBB::tbb | |
${SDL2_LIBRARIES} | |
${OPENGL_LIBRARY}) | |
option(LINK_TBB_MALLOC "Link TBB malloc and malloc_proxy to show bug" OFF) | |
if (LINK_TBB_MALLOC) | |
target_link_libraries(sdl2_test PUBLIC | |
TBB::tbbmalloc | |
TBB::tbbmalloc_proxy) | |
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <SDL.h> | |
#include <OpenGL/gl.h> | |
int win_width = 512; | |
int win_height = 512; | |
int main(int argc, const char **argv) | |
{ | |
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { | |
std::cerr << "Failed to init SDL: " << SDL_GetError() << "\n"; | |
return -1; | |
} | |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); | |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); | |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); | |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); | |
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); | |
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); | |
SDL_Window *window = SDL_CreateWindow("Test App", | |
SDL_WINDOWPOS_CENTERED, | |
SDL_WINDOWPOS_CENTERED, | |
win_width, | |
win_height, | |
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); | |
SDL_GLContext gl_context = SDL_GL_CreateContext(window); | |
SDL_GL_SetSwapInterval(1); | |
SDL_GL_MakeCurrent(window, gl_context); | |
glClearColor(0.f, 0.f, 1.f, 1.f); | |
bool done = false; | |
while (!done) { | |
SDL_Event event; | |
while (SDL_PollEvent(&event)) { | |
if (event.type == SDL_QUIT) { | |
done = true; | |
} | |
if (event.type == SDL_KEYDOWN) { | |
if (event.key.keysym.sym == SDLK_ESCAPE) { | |
done = true; | |
} | |
} | |
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && | |
event.window.windowID == SDL_GetWindowID(window)) { | |
done = true; | |
} | |
} | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
SDL_GL_SwapWindow(window); | |
} | |
SDL_GL_DeleteContext(gl_context); | |
SDL_DestroyWindow(window); | |
SDL_Quit(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment