WerWolv / ImHex-Patterns

Hex patterns, include patterns and magic files for the use with the ImHex Hex Editor
https://github.com/WerWolv/ImHex
GNU General Public License v2.0
657 stars 173 forks source link

std::hash::crc32 cannot cast value to type 'pattern' #273

Closed themixednuts closed 3 months ago

themixednuts commented 3 months ago

string is of type str, but I've also tried literal numbers and same error.

std::hash::crc32(string, 0xFFFFFFFF, 0x04C11DB7, 0xFFFFFFFF, true, true);
//                      ^ E: runtime error: Cannot cast value to type 'pattern'.fd
paxcut commented 3 months ago

I just tested the following code and it ran without problems. This was recently added so make sure you update the libraries in the content store before trying it again.

import std.hash;

str test = "hello";
std::print("{}",std::hash::crc32(test, 0xFFFFFFFF, 0x04C11DB7, 0xFFFFFFFF, true, true));
themixednuts commented 3 months ago

I just tested the following code and it ran without problems. This was recently added so make sure you update the libraries in the content store before trying it again.

import std.hash;

str test = "hello";
std::print("{}",std::hash::crc32(test, 0xFFFFFFFF, 0x04C11DB7, 0xFFFFFFFF, true, true));

Interesting. Still have the issue, even after exiting and relaunching.

import std.hash;

fn main(){
    str test = "hello";
    std::print("{}",std::hash::crc32(test, 0xFFFFFFFF, 0x04C11DB7, 0xFFFFFFFF, true, true));
};
// results

E: [ Stack Trace ]
E: C:\Users\****\AppData\Local\imhex\includes\std/hash.pat:48:94
E: 48 |  reflect_in, reflect_out);
E:                               ^
E: <Source Code>:113:86
E: 113 |  0xFFFFFFFF, true, true));
E:                               ^

E: runtime error: Cannot cast value to type 'pattern'.

image

paxcut commented 3 months ago

Does the crc32 function in the library looks like this?

  fn crc32(ref auto pattern, u32 init, u32 poly, u32 xorout, bool reflect_in, bool reflect_out) {
        return builtin::std::hash::crc32(pattern, init, poly, xorout, reflect_in, reflect_out);
    };

in particular, does it have the builtin:: part added?

themixednuts commented 3 months ago

yea this is what the file shows

    // C:\Users\*****\AppData\Local\imhex\includes\std\hash.pat : ln 47
    fn crc32(ref auto pattern, u32 init, u32 poly, u32 xorout, bool reflect_in, bool reflect_out) {
        return builtin::std::hash::crc32(pattern, init, poly, xorout, reflect_in, reflect_out);
    };
paxcut commented 3 months ago

You must be running an older version of Imhex, one built before the fix was added on 7/7.

themixednuts commented 3 months ago

That was it, off by one minor patch, thank you!

paxcut commented 3 months ago

yeah sorry about that. I made the assumption that the fixes were done in the library include file but seeing how yours was identical I went back and looked at the actual fix changes and noticed that .cpp files were changed which indicates imhex needs updating. A bit of running around but you got it working. Good deal! and thanks for closing the issue.