-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] "Exception: vector" crash in pattern language #2108
Comments
With printf-debugging it is clear that some index gets negative, but that's not visible in the error message.
|
With printf debugging ImHex completely choked one core and crawled to a near halt, after 15 seconds it doesn't even printf anymore. |
slow-imhex.mov |
In order to reproduce the error you are getting we will also need a sample input file to run the pattern on. From your description it looks like your code is creating an exception when it runs. The exception has to do with the c++ vector class used internally to create data types. Pattern language has no printf so you probably mean debugging using If you use print() in a way that produces tons of output it is possible to overwhelm you resources, you need to avoid doing that by not printing everything everywhere. Also use the pattern language debugger to some extent to help you determine the source of the error. |
uncompress to dealer2a.crp and run the pattern script on it, I restored the bugs in the code so it will throw this exception again. If ImHex unfreezes I will also copy the script with print() lines to show how badly it stalls. |
I used the debugger, but it's really not very useful when the error happens on iteration 30,000 - i will literally die pressing continue 30,000 times. |
You can also put and if statement that checks the iteration number and create a dummy statement when it is true where you can place the breakpoint . |
Ideally, it should break into the debugger when a script exception is thrown (provided there is no try/catch). |
there is also |
But it doesn't let you use the debugger at the point where exception happened, exactly what I'm saying. |
this is not an error in the pattern language. you are creating an exception in the c++ code that runs the pattern language and crashing imhex when it is triggered. That should never happen regardless of the problems that the script may have but it cannot be debugged in pattern language and needs to be fixed so it doesnt occur. |
Okay, I believe the problem is the negative index, as I posted in my second message - could it be the scripting engine does not process that correctly? Or maybe just an out of bounds index if it's treated as unsigned. |
I did not manage to wait the std::print() version - it was getting slower and slower with each step, so I had to kill ImHex. |
it is crashing when it tries to create the stack trace, so it isn't the negative index per se. |
The thing where large console messages would cause ImHex to slow down a lot was fixed a few days ago btw |
Oh, awesome! |
So this seems like an actual bug that needs to be fixed? |
The error is caused by this code I think: if (len != 0)
{
u32 offset = ((inbyte & 0x10) << 0x0C) + (offset_hi * 256) + offset_lo + 1;
Subrange<dict_len> dict_data @ datapos - offset in output;
std::mem::copy_value_to_section(dict_data, output, datapos);
datapos += dict_len;
} that probably should be |
No, this was fixed (if you look at the message edits), but the vector error remained. The bug is on this line:
|
As I said in the OP, I do not need help debugging the script itself, I fixed it and it works. I need help with general debuggability of the script writing process where errors "Exception: vector" are not extremely helpful to diagnose what has gone wrong. |
Maybe I wasn't clear enough about stating the fact that this is an internal bug in imhex that cannot be debugged from pattern language. When errors that can be debugged occur, ImHex does not crash and you get a message indicating what went wrong. In this case imhex crashes so it is impossible to fix the problem by debugging the script. It may help, but the bug needs to be fixed in the source code of pattern language. |
Great, and this is what this ticket is about, thanks! |
I know you don't need help debugging the code and that it is working for you, but I wanted to mention that I also got it working without changing the place you said is causing the error. What I did is make sure that only positive len and dict_lens are used in all the different cases. |
Operating System
MacOS
What's the issue you encountered?
This is all I get, how can I go about debugging my pattern code?
How can the issue be reproduced?
Run this script
ImHex Version
1.36.2
ImHex Build Type
Installation type
brew install imhex
Additional context?
The text was updated successfully, but these errors were encountered: