Skip to content

Commit 7c65de5

Browse files
ramses-tech-usernVxxbojackHaasmanmohhsharafsmirko-dev
committed
Oss release v1.2.2 created 2022-10-05-09-56
see CHANGELOG.md for details Original commit sha: 340e202f98b3c88d432a6d35dce95908f5450214 Co-authored-by: Askanaz Torosyan <[email protected]> Co-authored-by: Daniel Haas <[email protected]> Co-authored-by: Mohamed Sharaf-El-Deen <[email protected]> Co-authored-by: Mirko Sova <[email protected]> Co-authored-by: Tobias Hammer <[email protected]> Co-authored-by: Violin Yanev <[email protected]>
1 parent e648e0d commit 7c65de5

File tree

13 files changed

+240
-15
lines changed

13 files changed

+240
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
# Unreleased
44

5-
**CHANGED**
5+
# v1.2.2
66

77
**ADDED**
88

9+
* Added LogicEngine::loadFromFileDescriptor() to load logic files with an open file descriptor
10+
911
**FIXED**
1012

13+
* Scripts (and other nodes) with no input or no output properties do not fail validation anymore,
14+
only nodes with actual properties on each input/output side are checked if they are linked
15+
1116
# v1.2.1
1217

1318
**FIXED**

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cmake_minimum_required(VERSION 3.13)
1515

1616
set(RLOGIC_VERSION_MAJOR 1)
1717
set(RLOGIC_VERSION_MINOR 2)
18-
set(RLOGIC_VERSION_PATCH 1)
18+
set(RLOGIC_VERSION_PATCH 2)
1919

2020
set(RLOGIC_VERSION ${RLOGIC_VERSION_MAJOR}.${RLOGIC_VERSION_MINOR}.${RLOGIC_VERSION_PATCH})
2121
set(ramses-logic_VERSION "${RLOGIC_VERSION}" CACHE STRING "Ramses Logic version" FORCE)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ existing files exported with Logic Engine version **W** or newer (Binary file co
4040

4141
|Logic | Included Ramses version | Minimum required Ramses version | Binary file compatibility |
4242
|----------|-------------------------------|------------------------------------|------------------------------|
43+
|v1.2.2 | 27.0.125 | 27.0.102 | >= 1.0.0, F-Levels 01 - 03 |
4344
|v1.2.1 | 27.0.125 | 27.0.102 | >= 1.0.0, F-Levels 01 - 03 |
4445
|v1.2.0 | 27.0.122 | 27.0.102 | >= 1.0.0, F-Levels 01 - 03 |
4546
|v1.1.x | 27.0.121 | 27.0.102 | >= 1.0.0, F-Levels 01, 02 |

include/ramses-logic/LogicEngine.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,23 @@ namespace rlogic
658658
*/
659659
RLOGIC_API bool loadFromFile(std::string_view filename, ramses::Scene* ramsesScene = nullptr, bool enableMemoryVerification = true);
660660

661+
/**
662+
* Loads the whole LogicEngine data from the given file descriptor. This method is equivalent to #loadFromFile().
663+
*
664+
* The file descriptor must be opened for read access and must support seeking.
665+
* It will be in closed state after this call.
666+
*
667+
* @param[in] fd Open and readable filedescriptor.
668+
* @param[in] offset Absolute starting position of LogicEngine data within fd.
669+
* @param[in] length Size of the data within fd.
670+
* @param ramsesScene pointer to the Ramses Scene which holds the objects referenced in the Ramses Logic file
671+
* @param enableMemoryVerification flag to enable memory verifier (a flatbuffers feature which checks bounds and ranges).
672+
* Disable this only if the file comes from a trusted source and performance is paramount.
673+
* @return true if deserialization was successful, false otherwise. To get more detailed
674+
* error information use #getErrors()
675+
*/
676+
RLOGIC_API bool loadFromFileDescriptor(int fd, size_t offset, size_t length, ramses::Scene* ramsesScene = nullptr, bool enableMemoryVerification = true);
677+
661678
/**
662679
* Loads the whole LogicEngine data from the given memory buffer. This method is equivalent to
663680
* #loadFromFile but allows to have the file-opening

lib/impl/LogicEngine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ namespace rlogic
219219
return m_impl->loadFromFile(filename, ramsesScene, enableMemoryVerification);
220220
}
221221

222+
bool LogicEngine::loadFromFileDescriptor(int fd, size_t offset, size_t length, ramses::Scene* ramsesScene /* = nullptr*/, bool enableMemoryVerification /* = true */)
223+
{
224+
return m_impl->loadFromFileDescriptor(fd, offset, length, ramsesScene, enableMemoryVerification);
225+
}
226+
222227
bool LogicEngine::loadFromBuffer(const void* rawBuffer, size_t bufferSize, ramses::Scene* ramsesScene /* = nullptr*/, bool enableMemoryVerification /* = true */)
223228
{
224229
return m_impl->loadFromBuffer(rawBuffer, bufferSize, ramsesScene, enableMemoryVerification);

lib/impl/LogicEngineImpl.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,27 @@ namespace rlogic::internal
438438
return loadFromByteData((*maybeBytesFromFile).data(), fileSize, scene, enableMemoryVerification, fmt::format("file '{}' (size: {})", filename, fileSize));
439439
}
440440

