Skip to content

Commit

Permalink
some ASan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mathis committed Sep 15, 2022
1 parent 1c07a5a commit 29578bf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
20 changes: 10 additions & 10 deletions Dependencies/datachannel-wasm/wasm/js/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
wsSetOpenCallback: function(ws, openCallback) {
var webSocket = WEBSOCKET.map[ws];
var cb = function() {
if(webSocket.rtcUserDeleted) return;
var userPointer = webSocket.rtcUserPointer || 0;
if(webSocket.wsUserDeleted) return;
var userPointer = webSocket.wsUserPointer || 0;
Module['dynCall']('vi', openCallback, [userPointer]);
};
webSocket.onopen = cb;
Expand All @@ -70,8 +70,8 @@
wsSetErrorCallback: function(ws, errorCallback) {
var webSocket = WEBSOCKET.map[ws];
var cb = function() {
if(webSocket.rtcUserDeleted) return;
var userPointer = webSocket.rtcUserPointer || 0;
if(webSocket.wsUserDeleted) return;
var userPointer = webSocket.wsUserPointer || 0;
Module['dynCall']('vii', errorCallback, [0, userPointer]);
};
webSocket.onerror = cb;
Expand All @@ -80,10 +80,10 @@
wsSetMessageCallback: function(ws, messageCallback) {
var webSocket = WEBSOCKET.map[ws];
webSocket.onmessage = function(evt) {
if(webSocket.rtcUserDeleted) return;
if(webSocket.wsUserDeleted) return;
if(typeof evt.data == 'string') {
var pStr = WEBSOCKET.allocUTF8FromString(evt.data);
var userPointer = webSocket.rtcUserPointer || 0;
var userPointer = webSocket.wsUserPointer || 0;
Module['dynCall']('viii', messageCallback, [pStr, -1, userPointer]);
_free(pStr);
} else {
Expand All @@ -92,14 +92,14 @@
var pBuffer = _malloc(size);
var heapBytes = new Uint8Array(Module['HEAPU8'].buffer, pBuffer, size);
heapBytes.set(byteArray);
var userPointer = webSocket.rtcUserPointer || 0;
var userPointer = webSocket.wsUserPointer || 0;
Module['dynCall']('viii', messageCallback, [pBuffer, size, userPointer]);
_free(pBuffer);
}
};
webSocket.onclose = function() {
if(webSocket.rtcUserDeleted) return;
var userPointer = webSocket.rtcUserPointer || 0;
if(webSocket.wsUserDeleted) return;
var userPointer = webSocket.wsUserPointer || 0;
Module['dynCall']('viii', messageCallback, [0, 0, userPointer]);
};
},
Expand All @@ -125,7 +125,7 @@

wsSetUserPointer: function(ws, ptr) {
var webSocket = WEBSOCKET.map[ws];
if(webSocket) webSocket.rtcUserPointer = ptr;
if(webSocket) webSocket.wsUserPointer = ptr;
},
};

Expand Down
10 changes: 6 additions & 4 deletions OpenGL/src/ui/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Component* Component::findCommonAncestor(Component* other) {
auto ancestorsB = other->findAncestors();
int i = 0;
int count = std::min(ancestorsA.size(), ancestorsB.size());
while (ancestorsA[i] == ancestorsB[i] && i < count) {
while (i < count && ancestorsA[i] == ancestorsB[i]) {
i++;
}
if (i == 0) return nullptr;
Expand All @@ -354,8 +354,8 @@ Component* Component::findRoot() {

void Component::handleEvent(Event const& evt) {
Component* target = findTargetComponent(evt.getPosition());
Component* ancestor;
if(!target) return;
Component* ancestor;

// un-hover
if(hoverComponent) {
Expand Down Expand Up @@ -391,8 +391,10 @@ void Component::handleEvent(Event const& evt) {
// bubble event (child-to-parent)
bool stop = false;
comp = target;
while(!stop && comp) {
stop = comp->applyEvent(evt);
// notice that applyEvent may result in the component being destroyed, in which case
// we absolutely don't want to call comp->parent.
// comp MUST return true (stop propagation) in that case.
while(comp && !comp->applyEvent(evt)) {
comp = comp->parent;
}
}
Expand Down
29 changes: 15 additions & 14 deletions OpenGL/src/util/AnimationMixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ void AnimationMixer::addAnim(Animation animType, Spline relatedAnimation) {

glm::vec3 AnimationMixer::computeAnim(uint32_t dt) {
glm::vec3 target;
while (dt > 0)
{
if(transition != nullptr) {
while (dt > 0) {
if(transition != nullptr) {
target = transition->compute(dt);
if(dt > 0) transition = nullptr;
}
else {
target = animations.at(currentAnimation).compute(dt);
if(dt > 0) {
std::vector<std::pair<uint32_t, glm::vec3> > keyframes;
else {
target = animations.at(currentAnimation).compute(dt);
if(dt > 0) {
std::vector<std::pair<uint32_t, glm::vec3> > keyframes;
Spline* current = &animations.at(currentAnimation);
Spline* next = &animations.at(nextAnimation);

Expand All @@ -33,7 +32,7 @@ glm::vec3 AnimationMixer::computeAnim(uint32_t dt) {
current->reset();
currentAnimation = nextAnimation;
nextAnimation = Animation::Idle;
}
}
}
}
return target;
Expand All @@ -44,24 +43,26 @@ void AnimationMixer::setAnimation(Animation anim) {
if(currentAnimation != anim && currentAnimation != Animation::Dab && (currentAnimation != Animation::Break || anim == Animation::Break)) {
std::vector<std::pair<uint32_t, glm::vec3> > keyframes;
Spline* current;
if(transition != nullptr)
if(transition)
current = transition.get();
else
current = &animations.at(currentAnimation);

Spline* next = &animations.at(anim);
Spline* next = &animations.at(anim);

uint32_t transitionTime = (uint32_t)(distance(current->getCurrentPoint(), next->getCurrentPoint()) * 1000 / std::max(current->getCurrentSpeed(), next->getCurrentSpeed()));

keyframes.emplace_back(0, current->getCurrentPoint());
keyframes.emplace_back(transitionTime, next->getCurrentPoint());
transition = std::make_unique<Spline>(keyframes, smoothing * current->getCurrentDerivative(), smoothing * -next->getCurrentDerivative());

// two-step to prevent erasing transition with may be pointed to by current.
auto newTransition = std::make_unique<Spline>(keyframes, smoothing * current->getCurrentDerivative(), smoothing * -next->getCurrentDerivative());
current->reset();
transition = move(newTransition);

currentAnimation = anim;
}else
{
}
else {
nextAnimation = anim;
}

}

0 comments on commit 29578bf

Please sign in to comment.