Skip to content

Commit

Permalink
Make FamilyBase ID generator function non-inline
Browse files Browse the repository at this point in the history
Previously the function body was defined inline in the class body. For some toolchains (particularly discovered with LLVM on MinGW), different dynamic libraries call into different definitions of the function. This can lead to the same IDs being used even for different types, which can lead to issues and potentially crashes. This commit moves it to the CPP file so that all binaries call into the same function exported by the RmlUi library.

This commit does not change the fact that different binaries can still produce different IDs for the same type. However, that situation can generally be handled safely.
  • Loading branch information
mikke89 committed Oct 23, 2024
1 parent 7a8acea commit 36af609
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
8 changes: 2 additions & 6 deletions Include/RmlUi/Core/Traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,14 @@ enum class FamilyId : int {};

class RMLUICORE_API FamilyBase {
protected:
static int GetNewId()
{
static int id = 0;
return id++;
}
static int GetNewId();
};

template <typename T>
class Family : FamilyBase {
public:
// Get a unique ID for a given type.
// Note: IDs will be unique across DLL-boundaries even for the same type.
// Note: An ID for a given type may not match across DLL-boundaries.
static FamilyId Id()
{
static int id = GetNewId();
Expand Down
1 change: 1 addition & 0 deletions Source/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ add_library(rmlui_core
TextureLayoutRow.h
TextureLayoutTexture.cpp
TextureLayoutTexture.h
Traits.cpp
Transform.cpp
TransformPrimitive.cpp
TransformState.cpp
Expand Down
38 changes: 38 additions & 0 deletions Source/Core/Traits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This source file is part of RmlUi, the HTML/CSS Interface Middleware
*
* For the latest information, see http://github.com/mikke89/RmlUi
*
* Copyright (c) 2019-2024 The RmlUi Team, and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

#include "../../Include/RmlUi/Core/Traits.h"

namespace Rml {

int FamilyBase::GetNewId()
{
static int id = 0;
return id++;
}

} // namespace Rml

0 comments on commit 36af609

Please sign in to comment.