What's new

KSP bug and gotcha

kotori

Senior Member
Hi
I finally got a grip of a bug which was initially very confusing. Consider this code:
Code:
on init
    declare $x
    message("")
    if (1 = 1)     
        $x := 1
    end if
    message($x)
end on
When you press apply you expect to see the message "1" presented and that is exactly what happens.
Now say you want to try the code without the "$x := 1" so you comment that line out:
Code:
on init
    declare $x
    message("")
    if (1 = 1)     
        {$x := 1}      { <-- commented out }
    end if
    message($x)
end on
Now you'd expect to see the default value of $x presented ("0"). However the second message statement is never executed so there is no message presented. Apparently Kontakt can't properly handle empty if-statements whose condition is true (maybe this applies to while-loops as well). It seems that executing the body of an empty if-statement causes the execution of the whole callback to be silently aborted.

Normally one doesn't use empty bodies, but sometimes when you test things you comment out code and then this one is a real gotcha.
So I guess we now have two cases where a callback is silently aborted:
* Executing an empty if-body
* Assigning to a builtin variable

Nils
 
Hi Nils!

Thank you! Good to know.

I had some strange bugs last time too, but couldn't verify them 100%. One crashed kontakt and cubase when hiting apply... i had a for loop setting some variables "on init". I did some test with this loop in another test script, but couldn't reproduce this bug. But my guitarscript always crashed (kontakt and cubase => 100% CPU) so i rewrote some code and placed it on another position and it worked...strange. Searched for about 2 hours...haven't found what i did wrong.
 
Hi Nils!

Thank you! Good to know.

I had some strange bugs last time too, but couldn't verify them 100%. One crashed kontakt and cubase when hiting apply... i had a for loop setting some variables "on init". I did some test with this loop in another test script, but couldn't reproduce this bug. But my guitarscript always crashed (kontakt and cubase => 100% CPU) so i rewrote some code and placed it on another position and it worked...strange. Searched for about 2 hours...haven't found what i did wrong.

Could it be that you ended a block incorrectly?
https://www.native-instruments.de/site/forum_us/showpost.php?p=199710&postcount=109 (Here)'s a crashing bug that's still there in K2.1. (Please be careful not to have anything unsaved loaded if you try that script).
 
Top Bottom