Skip to content

Commit

Permalink
Fix nspec crash related to Editable Poly
Browse files Browse the repository at this point in the history
  • Loading branch information
pudingus committed Aug 8, 2021
1 parent cc8961c commit b2e0de8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
33 changes: 32 additions & 1 deletion plugins/nspec/nspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");
Expand All @@ -136,35 +154,43 @@ 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");

nspec->Normal(normID - 1) = normal;
}

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");
Expand All @@ -175,16 +201,21 @@ 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");

nspec->SetNormalExplicit(normID - 1, value);
}

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");

Expand Down
1 change: 0 additions & 1 deletion plugins/nspec/nspec_2014.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<ProjectGuid>{F3DB68C2-EC68-45E0-BC6F-41D1C0039A94}</ProjectGuid>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<MaxSDK>$(ADSK_3DSMAX_SDK_2014)</MaxSDK>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(MaxSDK)\ProjectSettings\PropertySheets\3dsmax.general.project.settings.props" />
Expand Down
1 change: 0 additions & 1 deletion plugins/nspec/nspec_2015.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<ProjectGuid>{0113A92C-713C-463B-AD6F-8092BB750C45}</ProjectGuid>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<MaxSDK>$(ADSK_3DSMAX_SDK_2015)</MaxSDK>
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(MaxSDK)\ProjectSettings\PropertySheets\3dsmax.general.project.settings.props" />
Expand Down
2 changes: 1 addition & 1 deletion plugins/nspec/nspec_2020.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<AdditionalDependencies>bmm.lib;core.lib;geom.lib;gfx.lib;mesh.lib;maxutil.lib;maxscrpt.lib;gup.lib;paramblk2.lib;;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>nspec.def</ModuleDefinitionFile>
<GenerateDebugInformation Condition="'$(Configuration)'=='Release'">false</GenerateDebugInformation>
</Link>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="nspec.cpp" />
Expand Down
2 changes: 1 addition & 1 deletion scripts/max4ds/init.ms
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit b2e0de8

Please sign in to comment.