Skip to content

Commit

Permalink
Prevent crashes in situations where resources have been disposed of
Browse files Browse the repository at this point in the history
  • Loading branch information
Lactozilla committed Mar 26, 2024
1 parent 15ef89c commit 33ce70f
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 184 deletions.
30 changes: 17 additions & 13 deletions guides/Documentation.htm
Original file line number Diff line number Diff line change
Expand Up @@ -5142,7 +5142,7 @@ <h2 style="margin-bottom: 8px;">Model.GetAnimationCount</h2>
<li>model (Integer): The model index to check.</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">The animation count. Will always return <code>0</code> for vertex-animated models.</div>
<div style="font-size: 14px;">Returns an Integer value.</div>
</p>
<p id="Reference_functions_Model_GetAnimationName">
<h2 style="margin-bottom: 8px;">Model.GetAnimationName</h2>
Expand Down Expand Up @@ -5177,7 +5177,7 @@ <h2 style="margin-bottom: 8px;">Model.GetFrameCount</h2>
<li>model (Integer): The model index to check.</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">The frame count. Will always return <code>0</code> for skeletal-animated models.</div>
<div style="font-size: 14px;">Returns an Integer value.</div>
</p>
<p id="Reference_functions_Model_GetAnimationLength">
<h2 style="margin-bottom: 8px;">Model.GetAnimationLength</h2>
Expand Down Expand Up @@ -5356,7 +5356,7 @@ <h2 style="margin-bottom: 8px;">Music.IsPlaying</h2>
<li>music (Integer): The music index to play.</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">Returns whether or not the music is playing.</div>
<div style="font-size: 14px;">Returns a Boolean value.</div>
</p>
<p id="Reference_functions_Music_GetPosition">
<h2 style="margin-bottom: 8px;">Music.GetPosition</h2>
Expand All @@ -5366,6 +5366,8 @@ <h2 style="margin-bottom: 8px;">Music.GetPosition</h2>
<ul style="margin-top: 0px; font-size: 14px;">
<li>music (Integer): The music index to get the current position (in seconds) of.</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">Returns a Decimal value.</div>
</p>
<p id="Reference_functions_Music_Alter">
<h2 style="margin-bottom: 8px;">Music.Alter</h2>
Expand Down Expand Up @@ -5404,13 +5406,13 @@ <h2 style="margin-bottom: 8px;">Number.AsInteger</h2>
<p id="Reference_functions_Number_AsDecimal">
<h2 style="margin-bottom: 8px;">Number.AsDecimal</h2>
<code>Number.AsDecimal(n)</code>
<div style="margin-top: 8px; font-size: 14px;">Converts a Integer to an Decimal.</div>
<div style="margin-top: 8px; font-size: 14px;">Converts a Integer to a Decimal.</div>
<div style="font-weight: bold; margin-top: 8px;">Parameters:</div>
<ul style="margin-top: 0px; font-size: 14px;">
<li>n (Number): Number value.</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">Returns an Decimal value.</div>
<div style="font-size: 14px;">Returns a Decimal value.</div>
</p>
<p id="Reference_functions_Object_Loaded">
<h2 style="margin-bottom: 8px;">Object.Loaded</h2>
Expand Down Expand Up @@ -5756,13 +5758,13 @@ <h2 style="margin-bottom: 8px;">RSDK.Math.RadianToInteger</h2>
<p id="Reference_functions_RSDK_Math_IntegerToRadian">
<h2 style="margin-bottom: 8px;">RSDK.Math.IntegerToRadian</h2>
<code>RSDK.Math.IntegerToRadian(integer)</code>
<div style="margin-top: 8px; font-size: 14px;">Gets the radian decimal conversion of an integer, based on 256.</div>
<div style="margin-top: 8px; font-size: 14px;">Gets the radia Decimal conversion of an integer, based on 256.</div>
<div style="font-weight: bold; margin-top: 8px;">Parameters:</div>
<ul style="margin-top: 0px; font-size: 14px;">
<li>integer (Integer): Integer value to convert.</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">A radian decimal value of the converted integer.</div>
<div style="font-size: 14px;">A radia Decimal value of the converted integer.</div>
</p>
<p id="Reference_functions_RSDK_Matrix_Create256">
<h2 style="margin-bottom: 8px;">RSDK.Matrix.Create256</h2>
Expand Down Expand Up @@ -7719,7 +7721,7 @@ <h2 style="margin-bottom: 8px;">Sound.Play</h2>
<li>volume (Decimal): Controls the volume of the audio. 0.0 is muted, 1.0 is normal volume. (1.0 is the default.)</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">Returns the channel index where the sound began to play.</div>
<div style="font-size: 14px;">Returns the channel index where the sound began to play, or <code>-1</code> if no channel was available.</div>
</p>
<p id="Reference_functions_Sound_Loop">
<h2 style="margin-bottom: 8px;">Sound.Loop</h2>
Expand All @@ -7734,7 +7736,7 @@ <h2 style="margin-bottom: 8px;">Sound.Loop</h2>
<li>volume (Decimal): Controls the volume of the audio. 0.0 is muted, 1.0 is normal volume. (1.0 is the default.)</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">Returns the channel index where the sound began to play.</div>
<div style="font-size: 14px;">Returns the channel index where the sound began to play, or <code>-1</code> if no channel was available.</div>
</p>
<p id="Reference_functions_Sound_Stop">
<h2 style="margin-bottom: 8px;">Sound.Stop</h2>
Expand Down Expand Up @@ -7786,6 +7788,8 @@ <h2 style="margin-bottom: 8px;">Sound.IsPlaying</h2>
<ul style="margin-top: 0px; font-size: 14px;">
<li>sound (Integer): The sound index.</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">Returns a Boolean value.</div>
</p>
<p id="Reference_functions_Sound_PlayMultiple">
<h2 style="margin-bottom: 8px;">Sound.PlayMultiple</h2>
Expand All @@ -7799,7 +7803,7 @@ <h2 style="margin-bottom: 8px;">Sound.PlayMultiple</h2>
<li>volume (Decimal): Controls the volume of the audio. 0.0 is muted, 1.0 is normal volume. (1.0 is the default.)</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">Returns the channel index where the sound began to play.</div>
<div style="font-size: 14px;">Returns the channel index where the sound began to play, or <code>-1</code> if no channel was available.</div>
</p>
<p id="Reference_functions_Sound_LoopMultiple">
<h2 style="margin-bottom: 8px;">Sound.LoopMultiple</h2>
Expand All @@ -7814,7 +7818,7 @@ <h2 style="margin-bottom: 8px;">Sound.LoopMultiple</h2>
<li>volume (Decimal): Controls the volume of the audio. 0.0 is muted, 1.0 is normal volume. (1.0 is the default.)</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">Returns the channel index where the sound began to play.</div>
<div style="font-size: 14px;">Returns the channel index where the sound began to play, or <code>-1</code> if no channel was available.</div>
</p>
<p id="Reference_functions_Sound_PlayAtChannel">
<h2 style="margin-bottom: 8px;">Sound.PlayAtChannel</h2>
Expand Down Expand Up @@ -8581,13 +8585,13 @@ <h2 style="margin-bottom: 8px;">String.ParseInteger</h2>
<p id="Reference_functions_String_ParseDecimal">
<h2 style="margin-bottom: 8px;">String.ParseDecimal</h2>
<code>String.ParseDecimal(string)</code>
<div style="margin-top: 8px; font-size: 14px;">Convert a String value to an Decimal value if possible.</div>
<div style="margin-top: 8px; font-size: 14px;">Convert a String value to a Decimal value if possible.</div>
<div style="font-weight: bold; margin-top: 8px;">Parameters:</div>
<ul style="margin-top: 0px; font-size: 14px;">
<li>string (String): The string to parse.</li>
</ul>
<div style="font-weight: bold; margin-top: 8px;">Returns:</div>
<div style="font-size: 14px;">Returns the value as an Decimal.</div>
<div style="font-size: 14px;">Returns the value as a Decimal.</div>
</p>
<p id="Reference_functions_Texture_Create">
<h2 style="margin-bottom: 8px; color: red;">Texture.Create</h2>
Expand Down
14 changes: 7 additions & 7 deletions source/Engine/Bytecode/ScriptEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,12 +1115,12 @@ PUBLIC STATIC VMValue ScriptEntity::VM_SetAnimation(int argCount, VMValue* args,
if (!self)
return NULL_VAL;

if (self->Sprite < 0) {
ScriptManager::Threads[threadID].ThrowRuntimeError(false, "this.Sprite is not set!", animation);
ISprite* sprite = Scene::GetSpriteResource(self->Sprite);
if (!sprite) {
ScriptManager::Threads[threadID].ThrowRuntimeError(false, "Sprite is not set!", animation);
return NULL_VAL;
}

ISprite* sprite = Scene::SpriteList[self->Sprite]->AsSprite;
if (!(animation >= 0 && (size_t)animation < sprite->Animations.size())) {
ScriptManager::Threads[threadID].ThrowRuntimeError(false, "Animation %d is not in bounds of sprite.", animation);
return NULL_VAL;
Expand Down Expand Up @@ -1150,12 +1150,12 @@ PUBLIC STATIC VMValue ScriptEntity::VM_ResetAnimation(int argCount, VMValue* arg
return NULL_VAL;

int spriteIns = self->Sprite;
if (!(spriteIns > -1 && (size_t)spriteIns < Scene::SpriteList.size())) {
ISprite* sprite = Scene::GetSpriteResource(spriteIns);
if (!sprite) {
ScriptManager::Threads[threadID].ThrowRuntimeError(false, "Sprite %d does not exist!", spriteIns);
return NULL_VAL;
}

ISprite* sprite = Scene::SpriteList[self->Sprite]->AsSprite;
if (!(animation >= 0 && (Uint32)animation < sprite->Animations.size())) {
ScriptManager::Threads[threadID].ThrowRuntimeError(false, "Animation %d is not in bounds of sprite.", animation);
return NULL_VAL;
Expand Down Expand Up @@ -1362,7 +1362,7 @@ PUBLIC STATIC VMValue ScriptEntity::VM_GetHitboxFromSprite(int argCount, VMValue
int frame = GET_ARG(3, GetInteger);
int hitbox = GET_ARG(4, GetInteger);

if (!self)
if (!self || !sprite)
return NULL_VAL;

if (!(animation > -1 && (size_t)animation < sprite->Animations.size())) {
Expand Down Expand Up @@ -1404,7 +1404,7 @@ PUBLIC STATIC VMValue ScriptEntity::VM_ReturnHitboxFromSprite(int argCount, VMVa
int frame = GET_ARG(3, GetInteger);
int hitbox = GET_ARG(4, GetInteger);

if (!self)
if (!self || !sprite)
return NULL_VAL;

if (!(animation > -1 && (size_t)animation < sprite->Animations.size())) {
Expand Down
Loading

0 comments on commit 33ce70f

Please sign in to comment.