Skip to content

Commit

Permalink
Enable GL code paths with explicit define
Browse files Browse the repository at this point in the history
Replace remaining __ANDROID__/__linux__ ifdefs with specific define
OPENMOBILEMAPS_GL.
This solves various memory-related crashes in linux builds, which where
caused by specific limits (maxStylesPerGroup) that apply to GL, but
where only ifdef-ed in __ANDROID__.
  • Loading branch information
matzf committed Dec 2, 2024
1 parent 3b3bf44 commit bd99dfe
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ set_property(
PROPERTY COMPILE_DEFINITIONS
$<$<CONFIG:Debug>:LOG_LEVEL=4> # LogTrace
$<$<CONFIG:Release>:LOG_LEVEL=1>) # LogWarning
target_compile_definitions(mapscore PRIVATE OPENMOBILEMAPS_GL=1)
target_compile_features(mapscore PRIVATE cxx_std_20)
target_compile_options(mapscore PRIVATE -Werror -Wno-deprecated -Wno-reorder -fPIC) # fPIC so we can "embed" into shared mapscore_jni
target_link_libraries(mapscore ${OPENGL_LIBRARIES})
Expand Down
1 change: 1 addition & 0 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ include_directories(src/main/cpp/graphics/objects)
include_directories(src/main/cpp/graphics/shader)
include_directories(src/main/cpp/scheduling)

target_compile_definitions(mapscore PRIVATE OPENMOBILEMAPS_GL=1)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ColorLineGroup2dShaderOpenGl.h"
#include "OpenGlContext.h"
#include "OpenGlHelper.h"
#include <cassert>
#include <cstring>

ColorLineGroup2dShaderOpenGl::ColorLineGroup2dShaderOpenGl(bool projectOntoUnitSphere)
Expand Down Expand Up @@ -60,6 +61,8 @@ void ColorLineGroup2dShaderOpenGl::preRender(const std::shared_ptr<::RenderingCo
}

void ColorLineGroup2dShaderOpenGl::setStyles(const ::SharedBytes & styles) {
assert(styles.elementCount <= maxNumStyles);
assert(styles.elementCount * styles.bytesPerElement <= lineValues.size() * sizeof(float));
{
std::lock_guard<std::recursive_mutex> overlayLock(styleMutex);
if(styles.elementCount > 0) {
Expand Down
4 changes: 2 additions & 2 deletions shared/src/graphics/SceneInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* SPDX-License-Identifier: MPL-2.0
*/

#ifdef __linux__
#ifdef OPENMOBILEMAPS_GL

#include "GraphicsObjectFactoryOpenGl.h"
#include "OpenGlContext.h"
Expand All @@ -25,7 +25,7 @@ std::shared_ptr<SceneInterface> SceneInterface::create(const std::shared_ptr<::G
}

std::shared_ptr<SceneInterface> SceneInterface::createWithOpenGl() {
#ifdef __linux__
#ifdef OPENMOBILEMAPS_GL
auto scene = std::static_pointer_cast<SceneInterface>(std::make_shared<Scene>(std::make_shared<GraphicsObjectFactoryOpenGl>(),
std::make_shared<ShaderFactoryOpenGl>(),
std::make_shared<OpenGlContext>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Tiled2dMapVectorSourceSymbolDataManager:

bool persistingSymbolPlacement = false;

#ifdef __ANDROID__
#ifdef OPENMOBILEMAPS_GL
// Higher counts may cause issues for instanced text rendering
int32_t maxNumFeaturesPerGroup = 3500;
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Tiled2dMapVectorLineTile


static const int maxNumLinePoints = std::numeric_limits<uint16_t>::max() / 4 + 1; // 4 vertices per line coord, only 2 at the start/end
#ifdef __ANDROID__
#ifdef OPENMOBILEMAPS_GL
static const int maxStylesPerGroup = 32;
#else
static const int maxStylesPerGroup = 256;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Tiled2dMapVectorPolygonPatternTile

void setupTextureCoordinates();

#ifdef __ANDROID__
#ifdef OPENMOBILEMAPS_GL
static const int maxStylesPerGroup = 16;
#else
static const int maxStylesPerGroup = 256;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Tiled2dMapVectorPolygonTile

void setupPolygons(const std::vector<std::shared_ptr<GraphicsObjectInterface>> &newPolygonObjects);

#ifdef __ANDROID__
#ifdef OPENMOBILEMAPS_GL
static const int maxStylesPerGroup = 16;
#else
static const int maxStylesPerGroup = 256;
Expand Down

0 comments on commit bd99dfe

Please sign in to comment.