Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix: address critical correctness, safety, and robustness issues across engine

esengineb0b2df60d8be
diff --git a/sdk/src/animation/ValueTween.ts b/sdk/src/animation/ValueTween.ts
index 5ca41c60c..5aaca455b 100644
--- a/sdk/src/animation/ValueTween.ts
+++ b/sdk/src/animation/ValueTween.ts
@@ -325,6 +325,15 @@ class ValueTweenManager {
}
}
}
+
+ for (const [id, entry] of this.entries_) {
+ if (
+ entry.state === TweenState.Completed ||
+ entry.state === TweenState.Cancelled
+ ) {
+ this.entries_.delete(id);
+ }
+ }
}
pause(id: number): void {
diff --git a/sdk/src/audio/Audio.ts b/sdk/src/audio/Audio.ts
index 9c5315859..1ad9ba159 100644
--- a/sdk/src/audio/Audio.ts
+++ b/sdk/src/audio/Audio.ts
@@ -7,7 +7,7 @@ export class Audio {
private static bufferCache_ = new Map<string, AudioBufferHandle>();
private static bgmHandle_: AudioHandle | null = null;
private static bgmVolume_ = 1.0;
- private static fadeAnimId_ = 0;
+ private static fadeAnimIds_ = new Set<number>();
private static disposed_ = false;
private static assetResolver_: ((url: string) => ArrayBuffer | null) | null = null;
static baseUrl = '';
@@ -19,10 +19,10 @@ export class Audio {
this.bgmHandle_ = null;
this.bgmVolume_ = 1.0;
this.disposed_ = false;
- if (this.fadeAnimId_) {
- cancelAnimationFrame(this.fadeAnimId_);
- this.fadeAnimId_ = 0;
+ for (const id of this.fadeAnimIds_) {
+ cancelAnimationFrame(id);
}
+ this.fadeAnimIds_.clear();
}
static setAssetResolver(resolver: (url: string) => ArrayBuffer | null): void {
@@ -201,10 +201,10 @@ export class Audio {
static dispose(): void {
this.disposed_ = true;
- if (this.fadeAnimId_) {
- cancelAnimationFrame(this.fadeAnimId_);
- this.fadeAnimId_ = 0;
+ for (const id of this.fadeAnimIds_) {
+ cancelAnimationFrame(id);
}
+ this.fadeAnimIds_.clear();
if (this.bgmHandle_) {
this.bgmHandle_.stop();
this.bgmHandle_ = null;
@@ -220,33 +220,39 @@ export class Audio {
private static fadeIn(handle: AudioHandle, duration: number, targetVolume: number): void {
handle.setVolume(0);
const startTime = performance.now();
+ let animId = 0;
const tick = () => {
const elapsed = (performance.now() - startTime) / 1000;
const t = Math.min(elapsed / duration, 1);
handle.setVolume(t * targetVolume);
if (t < 1 && handle.isPlaying) {
- this.fadeAnimId_ = requestAnimationFrame(tick);
+ animId = requestAnimationFrame(tick);
+ this.fadeAnimIds_.add(animId);
} else {
- this.fadeAnimId_ = 0;
+ this.fadeAnimIds_.delete(animId);
}
};
- this.fadeAnimId_ = requestAnimationFrame(tick);
+ animId = requestAnimationFrame(tick);
+ this.fadeAnimIds_.add(animId);
}
private static fadeOut(handle: AudioHandle, duration: number, startVolume: number): void {
const startTime = performance.now();
+ let animId = 0;
const tick = () => {
const elapsed = (performance.now() - startTime) / 1000;
const t = Math.min(elapsed / duration, 1);
handle.setVolume(startVolume * (1 - t));
if (t < 1 && handle.isPlaying) {
- this.fadeAnimId_ = requestAnimationFrame(tick);
+ animId = requestAnimationFrame(tick);
+ this.fadeAnimIds_.add(animId);
} else {
handle.stop();
- this.fadeAnimId_ = 0;
+ this.fadeAnimIds_.delete(animId);
}
};
- this.fadeAnimId_ = requestAnimationFrame(tick);
+ animId = requestAnimationFrame(tick);
+ this.fadeAnimIds_.add(animId);
}
private static createDeferredHandle(): AudioHandle & { resolve(real: AudioHandle): void } {
diff --git a/sdk/src/component.ts b/sdk/src/component.ts
index c2e2164e1..0ff0bea3e 100644
--- a/sdk/src/component.ts
+++ b/sdk/src/component.ts
@@ -106,7 +106,18 @@ function createComponentDef<T extends object>(
const result = { ...defaultsRec };
for (const k of keyInfo.objectKeys) result[k] = { ...(defaultsRec[k] as object) };
for (const k of keyInfo.arrayKeys) result[k] = (defaultsRec[k] as unknown[]).slice();
- if (data) Object.assign(result, data);
+ if (data) {
+ const dataRec = data as Record<string, unknown>;
+ for (const k of Object.keys(dataRec)) {
+ if (dataRec[k] !== undefined) {
+ if (keyInfo.objectKeys.includes(k) && typeof dataRec[k] === 'object' && dataRec[k] !== null && !Array.isArray(dataRec[k])) {
+ Object.assign(result[k] as object, dataRec[k]);
+ } else {
+ result[k] = dataRec[k];
+ }
+ }
+ }
+ }
return result as T;
}
return data ? { ...defaults, ...data } : { ...defaults };
diff --git a/sdk/src/ecs/BuiltinBridge.ts b/sdk/src/ecs/BuiltinBridge.ts
index aea7f98a0..00a2096ec 100644
--- a/sdk/src/ecs/BuiltinBridge.ts
+++ b/sdk/src/ecs/BuiltinBridge.ts
@@ -359,6 +359,10 @@ export class BuiltinBridge {
};
}
+ /**
+ * Returns a getter that reads C++ component data into a shared preallocated object.
+ * WARNING: The returned object is reused across calls — copy it if you need to retain the values.
+ */
resolvePtrGetter(cppName: string): ((entity: Entity) => unknown) | null {
const accessor = PTR_ACCESSORS[cppName];
if (!accessor) return null;
diff --git a/src/esengine/animation/TimelineSystem.cpp b/src/esengine/animation/TimelineSystem.cpp
index 6765c6a0d..d7c98b81e 100644
--- a/src/esengine/animation/TimelineSystem.cpp
+++ b/src/esengine/animation/TimelineSystem.cpp
@@ -162,6 +162,10 @@ f32 TimelineSystem::evaluateChannel(const TimelineChannel& channel, f32 time) {
f32 TimelineSystem::applyWrapMode(f32 time, f32 duration, TimelineWrapMode mode, bool& stopped) {
stopped = false;
+ if (duration <= 0.0f) {
+ stopped = true;
+ return 0.0f;
+ }
if (time < 0.0f) return 0.0f;
if (time < duration) return time;
@@ -403,8 +407,14 @@ i32 TimelineSystem::evaluateAt(
// ---------------------------------------------------------------------------
i32 TimelineSystem::addEventString(const std::string& str) {
+ auto it = stringPoolIndex_.find(str);
+ if (it != stringPoolIndex_.end()) {
+ return it->second;
+ }
+ i32 idx = static_cast<i32>(stringPool_.size());
stringPool_.push_back(str);
- return static_cast<i32>(stringPool_.size()) - 1;
+ stringPoolIndex_[str] = idx;
+ return idx;
}
const std::string& TimelineSystem::getEventString(i32 index) const {
@@ -436,6 +446,7 @@ void TimelineSystem::clearPendingResults() {
pendingEvents_.clear();
pendingCustomProperties_.clear();
stringPool_.clear();
+ stringPoolIndex_.clear();
}
// ---------------------------------------------------------------------------
diff --git a/src/esengine/animation/TimelineSystem.hpp b/src/esengine/animation/TimelineSystem.hpp
index 3a7f43686..4c8c0efb3 100644
--- a/src/esengine/animation/TimelineSystem.hpp
+++ b/src/esengine/animation/TimelineSystem.hpp
@@ -107,6 +107,7 @@ private:
std::vector<TimelineEvent> pendingEvents_;
std::vector<CustomPropertyResult> pendingCustomProperties_;
std::vector<std::string> stringPool_;
+ std::unordered_map<std::string, i32> stringPoolIndex_;
static const std::string EMPTY_STRING;
};
diff --git a/src/esengine/animation/TweenSystem.cpp b/src/esengine/animation/TweenSystem.cpp
index 44b3d83b1..762cf9d9b 100644
--- a/src/esengine/animation/TweenSystem.cpp
+++ b/src/esengine/animation/TweenSystem.cpp
@@ -21,11 +21,17 @@ void TweenSystem::update(ecs::Registry& registry, f32 deltaTime) {
if (tween.delay > 0.0f) {
tween.delay -= deltaTime;
- continue;
+ if (tween.delay > 0.0f) {
+ continue;
+ }
+ deltaTime = -tween.delay;
+ tween.delay = 0.0f;
}
tween.elapsed += deltaTime;
- f32 rawT = glm::clamp(tween.elapsed / tween.duration, 0.0f, 1.0f);
+ f32 rawT = (tween.duration > 0.0f)
+ ? glm::clamp(tween.elapsed / tween.duration, 0.0f, 1.0f)
+ : 1.0f;
f32 easedT = evaluateEasing(tween, rawT);
f32 value = glm::mix(tween.from_value, tween.to_value, easedT);
diff --git a/src/esengine/app/App.cpp b/src/esengine/app/App.cpp
index bf8174c3f..85ac43b69 100644
--- a/src/esengine/app/App.cpp
+++ b/src/esengine/app/App.cpp
@@ -133,6 +133,7 @@ void App::init() {
group.init(registry_);
}
+ last_frame_time_ = platform_->getTime();
initialized_ = true;
ES_LOG_INFO("App initialized");
}
diff --git a/src/esengine/core/Engine.cpp b/src/esengine/core/Engine.cpp
index a2cee0f4e..721b9003b 100644
--- a/src/esengine/core/Engine.cpp
+++ b/src/esengine/core/Engine.cpp
@@ -67,13 +67,9 @@ bool Engine::hasWebGL2() {
}
u32 Engine::getMaxTextureSize() {
-#ifdef ES_PLATFORM_WEB
GLint maxSize = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
- return static_cast<u32>(maxSize);
-#else
- return 2048; // Default fallback
-#endif
+ return (maxSize > 0) ? static_cast<u32>(maxSize) : 2048;
}
} // namespace esengine
diff --git a/src/esengine/ecs/Registry.hpp b/src/esengine/ecs/Registry.hpp
index 055f328b7..de7c495f7 100644
--- a/src/esengine/ecs/Registry.hpp
+++ b/src/esengine/ecs/Registry.hpp
@@ -84,13 +84,15 @@ public:
*/
Entity create() {
u32 index;
- if (!recycled_.empty()) {
+ while (!recycled_.empty()) {
index = recycled_.front();
recycled_.pop();
- } else {
- index = next_index_++;
+ if (index < entityValid_.size() && entityValid_[index]) {
+ continue;
+ }
+ return activateIndex(index);
}
-
+ index = next_index_++;
return activateIndex(index);
}
@@ -594,6 +596,7 @@ private:
* @brief Activates an entity index: resizes arrays, bumps generation, returns packed Entity
*/
Entity activateIndex(u32 index) {
+ ES_ASSERT(index <= Entity::INDEX_MASK, "Entity index overflow (20-bit limit exceeded)");
if (index >= entityValid_.size()) {
entityValid_.resize(index + 1, false);
generations_.resize(index + 1, 0);
diff --git a/src/esengine/ecs/SparseSet.hpp b/src/esengine/ecs/SparseSet.hpp
index 700cbe55f..37627c2b0 100644
--- a/src/esengine/ecs/SparseSet.hpp
+++ b/src/esengine/ecs/SparseSet.hpp
@@ -269,9 +269,17 @@ public:
const u32 idx = entity.index();
const auto pageIndex = idx / SPARSE_PAGE_SIZE;
const auto offset = idx % SPARSE_PAGE_SIZE;
- const Entity last = dense_.back();
const u32 denseIdx = (*pages_[pageIndex])[offset];
+ if (denseIdx == static_cast<u32>(dense_.size()) - 1) {
+ dense_.pop_back();
+ components_.pop_back();
+ (*pages_[pageIndex])[offset] = INVALID_INDEX;
+ return;
+ }
+
+ const Entity last = dense_.back();
+
dense_[denseIdx] = last;
components_[denseIdx] = std::move(components_.back());
diff --git a/src/esengine/events/Signal.hpp b/src/esengine/events/Signal.hpp
index c147bee0b..194d80344 100644
--- a/src/esengine/events/Signal.hpp
+++ b/src/esengine/events/Signal.hpp
@@ -77,14 +77,14 @@ public:
void publish(Args... args) {
if (publishing_) {
for (const auto& [id, callback] : callbacks_) {
- if (callback) {
+ if (callback && !isPendingRemove(id)) {
callback(args...);
}
}
} else {
publishing_ = true;
for (const auto& [id, callback] : callbacks_) {
- if (callback) {
+ if (callback && !isPendingRemove(id)) {
callback(args...);
}
}
@@ -142,6 +142,13 @@ private:
/**
* @brief Process pending add/remove operations after publishing
*/
+ bool isPendingRemove(CallbackId id) const {
+ for (auto removedId : pendingRemoves_) {
+ if (removedId == id) return true;
+ }
+ return false;
+ }
+
void processPendingOperations() {
for (auto id : pendingRemoves_) {
callbacks_.erase(id);
@@ -154,6 +161,7 @@ private:
pendingAdds_.clear();
}
+ Shared<bool> alive_ = makeShared<bool>(true);
std::unordered_map<CallbackId, Callback> callbacks_;
std::vector<std::pair<CallbackId, Callback>> pendingAdds_;
std::vector<CallbackId> pendingRemoves_;
@@ -196,7 +204,7 @@ public:
publishing_ = true;
for (const auto& [id, callback] : callbacks_) {
- if (callback) {
+ if (callback && !isPendingRemove(id)) {
results.push_back(callback(args...));
}
}
@@ -215,7 +223,7 @@ public:
Ret publishFirst(Ret defaultValue, Args... args) {
publishing_ = true;
for (const auto& [id, callback] : callbacks_) {
- if (callback) {
+ if (callback && !isPendingRemove(id)) {
Ret result = callback(args...);
if (result != defaultValue) {
publishing_ = false;
@@ -258,6 +266,13 @@ private:
}
}
+ bool isPendingRemove(CallbackId id) const {
+ for (auto removedId : pendingRemoves_) {
+ if (removedId == id) return true;
+ }
+ return false;
+ }
+
void processPendingOperations() {
for (auto id : pendingRemoves_) {
callbacks_.erase(id);
@@ -270,6 +285,7 @@ private:
pendingAdds_.clear();
}
+ Shared<bool> alive_ = makeShared<bool>(true);
std::unordered_map<CallbackId, Callback> callbacks_;
std::vector<std::pair<CallbackId, Callback>> pendingAdds_;
std::vector<CallbackId> pendingRemoves_;
diff --git a/src/esengine/events/Sink.hpp b/src/esengine/events/Sink.hpp
index 56898af96..39a2f3071 100644
--- a/src/esengine/events/Sink.hpp
+++ b/src/esengine/events/Sink.hpp
@@ -68,8 +68,11 @@ public:
*/
[[nodiscard]] Connection connect(Callback callback) {
CallbackId id = signal_->connect(std::move(callback));
- return Connection(id, [signal = signal_](CallbackId callbackId) {
- signal->disconnect(callbackId);
+ Weak<bool> weak = signal_->alive_;
+ return Connection(id, [signal = signal_, weak](CallbackId callbackId) {
+ if (weak.lock()) {
+ signal->disconnect(callbackId);
+ }
});
}
@@ -131,8 +134,11 @@ public:
[[nodiscard]] Connection connect(Callback callback) {
CallbackId id = signal_->connect(std::move(callback));
- return Connection(id, [signal = signal_](CallbackId callbackId) {
- signal->disconnect(callbackId);
+ Weak<bool> weak = signal_->alive_;
+ return Connection(id, [signal = signal_, weak](CallbackId callbackId) {
+ if (weak.lock()) {
+ signal->disconnect(callbackId);
+ }
});
}
diff --git a/src/esengine/math/Math.hpp b/src/esengine/math/Math.hpp
index 5bd2524bc..305f34588 100644
--- a/src/esengine/math/Math.hpp
+++ b/src/esengine/math/Math.hpp
@@ -191,8 +191,8 @@ inline bool approxEqual(const glm::vec3& a, const glm::vec3& b, float epsilon =
* @param far Far plane distance
* @return Orthographic projection matrix
*/
-inline glm::mat4 ortho(float left, float right, float bottom, float top, float near, float far) {
- return glm::ortho(left, right, bottom, top, near, far);
+inline glm::mat4 ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane) {
+ return glm::ortho(left, right, bottom, top, nearPlane, farPlane);
}
/**
@@ -203,8 +203,8 @@ inline glm::mat4 ortho(float left, float right, float bottom, float top, float n
* @param far Far plane distance
* @return Perspective projection matrix
*/
-inline glm::mat4 perspective(float fov, float aspect, float near, float far) {
- return glm::perspective(fov, aspect, near, far);
+inline glm::mat4 perspective(float fov, float aspect, float nearPlane, float farPlane) {
+ return glm::perspective(fov, aspect, nearPlane, farPlane);
}
/**
diff --git a/src/esengine/particle/Particle.cpp b/src/esengine/particle/Particle.cpp
index 29f0305f3..9396d9156 100644
--- a/src/esengine/particle/Particle.cpp
+++ b/src/esengine/particle/Particle.cpp
@@ -43,6 +43,15 @@ void ParticlePool::clear() {
alive_count_ = 0;
}
+void ParticlePool::deallocateByIndex(u32 index) {
+ if (index >= particles_.size() || !particles_[index].alive) {
+ return;
+ }
+ particles_[index].alive = false;
+ free_list_.push_back(index);
+ alive_count_--;
+}
+
void ParticlePool::forEachAlive(const std::function<void(Particle&)>& fn) {
for (auto& p : particles_) {
if (p.alive) {
diff --git a/src/esengine/particle/Particle.hpp b/src/esengine/particle/Particle.hpp
index 12227e5d6..8f108f6a7 100644
--- a/src/esengine/particle/Particle.hpp
+++ b/src/esengine/particle/Particle.hpp
@@ -35,10 +35,15 @@ public:
u32 capacity() const { return capacity_; }
u32 aliveCount() const { return alive_count_; }
+ std::vector<Particle>& particles() { return particles_; }
+ const std::vector<Particle>& particles() const { return particles_; }
void forEachAlive(const std::function<void(Particle&)>& fn);
void forEachAlive(const std::function<void(const Particle&)>& fn) const;
+ /** @brief Deallocate a particle by its pool index */
+ void deallocateByIndex(u32 index);
+
private:
std::vector<Particle> particles_;
std::vector<u32> free_list_;
diff --git a/src/esengine/particle/ParticleSystem.cpp b/src/esengine/particle/ParticleSystem.cpp
index 6e56b184e..bf6fda1fb 100644
--- a/src/esengine/particle/ParticleSystem.cpp
+++ b/src/esengine/particle/ParticleSystem.cpp
@@ -220,13 +220,14 @@ void ParticleSystem::updateParticles(const ecs::ParticleEmitter& emitter,
auto colorEasing = static_cast<EasingType>(emitter.colorEasing);
i32 totalFrames = emitter.spriteColumns * emitter.spriteRows;
- dead_particles_.clear();
+ dead_particle_indices_.clear();
state.pool.forEachAlive([&](Particle& p) {
p.age += dt;
if (p.age >= p.lifetime) {
- dead_particles_.push_back(&p);
+ u32 idx = static_cast<u32>(&p - &state.pool.particles()[0]);
+ dead_particle_indices_.push_back(idx);
return;
}
@@ -246,9 +247,9 @@ void ParticleSystem::updateParticles(const ecs::ParticleEmitter& emitter,
f32 colorT = applyEasing(colorEasing, t);
p.color = math::lerp(p.start_color, p.end_color, colorT);
- if (totalFrames > 1) {
+ if (totalFrames > 1 && emitter.spriteFPS > 0.0f) {
f32 frameDuration = 1.0f / emitter.spriteFPS;
- u16 frame = static_cast<u16>(p.age / frameDuration);
+ u16 frame = static_cast<u16>(std::min(p.age / frameDuration, static_cast<f32>(totalFrames - 1)));
if (emitter.spriteLoop) {
frame = frame % static_cast<u16>(totalFrames);
} else {
@@ -258,8 +259,8 @@ void ParticleSystem::updateParticles(const ecs::ParticleEmitter& emitter,
}
});
- for (auto* p : dead_particles_) {
- state.pool.deallocate(p);
+ for (u32 idx : dead_particle_indices_) {
+ state.pool.deallocateByIndex(idx);
}
}
diff --git a/src/esengine/particle/ParticleSystem.hpp b/src/esengine/particle/ParticleSystem.hpp
index 442e5f639..60d9e0fa6 100644
--- a/src/esengine/particle/ParticleSystem.hpp
+++ b/src/esengine/particle/ParticleSystem.hpp
@@ -55,7 +55,7 @@ private:
std::unordered_map<Entity, EmitterState> states_;
std::mt19937 rng_;
- std::vector<Particle*> dead_particles_;
+ std::vector<u32> dead_particle_indices_;
u32 destroy_callback_id_ = 0;
};
diff --git a/src/esengine/renderer/BatchVertex.hpp b/src/esengine/renderer/BatchVertex.hpp
index aa77fab29..1b14b20bb 100644
--- a/src/esengine/renderer/BatchVertex.hpp
+++ b/src/esengine/renderer/BatchVertex.hpp
@@ -11,15 +11,6 @@ struct BatchVertex {
glm::vec2 texCoord;
};
-inline u32 packColor(const glm::vec4& c) {
- u8 r = static_cast<u8>(c.r * 255.0f + 0.5f);
- u8 g = static_cast<u8>(c.g * 255.0f + 0.5f);
- u8 b = static_cast<u8>(c.b * 255.0f + 0.5f);
- u8 a = static_cast<u8>(c.a * 255.0f + 0.5f);
- return static_cast<u32>(r) | (static_cast<u32>(g) << 8)
- | (static_cast<u32>(b) << 16) | (static_cast<u32>(a) << 24);
-}
-
inline u32 packColor(f32 r, f32 g, f32 b, f32 a) {
auto clamp = [](f32 v) -> u8 {
return static_cast<u8>(std::min(std::max(v, 0.0f), 1.0f) * 255.0f + 0.5f);
@@ -28,4 +19,8 @@ inline u32 packColor(f32 r, f32 g, f32 b, f32 a) {
| (static_cast<u32>(clamp(b)) << 16) | (static_cast<u32>(clamp(a)) << 24);
}
+inline u32 packColor(const glm::vec4& c) {
+ return packColor(c.r, c.g, c.b, c.a);
+}
+
} // namespace esengine
diff --git a/src/esengine/renderer/Framebuffer.cpp b/src/esengine/renderer/Framebuffer.cpp
index b07e8b780..9859e2168 100644
--- a/src/esengine/renderer/Framebuffer.cpp
+++ b/src/esengine/renderer/Framebuffer.cpp
@@ -18,6 +18,16 @@
#include <glad/glad.h>
#endif
+#ifndef GL_DEPTH_STENCIL
+ #define GL_DEPTH_STENCIL 0x84F9
+#endif
+#ifndef GL_UNSIGNED_INT_24_8
+ #define GL_UNSIGNED_INT_24_8 0x84FA
+#endif
+#ifndef GL_DEPTH_STENCIL_ATTACHMENT
+ #define GL_DEPTH_STENCIL_ATTACHMENT 0x821A
+#endif
+
namespace esengine {
// =============================================================================
@@ -118,13 +128,13 @@ bool Framebuffer::initialize() {
if (spec_.depthStencil) {
glGenTextures(1, &depthAttachment_);
glBindTexture(GL_TEXTURE_2D, depthAttachment_);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, spec_.width, spec_.height, 0,
- GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, spec_.width, spec_.height, 0,
+ GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_TEXTURE_2D, depthAttachment_, 0);
}
diff --git a/src/esengine/renderer/RenderFrame.cpp b/src/esengine/renderer/RenderFrame.cpp
index a1de988a7..caa8a1e4c 100644
--- a/src/esengine/renderer/RenderFrame.cpp
+++ b/src/esengine/renderer/RenderFrame.cpp
@@ -37,8 +37,10 @@ void Frustum::extractFromMatrix(const glm::mat4& vp) {
for (u32 i = 0; i < 6; ++i) {
f32 len = glm::length(planes[i].normal);
- planes[i].normal /= len;
- planes[i].distance /= len;
+ if (len > 1e-7f) {
+ planes[i].normal /= len;
+ planes[i].distance /= len;
+ }
}
}
diff --git a/src/esengine/resource/LoaderJobQueue.cpp b/src/esengine/resource/LoaderJobQueue.cpp
index 7ed9f5ea1..b38901133 100644
--- a/src/esengine/resource/LoaderJobQueue.cpp
+++ b/src/esengine/resource/LoaderJobQueue.cpp
@@ -105,13 +105,14 @@ u64 LoaderJobQueue::submit(LoadJob job) {
activeJobIds_.insert(jobId);
}
+ ES_LOG_DEBUG("LoaderJobQueue: Submitted job {} for '{}'", jobId, job.path);
+
{
std::lock_guard<std::mutex> lock(pendingMutex_);
pendingJobs_.push(std::move(job));
}
pendingCondition_.notify_one();
- ES_LOG_DEBUG("LoaderJobQueue: Submitted job {} for '{}'", jobId, job.path);
return jobId;
}
@@ -186,7 +187,7 @@ void LoaderJobQueue::workerThread() {
continue;
}
- job = std::move(const_cast<LoadJob&>(pendingJobs_.top()));
+ job = pendingJobs_.top();
pendingJobs_.pop();
}
diff --git a/src/esengine/resource/ResourcePool.hpp b/src/esengine/resource/ResourcePool.hpp
index 16e41b705..e178f6cc3 100644
--- a/src/esengine/resource/ResourcePool.hpp
+++ b/src/esengine/resource/ResourcePool.hpp
@@ -237,7 +237,7 @@ public:
* @return Count of non-freed resources
*/
usize size() const override {
- return entries_.size() - freeList_.size();
+ return entries_.size() - freeList_.size() - 1;
}
/**
@@ -247,6 +247,7 @@ public:
entries_.clear();
freeList_.clear();
pathToId_.clear();
+ entries_.push_back({nullptr, 0, "", 0});
}
/**
diff --git a/tests/resource/test_resource_pool.cpp b/tests/resource/test_resource_pool.cpp
index b3eb2cff8..b75fe9605 100644
--- a/tests/resource/test_resource_pool.cpp
+++ b/tests/resource/test_resource_pool.cpp
@@ -15,7 +15,7 @@ struct DummyResource {
using DummyHandle = esengine::resource::Handle<DummyResource>;
using DummyPool = esengine::resource::ResourcePool<DummyResource>;
-constexpr esengine::usize SENTINEL_SIZE = 1;
+constexpr esengine::usize SENTINEL_SIZE = 0;
} // namespace test