Skip to content

Commit 031b71f

Browse files
committed
Merge pull request godotengine#95103 from jamie-pate/fix_89119
Fix LightmapGI causes crash when using --headless
2 parents 1260bfb + f8c99ef commit 031b71f

File tree

3 files changed

+123
-6
lines changed

3 files changed

+123
-6
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**************************************************************************/
2+
/* light_storage.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include "light_storage.h"
32+
33+
using namespace RendererDummy;
34+
35+
LightStorage *LightStorage::singleton = nullptr;
36+
37+
LightStorage *LightStorage::get_singleton() {
38+
return singleton;
39+
}
40+
41+
LightStorage::LightStorage() {
42+
singleton = this;
43+
}
44+
45+
LightStorage::~LightStorage() {
46+
singleton = nullptr;
47+
}
48+
49+
bool LightStorage::free(RID p_rid) {
50+
if (owns_lightmap(p_rid)) {
51+
lightmap_free(p_rid);
52+
return true;
53+
} else if (owns_lightmap_instance(p_rid)) {
54+
lightmap_instance_free(p_rid);
55+
return true;
56+
}
57+
58+
return false;
59+
}
60+
61+
/* LIGHTMAP API */
62+
63+
RID LightStorage::lightmap_allocate() {
64+
return lightmap_owner.allocate_rid();
65+
}
66+
67+
void LightStorage::lightmap_initialize(RID p_lightmap) {
68+
lightmap_owner.initialize_rid(p_lightmap, Lightmap());
69+
}
70+
71+
void LightStorage::lightmap_free(RID p_rid) {
72+
lightmap_set_textures(p_rid, RID(), false);
73+
lightmap_owner.free(p_rid);
74+
}
75+
76+
/* LIGHTMAP INSTANCE */
77+
78+
RID LightStorage::lightmap_instance_create(RID p_lightmap) {
79+
LightmapInstance li;
80+
li.lightmap = p_lightmap;
81+
return lightmap_instance_owner.make_rid(li);
82+
}
83+
84+
void LightStorage::lightmap_instance_free(RID p_lightmap) {
85+
lightmap_instance_owner.free(p_lightmap);
86+
}

servers/rendering/dummy/storage/light_storage.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,29 @@
3636
namespace RendererDummy {
3737

3838
class LightStorage : public RendererLightStorage {
39+
private:
40+
static LightStorage *singleton;
41+
/* LIGHTMAP */
42+
struct Lightmap {
43+
// dummy lightmap, no data
44+
};
45+
46+
mutable RID_Owner<Lightmap, true> lightmap_owner;
47+
/* LIGHTMAP INSTANCE */
48+
49+
struct LightmapInstance {
50+
RID lightmap;
51+
};
52+
53+
mutable RID_Owner<LightmapInstance> lightmap_instance_owner;
54+
3955
public:
56+
static LightStorage *get_singleton();
57+
58+
LightStorage();
59+
virtual ~LightStorage();
60+
61+
bool free(RID p_rid);
4062
/* Light API */
4163

4264
virtual RID directional_light_allocate() override { return RID(); }
@@ -146,9 +168,11 @@ class LightStorage : public RendererLightStorage {
146168

147169
/* LIGHTMAP CAPTURE */
148170

149-
virtual RID lightmap_allocate() override { return RID(); }
150-
virtual void lightmap_initialize(RID p_rid) override {}
151-
virtual void lightmap_free(RID p_rid) override {}
171+
bool owns_lightmap(RID p_rid) { return lightmap_owner.owns(p_rid); }
172+
173+
virtual RID lightmap_allocate() override;
174+
virtual void lightmap_initialize(RID p_rid) override;
175+
virtual void lightmap_free(RID p_rid) override;
152176

153177
virtual void lightmap_set_textures(RID p_lightmap, RID p_light, bool p_uses_spherical_haromics) override {}
154178
virtual void lightmap_set_probe_bounds(RID p_lightmap, const AABB &p_bounds) override {}
@@ -167,8 +191,10 @@ class LightStorage : public RendererLightStorage {
167191

168192
/* LIGHTMAP INSTANCE */
169193

170-
RID lightmap_instance_create(RID p_lightmap) override { return RID(); }
171-
void lightmap_instance_free(RID p_lightmap) override {}
194+
bool owns_lightmap_instance(RID p_rid) { return lightmap_instance_owner.owns(p_rid); }
195+
196+
RID lightmap_instance_create(RID p_lightmap) override;
197+
void lightmap_instance_free(RID p_lightmap) override;
172198
void lightmap_instance_set_transform(RID p_lightmap, const Transform3D &p_transform) override {}
173199

174200
/* SHADOW ATLAS API */

servers/rendering/dummy/storage/utilities.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#ifndef UTILITIES_DUMMY_H
3232
#define UTILITIES_DUMMY_H
3333

34+
#include "light_storage.h"
3435
#include "material_storage.h"
3536
#include "mesh_storage.h"
3637
#include "servers/rendering/storage/utilities.h"
@@ -55,12 +56,16 @@ class Utilities : public RendererUtilities {
5556
return RS::INSTANCE_MESH;
5657
} else if (RendererDummy::MeshStorage::get_singleton()->owns_multimesh(p_rid)) {
5758
return RS::INSTANCE_MULTIMESH;
59+
} else if (RendererDummy::LightStorage::get_singleton()->owns_lightmap(p_rid)) {
60+
return RS::INSTANCE_LIGHTMAP;
5861
}
5962
return RS::INSTANCE_NONE;
6063
}
6164

6265
virtual bool free(RID p_rid) override {
63-
if (RendererDummy::TextureStorage::get_singleton()->owns_texture(p_rid)) {
66+
if (RendererDummy::LightStorage::get_singleton()->free(p_rid)) {
67+
return true;
68+
} else if (RendererDummy::TextureStorage::get_singleton()->owns_texture(p_rid)) {
6469
RendererDummy::TextureStorage::get_singleton()->texture_free(p_rid);
6570
return true;
6671
} else if (RendererDummy::MeshStorage::get_singleton()->owns_mesh(p_rid)) {

0 commit comments

Comments
 (0)