Skip to content

Commit

Permalink
Fix rare crash on SSE capable computers (everyone)
Browse files Browse the repository at this point in the history
This crash happens every 1 in 100000 times in obs-stream-effects 64-bit, which has the same GS::VertexBuffer wrapper as node-obs::Display and Face Masks. The crash happens due to unlucky placement of the buffers, which need to be 16-byte aligned, otherwise we write into memory that we shouldn't have written to. This results in funky crashes down the road which make absolutely no sense at all with a mdmp or a simple stack trace, since the cause of the crash happened earlier.

Affects pretty much all areas, as the Display was actively writing into memory of other areas. This might explain some exotic behavior we have seen, such as crashes inside the Chromium runtime or electron crashes.
  • Loading branch information
Xaymar committed Jan 22, 2018
1 parent d6be382 commit 8f4bbd5
Show file tree
Hide file tree
Showing 10 changed files with 945 additions and 276 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ SET(PROJECT_SOURCE
"src/nodeobs_obspp_manager.hpp" "src/nodeobs_obspp_manager.cpp"
"src/nodeobs_obspp_index.hpp" "src/nodeobs_obspp_index.cpp"
"src/nodeobs_content.h"
"src/gs-limits.h"
"src/gs-vertex.h" "src/gs-vertex.cpp"
"src/gs-vertexbuffer.h" "src/gs-vertexbuffer.cpp"
"src/util-memory.h" "src/util-memory.cpp"
)
SET(PROJECT_LIBRARIES
${CMAKE_JS_LIB}
Expand Down
26 changes: 26 additions & 0 deletions src/gs-limits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Modern effects for a modern Streamer
* Copyright (C) 2017 Michael Fabian Dirks
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

#pragma once
#include <inttypes.h>

namespace GS {
static const uint32_t MAXIMUM_VERTICES = 0xFFFFFFu;
static const uint32_t MAXIMUM_UVW_LAYERS = 8u;
}
48 changes: 48 additions & 0 deletions src/gs-vertex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Modern effects for a modern Streamer
* Copyright (C) 2017 Michael Fabian Dirks
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

#include "gs-vertex.h"
#include "util-memory.h"

GS::Vertex::Vertex() {
this->hasStore = true;
this->store = util::malloc_aligned(16, sizeof(vec3) * 3 + sizeof(uint32_t) + sizeof(vec4)*MAXIMUM_UVW_LAYERS);
this->position = reinterpret_cast<vec3*>(store);
this->normal = reinterpret_cast<vec3*>(reinterpret_cast<char*>(store) + (16 * 1));
this->tangent = reinterpret_cast<vec3*>(reinterpret_cast<char*>(store) + (16 * 2));
for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) {
this->uv[n] = reinterpret_cast<vec4*>(reinterpret_cast<char*>(store) + (16 * (2 + n)));
}
this->color = reinterpret_cast<uint32_t*>(reinterpret_cast<char*>(store) + (16 * (3 + MAXIMUM_UVW_LAYERS)));
}

GS::Vertex::~Vertex() {
if (hasStore)
util::free_aligned(store);
}

GS::Vertex::Vertex(vec3* p, vec3* n, vec3* t, uint32_t* col, vec4* uvs[MAXIMUM_UVW_LAYERS])
: position(p), normal(n), tangent(t), color(col) {
if (uvs != nullptr) {
for (size_t idx = 0; idx < MAXIMUM_UVW_LAYERS; idx++) {
this->uv[idx] = uvs[idx];
}
}
this->hasStore = false;
}
47 changes: 47 additions & 0 deletions src/gs-vertex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Modern effects for a modern Streamer
* Copyright (C) 2017 Michael Fabian Dirks
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/

#pragma once
#include "gs-limits.h"
#include <inttypes.h>
#include <xmmintrin.h>
extern "C" {
#pragma warning( push )
#pragma warning( disable: 4201 )
#include <graphics/vec3.h>
#pragma warning( pop )
}

namespace GS {
struct Vertex {
vec3* position;
vec3* normal;
vec3* tangent;
uint32_t* color;
vec4* uv[MAXIMUM_UVW_LAYERS];

Vertex();
Vertex(vec3* p, vec3* n, vec3* t, uint32_t* col, vec4* uv[MAXIMUM_UVW_LAYERS]);
~Vertex();

private:
bool hasStore;
void* store;
};
}
Loading

0 comments on commit 8f4bbd5

Please sign in to comment.