mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 11:42:51 +02:00
Merge pull request #15558 from AndrewMeadows/fix-crash-bugz178
BUGZ-178: avoid crash for RenderableModelEntityItem with invalid model
This commit is contained in:
commit
fbe947c8ac
3 changed files with 18 additions and 15 deletions
|
@ -361,6 +361,12 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
|
||||||
const uint32_t QUAD_STRIDE = 4;
|
const uint32_t QUAD_STRIDE = 4;
|
||||||
|
|
||||||
ShapeType type = getShapeType();
|
ShapeType type = getShapeType();
|
||||||
|
|
||||||
|
auto model = getModel();
|
||||||
|
if (!model) {
|
||||||
|
type = SHAPE_TYPE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == SHAPE_TYPE_COMPOUND) {
|
if (type == SHAPE_TYPE_COMPOUND) {
|
||||||
updateModelBounds();
|
updateModelBounds();
|
||||||
|
|
||||||
|
@ -442,10 +448,6 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
|
||||||
// to the visual model and apply them to the collision model (without regard for the
|
// to the visual model and apply them to the collision model (without regard for the
|
||||||
// collision model's extents).
|
// collision model's extents).
|
||||||
|
|
||||||
auto model = getModel();
|
|
||||||
// assert we never fall in here when model not fully loaded
|
|
||||||
assert(model && model->isLoaded());
|
|
||||||
|
|
||||||
glm::vec3 dimensions = getScaledDimensions();
|
glm::vec3 dimensions = getScaledDimensions();
|
||||||
glm::vec3 scaleToFit = dimensions / model->getHFMModel().getUnscaledMeshExtents().size();
|
glm::vec3 scaleToFit = dimensions / model->getHFMModel().getUnscaledMeshExtents().size();
|
||||||
// multiply each point by scale before handing the point-set off to the physics engine.
|
// multiply each point by scale before handing the point-set off to the physics engine.
|
||||||
|
@ -461,7 +463,6 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) {
|
||||||
adjustShapeInfoByRegistration(shapeInfo);
|
adjustShapeInfoByRegistration(shapeInfo);
|
||||||
} else if (type >= SHAPE_TYPE_SIMPLE_HULL && type <= SHAPE_TYPE_STATIC_MESH) {
|
} else if (type >= SHAPE_TYPE_SIMPLE_HULL && type <= SHAPE_TYPE_STATIC_MESH) {
|
||||||
updateModelBounds();
|
updateModelBounds();
|
||||||
auto model = getModel();
|
|
||||||
// assert we never fall in here when model not fully loaded
|
// assert we never fall in here when model not fully loaded
|
||||||
assert(model && model->isLoaded());
|
assert(model && model->isLoaded());
|
||||||
model->updateGeometry();
|
model->updateGeometry();
|
||||||
|
|
|
@ -294,9 +294,7 @@ void ModelEntityItem::setModelURL(const QString& url) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
if (_modelURL != url) {
|
if (_modelURL != url) {
|
||||||
_modelURL = url;
|
_modelURL = url;
|
||||||
if (_shapeType == SHAPE_TYPE_STATIC_MESH) {
|
_flags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS;
|
||||||
_flags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -329,11 +327,8 @@ const Transform ModelEntityItem::getTransform(bool& success, int depth) const {
|
||||||
void ModelEntityItem::setCompoundShapeURL(const QString& url) {
|
void ModelEntityItem::setCompoundShapeURL(const QString& url) {
|
||||||
withWriteLock([&] {
|
withWriteLock([&] {
|
||||||
if (_compoundShapeURL.get() != url) {
|
if (_compoundShapeURL.get() != url) {
|
||||||
ShapeType oldType = computeTrueShapeType();
|
|
||||||
_compoundShapeURL.set(url);
|
_compoundShapeURL.set(url);
|
||||||
if (oldType != computeTrueShapeType()) {
|
_flags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS;
|
||||||
_flags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,12 +249,19 @@ void PhysicalEntitySimulation::buildMotionStatesForEntitiesThatNeedThem() {
|
||||||
btCollisionShape* shape = const_cast<btCollisionShape*>(ObjectMotionState::getShapeManager()->getShapeByKey(requestItr->shapeHash));
|
btCollisionShape* shape = const_cast<btCollisionShape*>(ObjectMotionState::getShapeManager()->getShapeByKey(requestItr->shapeHash));
|
||||||
if (shape) {
|
if (shape) {
|
||||||
// shape is ready at last!
|
// shape is ready at last!
|
||||||
// But the entity's desired shape might have changed since last requested
|
// but the entity's physics desired physics status may have changed since last requested
|
||||||
// --> rebuild the ShapeInfo to verify hash
|
if (!entity->shouldBePhysical()) {
|
||||||
|
requestItr = _shapeRequests.erase(requestItr);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// rebuild the ShapeInfo to verify hash because entity's desired shape may have changed
|
||||||
// TODO? is there a better way to do this?
|
// TODO? is there a better way to do this?
|
||||||
ShapeInfo shapeInfo;
|
ShapeInfo shapeInfo;
|
||||||
entity->computeShapeInfo(shapeInfo);
|
entity->computeShapeInfo(shapeInfo);
|
||||||
if (shapeInfo.getHash() != requestItr->shapeHash) {
|
|
||||||
|
if (shapeInfo.getType() == SHAPE_TYPE_NONE) {
|
||||||
|
requestItr = _shapeRequests.erase(requestItr);
|
||||||
|
} else if (shapeInfo.getHash() != requestItr->shapeHash) {
|
||||||
// bummer, the hashes are different and we no longer want the shape we've received
|
// bummer, the hashes are different and we no longer want the shape we've received
|
||||||
ObjectMotionState::getShapeManager()->releaseShape(shape);
|
ObjectMotionState::getShapeManager()->releaseShape(shape);
|
||||||
// try again
|
// try again
|
||||||
|
|
Loading…
Reference in a new issue