Skip to content

Commit 09dfd13

Browse files
committed
Initialize image and release
1 parent e74d573 commit 09dfd13

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

modules/camera/camera_web.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ void CameraFeedWeb::_on_denied_callback(void *context) {
7373
bool CameraFeedWeb::activate_feed() {
7474
ERR_FAIL_COND_V_MSG(selected_format == -1, false, "CameraFeed format needs to be set before activating.");
7575

76+
// Initialize image when activating the feed
77+
if (image.is_null()) {
78+
image.instantiate();
79+
}
80+
7681
int width = parameters.get(KEY_WIDTH, 0);
7782
int height = parameters.get(KEY_HEIGHT, 0);
7883
// Firefox ESR (128.11.0esr) does not implement MediaStreamTrack.getCapabilities(), so 'formats' will be empty.
@@ -87,6 +92,9 @@ bool CameraFeedWeb::activate_feed() {
8792

8893
void CameraFeedWeb::deactivate_feed() {
8994
CameraDriverWeb::get_singleton()->stop_stream(device_id);
95+
// Release the image when deactivating the feed
96+
image.unref();
97+
data.clear();
9098
}
9199

92100
bool CameraFeedWeb::set_format(int p_index, const Dictionary &p_parameters) {
@@ -124,8 +132,6 @@ CameraFeedWeb::CameraFeedWeb(const CameraInfo &info) {
124132
feed_format.height = info.capability.height;
125133
feed_format.format = String("RGBA");
126134
formats.append(feed_format);
127-
128-
image.instantiate();
129135
}
130136

131137
CameraFeedWeb::~CameraFeedWeb() {

0 commit comments

Comments
 (0)