From b2e0de81657443d271adfb8322e0690e48c0ca08 Mon Sep 17 00:00:00 2001
From: pudingus <39903631+pudingus@users.noreply.github.com>
Date: Sun, 8 Aug 2021 18:41:05 +0200
Subject: [PATCH] Fix nspec crash related to Editable Poly
---
plugins/nspec/nspec.cpp | 33 +++++++++++++++++++++++++++++++-
plugins/nspec/nspec_2014.vcxproj | 1 -
plugins/nspec/nspec_2015.vcxproj | 1 -
plugins/nspec/nspec_2020.vcxproj | 2 +-
scripts/max4ds/init.ms | 2 +-
5 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/plugins/nspec/nspec.cpp b/plugins/nspec/nspec.cpp
index 9df4a01..0db341c 100644
--- a/plugins/nspec/nspec.cpp
+++ b/plugins/nspec/nspec.cpp
@@ -104,19 +104,32 @@ class FP_Basic : public IFP_Basic
{
public:
int GetNumNormals(Mesh& mesh) {
+ if (&mesh == nullptr) throw MAXException(L"mesh is nullptr");
+
+ mesh.SpecifyNormals();
MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (nspec == nullptr) return 0;
return nspec->GetNumNormals();
}
int GetNumFaces(Mesh& mesh) {
+ if (&mesh == nullptr) throw MAXException(L"mesh is nullptr");
+
+ mesh.SpecifyNormals();
MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (nspec == nullptr) return 0;
return nspec->GetNumFaces();
}
Point3& GetNormal(Mesh& mesh, int normID) {
+ if (&mesh == nullptr) throw MAXException(L"mesh is nullptr");
+
+ mesh.SpecifyNormals();
MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (nspec == nullptr) throw MAXException(L"nspec is nullptr");
+
int numNormals = nspec->GetNumNormals();
if (normID > numNormals || normID < 1) throw MAXException(L"normID out of valid range");
@@ -127,7 +140,12 @@ class FP_Basic : public IFP_Basic
int GetNormalId(Mesh& mesh, int face, int corner) {
+ if (&mesh == nullptr) throw MAXException(L"mesh is nullptr");
+
+ mesh.SpecifyNormals();
MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (nspec == nullptr) throw MAXException(L"nspec is nullptr");
+
int numFaces = nspec->GetNumFaces();
if (face > numFaces || face < 1) throw MAXException(L"face out of valid range");
if (corner > 3 || corner < 1) throw MAXException(L"corner out of valid range");
@@ -136,26 +154,32 @@ class FP_Basic : public IFP_Basic
}
bool SetNumNormals(Mesh& mesh, int numNormals) {
+ if (&mesh == nullptr) throw MAXException(L"mesh is nullptr");
if (numNormals < 0) throw MAXException(L"numNormals out of valid range");
mesh.SpecifyNormals(); //needed in 'Set...' functions or Max crashes, when setting it on new TriMeshes
MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (nspec == nullptr) throw MAXException(L"nspec is nullptr");
return nspec->SetNumNormals(numNormals);
}
bool SetNumFaces(Mesh& mesh, int numFaces) {
+ if (&mesh == nullptr) throw MAXException(L"mesh is nullptr");
if (numFaces < 0) throw MAXException(L"numFaces out of valid range");
mesh.SpecifyNormals();
MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (nspec == nullptr) throw MAXException(L"nspec is nullptr");
return nspec->SetNumFaces(numFaces);
}
void SetNormal(Mesh& mesh, int normID, Point3& normal) {
+ if (&mesh == nullptr) throw MAXException(L"mesh is nullptr");
mesh.SpecifyNormals();
MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (nspec == nullptr) throw MAXException(L"nspec is nullptr");
int numNormals = nspec->GetNumNormals();
if (normID > numNormals || normID < 1) throw MAXException(L"normID out of valid range");
@@ -163,8 +187,10 @@ class FP_Basic : public IFP_Basic
}
void SetNormalId(Mesh& mesh, int face, int corner, int normID) {
+ if (&mesh == nullptr) throw MAXException(L"mesh is nullptr");
mesh.SpecifyNormals();
MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (nspec == nullptr) throw MAXException(L"nspec is nullptr");
int numFaces = nspec->GetNumFaces();
if (face > numFaces || face < 1) throw MAXException(L"face out of valid range");
if (corner > 3 || corner < 1) throw MAXException(L"corner out of valid range");
@@ -175,8 +201,10 @@ class FP_Basic : public IFP_Basic
}
void SetNormalExplicit(Mesh& mesh, int normID, bool value) {
+ if (&mesh == nullptr) throw MAXException(L"mesh is nullptr");
mesh.SpecifyNormals();
MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (nspec == nullptr) throw MAXException(L"nspec is nullptr");
int numNormals = nspec->GetNumNormals();
if (normID > numNormals || normID < 1) throw MAXException(L"normID out of valid range");
@@ -184,7 +212,10 @@ class FP_Basic : public IFP_Basic
}
bool GetNormalExplicit(Mesh& mesh, int normID) {
- MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (&mesh == nullptr) throw MAXException(L"mesh is nullptr");
+ mesh.SpecifyNormals();
+ MeshNormalSpec* nspec = mesh.GetSpecifiedNormals();
+ if (nspec == nullptr) throw MAXException(L"nspec is nullptr");
int numNormals = nspec->GetNumNormals();
if (normID > numNormals || normID < 1) throw MAXException(L"normID out of valid range");
diff --git a/plugins/nspec/nspec_2014.vcxproj b/plugins/nspec/nspec_2014.vcxproj
index 65ee3b5..b27f3cd 100644
--- a/plugins/nspec/nspec_2014.vcxproj
+++ b/plugins/nspec/nspec_2014.vcxproj
@@ -19,7 +19,6 @@
{F3DB68C2-EC68-45E0-BC6F-41D1C0039A94}
DynamicLibrary
$(ADSK_3DSMAX_SDK_2014)
- 10.0.19041.0
diff --git a/plugins/nspec/nspec_2015.vcxproj b/plugins/nspec/nspec_2015.vcxproj
index 79fdf30..9ce4d44 100644
--- a/plugins/nspec/nspec_2015.vcxproj
+++ b/plugins/nspec/nspec_2015.vcxproj
@@ -19,7 +19,6 @@
{0113A92C-713C-463B-AD6F-8092BB750C45}
DynamicLibrary
$(ADSK_3DSMAX_SDK_2015)
- 10.0.19041.0
diff --git a/plugins/nspec/nspec_2020.vcxproj b/plugins/nspec/nspec_2020.vcxproj
index b449a82..3d053cd 100644
--- a/plugins/nspec/nspec_2020.vcxproj
+++ b/plugins/nspec/nspec_2020.vcxproj
@@ -49,7 +49,7 @@
bmm.lib;core.lib;geom.lib;gfx.lib;mesh.lib;maxutil.lib;maxscrpt.lib;gup.lib;paramblk2.lib;;%(AdditionalDependencies)
nspec.def
false
-
+
diff --git a/scripts/max4ds/init.ms b/scripts/max4ds/init.ms
index e8d6ab2..5c39808 100644
--- a/scripts/max4ds/init.ms
+++ b/scripts/max4ds/init.ms
@@ -2,7 +2,7 @@
local set_heapsize = 64 * 1024 * 1024 --64 MiB
if heapsize < set_heapsize then heapsize = set_heapsize
- global Max4ds_version = "v0.8.1"
+ global Max4ds_version = "v0.8.2"
--global Max4ds_scriptsPath = getFilenamePath (getThisScriptFilename())
fn DisableScript file = (