441+
bool LogicEngineImpl::loadFromFileDescriptor(int fd, size_t offset, size_t size, ramses::Scene* scene, bool enableMemoryVerification)
442+
{
443+
if (fd <= 0)
444+
{
445+
m_errors.add(fmt::format("Invalid file descriptor: {}", fd), nullptr, EErrorType::BinaryDataAccessError);
446+
return false;
447+
}
448+
if (size == 0)
449+
{
450+
m_errors.add("Failed to load from file descriptor: size may not be 0", nullptr, EErrorType::BinaryDataAccessError);
451+
return false;
452+
}
453+
std::optional<std::vector<char>> maybeBytesFromFile = FileUtils::LoadBinary(fd, offset, size);
454+
if (!maybeBytesFromFile)
455+
{
456+
m_errors.add(fmt::format("Failed to load from file descriptor: fd: {} offset: {} size: {}", fd, offset, size), nullptr, EErrorType::BinaryDataAccessError);
457+
return false;
458+
}
459+
return loadFromByteData((*maybeBytesFromFile).data(), size, scene, enableMemoryVerification, fmt::format("fd: {} (offset: {}, size: {})", fd, offset, size));
460+
}
461+
441462
bool LogicEngineImpl::checkFileIdentifierBytes(const std::string& dataSourceDescription, const std::string& fileIdBytes)
442463
{
443464
const std::string expected = getFileIdentifierMatchingFeatureLevel();

lib/impl/LogicEngineImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ namespace rlogic::internal
111111
const std::vector<WarningData>& validate() const;
112112

113113
bool loadFromFile(std::string_view filename, ramses::Scene* scene, bool enableMemoryVerification);
114+
bool loadFromFileDescriptor(int fd, size_t offset, size_t size, ramses::Scene* scene, bool enableMemoryVerification);
114115
bool loadFromBuffer(const void* rawBuffer, size_t bufferSize, ramses::Scene* scene, bool enableMemoryVerification);
115116
bool saveToFile(std::string_view filename, const SaveFileConfigImpl& config);
116117
[[nodiscard]] static bool GetFeatureLevelFromFile(std::string_view filename, EFeatureLevel& detectedFeatureLevel);

lib/internals/ApiObjects.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -736,13 +736,16 @@ namespace rlogic::internal
736736
continue;
737737

738738
assert(objAsNode->getOutputs() != nullptr);
739+
// only check for unlinked outputs if there are any
740+
if (objAsNode->getOutputs()->getChildCount() != 0u)
741+
{
742+
bool anyOutputLinked = false;
743+
for (const auto* output : objAsNode->getOutputs()->m_impl->collectLeafChildren())
744+
anyOutputLinked |= (output->hasOutgoingLink());
739745

740-
bool anyOutputLinked = false;
741-
for(const auto* output : objAsNode->getOutputs()->m_impl->collectLeafChildren())
742-
anyOutputLinked |= (output->hasOutgoingLink());
743-
744-
if (!anyOutputLinked)
745-
validationResults.add(fmt::format("Node [{}] has no outgoing links! Node should be deleted or properly linked!", objAsNode->getName()), objAsNode, EWarningType::UnusedContent);
746+
if (!anyOutputLinked)
747+
validationResults.add(fmt::format("Node [{}] has no outgoing links! Node should be deleted or properly linked!", objAsNode->getName()), objAsNode, EWarningType::UnusedContent);
748+
}
746749
}
747750
}
748751

@@ -760,13 +763,16 @@ namespace rlogic::internal
760763
continue;
761764

762765
assert(objAsNode->getInputs() != nullptr);
766+
// only check for unlinked inputs if there are any
767+
if (objAsNode->getInputs()->getChildCount() != 0u)
768+
{
769+
bool anyInputLinked = false;
770+
for (const auto* input : objAsNode->getInputs()->m_impl->collectLeafChildren())
771+
anyInputLinked |= (input->hasIncomingLink());
763772

764-
bool anyInputLinked = false;
765-
for (const auto* input : objAsNode->getInputs()->m_impl->collectLeafChildren())
766-
anyInputLinked |= (input->hasIncomingLink());
767-
768-
if (!anyInputLinked)
769-
validationResults.add(fmt::format("Node [{}] has no ingoing links! Node should be deleted or properly linked!", objAsNode->getName()), objAsNode, EWarningType::UnusedContent);
773+
if (!anyInputLinked)
774+
validationResults.add(fmt::format("Node [{}] has no ingoing links! Node should be deleted or properly linked!", objAsNode->getName()), objAsNode, EWarningType::UnusedContent);
775+
}
770776
}
771777
}
772778
}

lib/internals/FileUtils.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,28 @@ namespace rlogic::internal
4747

4848
return byteBuffer;
4949
}
50+
51+
std::optional<std::vector<char>> FileUtils::LoadBinary(int fd, size_t offset, size_t size)
52+
{
53+
std::unique_ptr<FILE, decltype(&fclose)> file(fdopen(fd, "rb"), &fclose);
54+
if (!file)
55+
{
56+
return std::nullopt;
57+
}
58+
59+
// NOLINTNEXTLINE(google-runtime-int) long cast required to match with fseek declaration
60+
if (fseek(file.get(), static_cast<long>(offset), SEEK_SET) != 0)
61+
{
62+
return std::nullopt;
63+
}
64+
65+
std::vector<char> byteBuffer(size);
66+
67+
const auto bytesRead = fread(byteBuffer.data(), 1, size, file.get());
68+
if (bytesRead != size)
69+
{
70+
return std::nullopt;
71+
}
72+
return byteBuffer;
73+
}
5074
}

lib/internals/FileUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ namespace rlogic::internal
1919
public:
2020
static bool SaveBinary(const std::string& filename, const void* binaryBuffer, size_t bufferLength);
2121
static std::optional<std::vector<char>> LoadBinary(const std::string& filename);
22+
static std::optional<std::vector<char>> LoadBinary(int fd, size_t offset, size_t size);
2223
};
2324
}

0 commit comments

Comments
 (0)